diff --git a/framework/scripts/cluster_control.py b/framework/scripts/cluster_control.py deleted file mode 100644 index 8af7b46bddd..00000000000 --- a/framework/scripts/cluster_control.py +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2015, Wazuh Inc. -# Created by Wazuh, Inc. . -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import argparse -import asyncio -import itertools -import logging -import operator -import sys -from os import path -from typing import Union - -import wazuh.core.cluster.cluster -import wazuh.core.cluster.utils -from wazuh.core.cluster import control, local_client -from wazuh.core.common import DECIMALS_DATE_FORMAT -from wazuh.core.utils import get_utc_strptime - - -def __print_table(data: map, headers: dict, show_header: bool = False): - """Pretty print list of lists. - - Paramaters - ---------- - data : map - Data to be printed. - headers : dict - Table headers. - show_header : bool - Whether to show the table header or not. - """ - - def get_max_size_cols(l: map) -> list: - """For each column of the table, return the size of the biggest element. - - Parameters - ---------- - l : map - Table. - - Returns - ------- - list - List containing the biggest element size of each column of the given table. - """ - return list(map(lambda x: max(map(lambda y: len(y) + 2, x)), map(list, zip(*l)))) - - if show_header: - table = list(itertools.chain([tuple(map(lambda x: x.upper(), headers))], data)) - else: - table = data - - sizes = get_max_size_cols(table) - - table_str = '\n'.join( - [''.join(["{}{}".format(col, " " * (max_size - len(col))) for col, max_size in zip(row, sizes)]) - for row in table]) - print(table_str) - - -async def print_agents(filter_status: list, filter_node: list): - """Print table with the agents information. - - Parameters - ---------- - filter_node : list - Nodes to return. - filter_status : list - Agent connection statuses to filter by. - """ - lc = local_client.LocalClient() - result = await control.get_agents(lc, filter_node=filter_node, filter_status=filter_status) - headers = {'id': 'ID', 'name': 'Name', 'ip': 'IP', 'status': 'Status', 'version': 'Version', - 'node_name': 'Node name'} - data = map(operator.itemgetter(*headers.keys()), result['items']) - __print_table(data, list(headers.values()), True) - - -async def print_nodes(filter_node: list): - """Print table with the cluster nodes. - - Parameters - ---------- - filter_node : list - Nodes to return. - """ - lc = local_client.LocalClient() - result = await control.get_nodes(lc, filter_node=filter_node) - headers = ["Name", "Type", "Version", "Address"] - data = map(lambda x: list(x.values()), result['items']) - __print_table(data, headers, True) - - -async def print_health(config: dict, more: bool, filter_node: Union[str, list]): - """Print the current status of the cluster as well as additional information. - - Parameters - ---------- - config : dict - Cluster current configuration. - more : bool - Indicate whether additional information is desired or not. - filter_node : str or list - Node to return. - """ - - def calculate_seconds(start_time: str, end_time: str): - """Calculate the time difference between two dates. - - Parameters - ---------- - start_time : str - Start date. - end_time : str - End date. - - Returns - ------- - str - Total seconds between the two dates. - """ - if end_time != 'n/a' and start_time != 'n/a': - seconds = \ - get_utc_strptime(end_time, DECIMALS_DATE_FORMAT) - get_utc_strptime(start_time, DECIMALS_DATE_FORMAT) - total_seconds = f"{round(seconds.total_seconds(), 3) if seconds.total_seconds() >= 0.0005 else 0.001}s" - else: - total_seconds = 'n/a' - - return total_seconds - - lc = local_client.LocalClient() - if filter_node is None: - filter_node = await control.get_nodes(lc, filter_node=filter_node) - filter_node = [node['name'] for node in filter_node['items']] - result = await control.get_health(lc, filter_node=filter_node) - msg2 = "" - - msg1 = f"Cluster name: {config['name']}\n\n" - msg1 += f"Last completed synchronization for connected nodes ({result['n_connected_nodes']}):\n" if not more \ - else f"Connected nodes ({result['n_connected_nodes']}):" - - for node, node_info in sorted(result["nodes"].items()): - msg2 += f"\n {node} ({node_info['info']['ip']})\n" - msg2 += f" Version: {node_info['info']['version']}\n" - msg2 += f" Type: {node_info['info']['type']}\n" - msg2 += f" Active agents: {node_info['info']['n_active_agents']}\n" - - if node_info['info']['type'] != "master": - if not more: - msg1 += f" {node} ({node_info['info']['ip']}): " \ - f"Integrity check: {node_info['status']['last_check_integrity']['date_end_master']} | " \ - f"Integrity sync: {node_info['status']['last_sync_integrity']['date_end_master']} | " \ - f"Agents-info: {node_info['status']['last_sync_agentinfo']['date_end_master']} | " \ - f"Agent-groups: {node_info['status']['last_sync_agentgroup']['date_end']} | " \ - f"Agent-groups full: {node_info['status']['last_sync_full_agentgroup']['date_end']} | " \ - f"Last keep alive: {node_info['status']['last_keep_alive']}.\n" - - msg2 += " Status:\n" - - # Last Keep Alive - msg2 += " Last keep Alive:\n" - msg2 += f" Last received: {node_info['status']['last_keep_alive']}.\n" - - # Integrity check - total = calculate_seconds(node_info['status']['last_check_integrity']['date_start_master'], - node_info['status']['last_check_integrity']['date_end_master']) - msg2 += f" Integrity check:\n" - msg2 += f" Last integrity check: {total} " \ - f"({node_info['status']['last_check_integrity']['date_start_master']} - " \ - f"{node_info['status']['last_check_integrity']['date_end_master']}).\n" - msg2 += f" Permission to check integrity: {node_info['status']['sync_integrity_free']}.\n" - - # Integrity sync - total = calculate_seconds(node_info['status']['last_sync_integrity']['date_start_master'], - node_info['status']['last_sync_integrity']['date_end_master']) - msg2 += " Integrity sync:\n" - msg2 += f" Last integrity synchronization: {total} " \ - f"({node_info['status']['last_sync_integrity']['date_start_master']} - " \ - f"{node_info['status']['last_sync_integrity']['date_end_master']}).\n" - - n_shared = str(node_info['status']['last_sync_integrity']['total_files']["shared"]) - n_missing = str(node_info['status']['last_sync_integrity']['total_files']["missing"]) - n_extra = str(node_info['status']['last_sync_integrity']['total_files']["extra"]) - msg2 += f" Synchronized files: Shared: {n_shared} | Missing: {n_missing} | " \ - f"Extra: {n_extra}.\n" - - # Agent info - total = calculate_seconds(node_info['status']['last_sync_agentinfo']['date_start_master'], - node_info['status']['last_sync_agentinfo']['date_end_master']) - msg2 += " Agents-info:\n" - msg2 += f" Last synchronization: {total} " \ - f"({node_info['status']['last_sync_agentinfo']['date_start_master']} - " \ - f"{node_info['status']['last_sync_agentinfo']['date_end_master']}).\n" - msg2 += f" Number of synchronized chunks: " \ - f"{node_info['status']['last_sync_agentinfo']['n_synced_chunks']}.\n" - msg2 += f" Permission to synchronize agent-info: " \ - f"{node_info['status']['sync_agent_info_free']}.\n" - - # Agent groups - total = calculate_seconds(node_info['status']['last_sync_agentgroup']['date_start'], - node_info['status']['last_sync_agentgroup']['date_end']) - msg2 += " Agents-groups:\n" - msg2 += f" Last synchronization: {total} " \ - f"({node_info['status']['last_sync_agentgroup']['date_start']} - " \ - f"{node_info['status']['last_sync_agentgroup']['date_end']}).\n" - msg2 += f" Number of synchronized chunks: " \ - f"{node_info['status']['last_sync_agentgroup']['n_synced_chunks']}.\n" - - # Agent groups full - total = calculate_seconds(node_info['status']['last_sync_full_agentgroup']['date_start'], - node_info['status']['last_sync_full_agentgroup']['date_end']) - msg2 += " Agents-groups full:\n" - msg2 += f" Last synchronization: {total} " \ - f"({node_info['status']['last_sync_full_agentgroup']['date_start']} - " \ - f"{node_info['status']['last_sync_full_agentgroup']['date_end']}).\n" - msg2 += f" Number of synchronized chunks: " \ - f"{node_info['status']['last_sync_full_agentgroup']['n_synced_chunks']}.\n" - print(msg1) - more and print(msg2) - - -def usage(): - """Show the usage of the parameters.""" - msg = """ - {0} [-h] [-d] [-fn [FILTER_NODE ...]] [-fs [FILTER_STATUS ...]][-a | -l | -i [HEALTH]] - Usage: - \t-l # List all nodes present in a cluster - \t-l -fn # List certain nodes that belong to the cluster - \t-a # List all agents connected to the cluster - \t-a -fn # Check which agents are reporting to certain nodes - \t-a -fs # List agents with certain status - \t-a -fn # List agents reporting to certain node and with certain status - \t-i # Check cluster health - \t-i -fn # Check certain node's health - - - Params: - \t-l, --list - \t-d, --debug - \t-h, --help - \t-fn, --filter-node - \t-fs, --filter-agent-status - \t-a, --list-agents - \t-i, --health - - """.format(path.basename(sys.argv[0])) - print(msg) - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('-d', '--debug', action='store_true', dest='debug', help="Enable debug mode") - parser.add_argument('-fn', '--filter-node', dest='filter_node', nargs='*', type=str, help="Filter by node name") - parser.add_argument('-fs', '--filter-agent-status', dest='filter_status', nargs='*', type=str, - help="Filter by agent status") - exclusive = parser.add_mutually_exclusive_group() - exclusive.add_argument('-a', '--list-agents', action='store_const', const='list_agents', help='List agents') - exclusive.add_argument('-l', '--list-nodes', action='store_const', const='list_nodes', help='List nodes') - exclusive.add_argument('-i', '--health', action='store', nargs='?', const='health', help='Show cluster health') - exclusive.add_argument('-u', '--usage', action='store_true', help='Show usage') - args = parser.parse_args() - - logging.basicConfig(level=logging.DEBUG if args.debug else logging.ERROR, format='%(levelname)s: %(message)s') - - cluster_status = wazuh.core.cluster.utils.get_cluster_status() - if cluster_status['enabled'] == 'no' or cluster_status['running'] == 'no': - logging.error("Cluster is not running.") - sys.exit(1) - - cluster_config = wazuh.core.cluster.utils.read_config() - wazuh.core.cluster.cluster.check_cluster_config(config=cluster_config) - try: - if args.filter_status and not args.list_agents: - logging.error("Wrong arguments.") - usage() - sys.exit(1) - elif args.list_agents: - my_function, my_args = print_agents, (args.filter_status, args.filter_node,) - elif args.list_nodes: - my_function, my_args = print_nodes, (args.filter_node,) - elif args.health: - more = args.health.lower() == 'more' - my_function, my_args = print_health, (cluster_config, more, args.filter_node,) - elif args.usage: - usage() - sys.exit(0) - else: - parser.print_help() - sys.exit(0) - - asyncio.run(my_function(*my_args)) - except KeyboardInterrupt: - pass - except Exception as e: - logging.error(e) - if args.debug: - raise - - -if __name__ == '__main__': - main() diff --git a/framework/scripts/tests/test_agent_groups.py b/framework/scripts/tests/test_agent_groups.py deleted file mode 100644 index d2ec39c228c..00000000000 --- a/framework/scripts/tests/test_agent_groups.py +++ /dev/null @@ -1,544 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# Created by Wazuh, Inc. . -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import pytest -import sys -from unittest.mock import call, patch, MagicMock - -with patch('wazuh.core.common.wazuh_uid'): - with patch('wazuh.core.common.wazuh_gid'): - sys.modules['wazuh.rbac.orm'] = MagicMock() - import wazuh.rbac.decorators - from wazuh.tests.util import RBAC_bypasser - - del sys.modules['wazuh.rbac.orm'] - wazuh.rbac.decorators.expose_resources = RBAC_bypasser - from scripts import agent_groups - from wazuh import agent - - -@patch('scripts.agent_groups.exit') -def test_signal_handler(mock_exit): - """Check if exit is called in signal_handler function.""" - agent_groups.signal_handler('test', 'test') - mock_exit.assert_called_once_with(1) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_show_groups(print_mock: MagicMock): - """Check that the show_groups function displays the groups properly.""" - class AffectedItems: - def __init__(self, affected_items): - self.affected_items = affected_items - self.total_affected_items = len(affected_items) - - with patch('scripts.agent_groups.cluster_utils.forward_function', - return_value=AffectedItems([{'name': 'a', 'count': 1}, {'name': 'b', 'count': 2}])) as forward_mock: - await agent_groups.show_groups() - forward_mock.assert_has_calls([call(func=agent.get_agent_groups, f_kwargs={}), - call(func=agent.get_agents, f_kwargs={'q': 'id!=000;group=null'})]) - print_mock.assert_has_calls([call('Groups (2):'), call(' a (1)'), - call(' b (2)'), call('Unassigned agents: 2.')]) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_show_group(print_mock: MagicMock): - """Check that the show_group function shows the groups to which an agent belongs.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - self.total_failed_items = len(failed_items) - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'id': 1, 'name': 'a', 'count': 1}, {'id': 2, 'name': 'b', 'count': 2}], - failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - agent_id = '1' - await agent_groups.show_group(agent_id) - forward_mock.assert_called_once_with(func=agent.get_agents, f_kwargs={'agent_list': [agent_id]}) - print_mock.assert_has_calls([call("The agent 'a' with ID '1' belongs to groups: Null.")]) - print_mock.reset_mock() - - await agent_groups.show_group('0') - print_mock.assert_has_calls([call('a')]) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_show_synced_agent(print_mock): - """Check that the synchronization status of an agent's groups is returned correctly.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'id': 1, 'name': 'a', 'synced': True}, - {'id': 2, 'name': 'b', 'synced': False}], - failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - agent_id = 0 - await agent_groups.show_synced_agent(agent_id) - forward_mock.assert_called_once_with(func=agent.get_agents_sync_group, f_kwargs={'agent_list': [agent_id]}) - print_mock.assert_has_calls([call("Agent '0' is synchronized. ")]) - print_mock.reset_mock() - await agent_groups.show_synced_agent(0) - print_mock.assert_has_calls([call('a')]) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_show_agents_with_group(print_mock): - """Check that agents belonging to a certain group are returned.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'name': 'a', 'id': 1, 'synced': True}, - {'id': 2, 'name': 'b', 'synced': False}], - failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - await agent_groups.show_agents_with_group(group_id='testing') - forward_mock.assert_called_once_with(func=agent.get_agents_in_group, - f_kwargs={'group_list': ['testing'], 'select': ['name'], - 'limit': None}) - print_mock.assert_has_calls([call("2 agent(s) in group 'testing':"), - call(' ID: 1 Name: a.'), call(' ID: 2 Name: b.')]) - print_mock.reset_mock() - await agent_groups.show_agents_with_group(group_id='testing') - print_mock.assert_has_calls([call("No agents found in group 'testing'.")]) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_show_group_files(print_mock): - """Check that the files of the specified group are returned.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'filename': 'a', 'hash': 'aa'}, {'filename': 'b', 'hash': 'bb'}], - failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - await agent_groups.show_group_files(group_id='testing') - forward_mock.assert_called_once_with(func=agent.get_group_files, f_kwargs={'group_list': ['testing']}) - print_mock.assert_has_calls([call("2 files for 'testing' group:"), call(' a [aa]'), call(' b [bb]')]) - print_mock.reset_mock() - await agent_groups.show_group_files(group_id='testing') - print_mock.assert_has_calls([call("0 files for 'testing' group:"), call(' a [aa]'), call(' b [bb]')]) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_unset_group(print_mock): - """Check the unassignment of one or more groups for an agent.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'filename': 'a', 'hash': 'aa'}, {'filename': 'b', 'hash': 'bb'}], - failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - with patch('scripts.agent_groups.get_stdin', return_value='y') as get_stdin_mock: - agent_id = '99' - group_id = 'testing' - await agent_groups.unset_group(agent_id=agent_id, group_id=group_id) - forward_mock.assert_called_once_with(func=agent.remove_agent_from_groups, - f_kwargs={'agent_list': [agent_id], 'group_list': [group_id]}) - get_stdin_mock.assert_has_calls([call("Do you want to delete the group 'testing' of agent '99'? [y/N]: ")]) - print_mock.assert_has_calls([call("Agent '99' removed from testing.")]) - print_mock.reset_mock() - get_stdin_mock.reset_mock() - - await agent_groups.unset_group(agent_id='999') - get_stdin_mock.assert_has_calls([call("Do you want to delete all groups of agent '999'? [y/N]: ")]) - print_mock.assert_has_calls([call("a")]) - print_mock.reset_mock() - - await agent_groups.unset_group(agent_id='999', quiet=True) - print_mock.assert_has_calls([call("a")]) - print_mock.reset_mock() - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_remove_group(print_mock): - """Check that the specified group is removed.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'testing': ['a', 'b']}], failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - with patch('scripts.agent_groups.get_stdin', return_value='y') as get_stdin_mock: - await agent_groups.remove_group(group_id='testing') - forward_mock.assert_called_once_with(func=agent.delete_groups, f_kwargs={'group_list': ['testing']}) - get_stdin_mock.assert_has_calls([call("Do you want to remove the 'testing' group? [y/N]: ")]) - print_mock.assert_has_calls([call('Group testing removed.')]) - print_mock.reset_mock() - get_stdin_mock.reset_mock() - - await agent_groups.remove_group(group_id='testing', quiet=True) - print_mock.assert_has_calls([call('a')]) - print_mock.reset_mock() - get_stdin_mock.reset_mock() - - with patch('scripts.agent_groups.get_stdin', return_value='n'): - await agent_groups.remove_group(group_id='testing') - print_mock.assert_has_calls([call('Cancelled.')]) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_set_group(print_mock): - """Check that it adds the specified group to the agent information.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'testing': ['agent0', 'agent1']}], failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - with patch('scripts.agent_groups.get_stdin', return_value='y') as get_stdin_mock: - await agent_groups.set_group(agent_id=1, group_id='testing') - forward_mock.assert_called_once_with(func=agent.assign_agents_to_group, - f_kwargs={'group_list': ['testing'], 'agent_list': ['001'], 'replace': False}) - get_stdin_mock.assert_has_calls( - [call("Do you want to add the group 'testing' to the agent '001'? [y/N]: ")]) - print_mock.assert_has_calls([call("Group 'testing' added to agent '001'.")]) - print_mock.reset_mock() - get_stdin_mock.reset_mock() - - await agent_groups.set_group(agent_id=2, group_id='testing', quiet=True) - print_mock.assert_has_calls([call('a')]) - print_mock.reset_mock() - get_stdin_mock.reset_mock() - - with patch('scripts.agent_groups.get_stdin', return_value='n'): - await agent_groups.set_group(agent_id=3, group_id='testing') - print_mock.assert_has_calls([call('Cancelled.')]) - - -@pytest.mark.asyncio -@patch('builtins.print') -async def test_create_group(print_mock): - """Check the successful group creation.""" - class AffectedItems: - called = False - - def __init__(self, affected_items, failed_items): - self.affected_items = affected_items - self.failed_items = failed_items - self.total_affected_items = 0 if AffectedItems.called else len(affected_items) - self.dikt = {'message': 'dikt_testing'} - AffectedItems.called = True - - async def forward_function(func, f_kwargs): - return AffectedItems(affected_items=[{'testing': ['agent0', 'agent1']}], failed_items={'a': 'b'}) - - with patch('scripts.agent_groups.cluster_utils.forward_function', side_effect=forward_function) as forward_mock: - with patch('scripts.agent_groups.get_stdin', return_value='y') as get_stdin_mock: - group_id = 'testing' - await agent_groups.create_group(group_id=group_id) - forward_mock.assert_called_once_with(func=agent.create_group, f_kwargs={'group_id': group_id}) - get_stdin_mock.assert_has_calls([call(f"Do you want to create the group '{group_id}'? [y/N]: ")]) - print_mock.assert_has_calls([call('dikt_testing')]) - print_mock.reset_mock() - get_stdin_mock.reset_mock() - - with patch('scripts.agent_groups.get_stdin', return_value='n'): - await agent_groups.create_group(group_id='testing') - print_mock.assert_has_calls([call('Cancelled.')]) - - -@patch('builtins.print') -@patch('scripts.agent_groups.basename', return_value="mock basename") -def test_usage(basename_mock, print_mock): - """Test if the usage is being correctly printed.""" - msg = """ - {0} [ -l [ -g group_id ] | -c -g group_id | -a (-i agent_id -g group_id | -g group_id) [-q] [-f] | -s -i agent_id | -S -i agent_id | -r (-g group_id | -i agent_id) [-q] ] - - Usage: - \t-l # List all groups - \t-l -g group_id # List agents in group - \t-c -g group_id # List configuration files in group - \t - \t-a -i agent_id -g group_id [-q] [-f] # Add group to agent - \t-r -i agent_id [-q] [-g group_id] # Remove all groups from agent [or single group] - \t-s -i agent_id # Show group of agent - \t-S -i agent_id # Show sync status of agent - \t - \t-a -g group_id [-q] # Create group - \t-r -g group_id [-q] # Remove group - - - Params: - \t-l, --list - \t-c, --list-files - \t-a, --add-group - \t-f, --force-single-group - \t-s, --show-group - \t-S, --show-sync - \t-r, --remove-group - - \t-i, --agent-id - \t-g, --group - - \t-q, --quiet (no confirmation) - \t-d, --debug - """.format(basename_mock.return_value) - - agent_groups.usage() - print_mock.assert_called_once_with(msg) - - basename_mock.assert_called_once_with(sys.argv[0]) - - -@patch('scripts.agent_groups.exit') -@patch('builtins.print') -def test_invalid_option(print_mock, exit_mock): - """Check the proper functioning of the function in charge of - notifying the user in case of error with the CLI options.""" - agent_groups.invalid_option() - print_mock.assert_has_calls([call('Invalid options.'), call("Try '--help' for more information.\n")]) - exit_mock.assert_called_once_with(1) - print_mock.reset_mock() - exit_mock.reset_mock() - - agent_groups.invalid_option(msg='test') - print_mock.assert_has_calls([call('Invalid options: test'), call("Try '--help' for more information.\n")]) - exit_mock.assert_called_once_with(1) - - -@patch('scripts.agent_groups.invalid_option') -@patch('scripts.agent_groups.argparse.ArgumentParser') -def test_get_script_arguments(argument_parser_mock, invalid_option_mock): - """Test the main function.""" - with patch('builtins.sum', return_value=1): - agent_groups.get_script_arguments() - argument_parser_mock.assert_called_once_with() - argument_parser_mock.return_value.add_argument.assert_has_calls( - [call('-l', '--list', action='store_true', dest='list', help='List the groups.'), - call('-c', '--list-files', action='store_true', dest='list_files', - help="List the group's configuration files."), - call('-a', '--add', action='store_true', dest='add', help='Add new group or new agent to group.'), - call('-f', '--force', action='store_true', dest='force', help='Force single group.'), - call('-s', '--show-group', action='store_true', dest='show_group', help='Show group of agent.'), - call('-S', '--show-sync', action='store_true', dest='show_sync', help='Show sync status of agent.'), - call('-r', '--remove', action='store_true', dest='remove', help='Remove group or agent from group.'), - call('-i', '--agent-id', type=str, dest='agent_id', help='Specify the agent ID.'), - call('-g', '--group-id', type=str, dest='group_id', help='Specify group ID.'), - call('-q', '--quiet', action='store_true', dest='quiet', help='Silent mode (no confirmation).'), - call('-d', '--debug', action='store_true', dest='debug', help='Debug mode.'), - call('-u', '--usage', action='store_true', dest='usage', help='Show usage.')]) - - with patch('builtins.sum', return_value=2): - agent_groups.get_script_arguments() - invalid_option_mock.assert_called_once_with("Bad argument combination.") - - -@pytest.mark.asyncio -@patch('scripts.agent_groups.exit', side_effect=exit) -@patch('scripts.agent_groups.remove_group') -@patch('scripts.agent_groups.unset_group') -@patch('scripts.agent_groups.show_synced_agent') -@patch('scripts.agent_groups.show_group') -@patch('scripts.agent_groups.invalid_option') -@patch('scripts.agent_groups.create_group') -@patch('scripts.agent_groups.set_group') -@patch('scripts.agent_groups.show_group_files') -@patch('scripts.agent_groups.show_agents_with_group') -@patch('scripts.agent_groups.show_groups') -@patch('scripts.agent_groups.usage') -@patch('builtins.print') -async def test_main(print_mock, usage_mock, show_groups_mock, show_agents_with_group_mock, show_group_files_mock, - set_group_mock, create_group_mock, invalid_option_mock, show_group_mock, show_synced_agent_mock, - unset_group_mock, remove_group_mock, exit_mock): - """Test the main function.""" - class Arguments: - def __init__(self, list=None, list_files=None, add=None, show_group=None, show_sync=None, force=False, - remove=None, agent_id=None, group_id=None, quiet=False, debug=False, usage=None): - self.list = list - self.list_files = list_files - self.add = add - self.force = force - self.show_group = show_group - self.show_sync = show_sync - self.remove = remove - self.agent_id = agent_id - self.group_id = group_id - self.quiet = quiet - self.debug = debug - self.usage = usage - self.invalid = None - - agent_groups.args = Arguments() - - # No arguments - await agent_groups.main() - show_groups_mock.assert_called() - show_groups_mock.reset_mock() - - with patch('scripts.agent_groups.usage') as usage_mock: - agent_groups.args.usage = True - await agent_groups.main() - usage_mock.assert_called_once() - - # -l - agent_groups.args.list = True - await agent_groups.main() - show_groups_mock.assert_called_once() - - # -l -g - agent_groups.args.group_id = 'group' - await agent_groups.main() - show_agents_with_group_mock.assert_called_once_with(agent_groups.args.group_id) - - # -c --list-files - agent_groups.args = Arguments(list_files=True) - await agent_groups.main() - invalid_option_mock.assert_called_once_with('Missing group.') - invalid_option_mock.reset_mock() - - # -c -g - agent_groups.args = Arguments(list_files=True, group_id='group') - await agent_groups.main() - show_group_files_mock.assert_called_once_with('group') - - # -a -i agent_id -g group_id - agent_groups.args = Arguments(add=True, agent_id='001', group_id='group1') - await agent_groups.main() - set_group_mock.assert_called_once_with('001', 'group1', False, False) - set_group_mock.reset_mock() - - # -a -i agent_id -g group_id -f - agent_groups.args = Arguments(add=True, agent_id='001', group_id='group1', force=True) - await agent_groups.main() - set_group_mock.assert_called_once_with('001', 'group1', False, True) - set_group_mock.reset_mock() - - # -a -i agent_id -g group_id -f -q - agent_groups.args = Arguments(add=True, agent_id='001', group_id='group1', force=True, quiet=True) - await agent_groups.main() - set_group_mock.assert_called_once_with('001', 'group1', True, True) - - # -a -g group_id - agent_groups.args = Arguments(add=True, group_id='group1') - await agent_groups.main() - create_group_mock.assert_called_once_with('group1', False) - create_group_mock.reset_mock() - - # -a -g group_id -q - agent_groups.args = Arguments(add=True, group_id='group1', quiet=True) - await agent_groups.main() - create_group_mock.assert_called_once_with('group1', True) - - # -a - agent_groups.args = Arguments(add=True) - await agent_groups.main() - invalid_option_mock.assert_called_once_with("Missing agent ID or group.") - invalid_option_mock.reset_mock() - - # -s - agent_groups.args = Arguments(show_group=True) - await agent_groups.main() - invalid_option_mock.assert_called_once_with("Missing agent ID.") - invalid_option_mock.reset_mock() - - # -s -i agent_id - agent_groups.args = Arguments(show_group=True, agent_id='002') - await agent_groups.main() - show_group_mock.assert_called_once_with("002") - - # -S - agent_groups.args = Arguments(show_sync=True) - await agent_groups.main() - invalid_option_mock.assert_called_once_with("Missing agent ID.") - invalid_option_mock.reset_mock() - - # -S -i agent_id - agent_groups.args = Arguments(show_sync=True, agent_id='003') - await agent_groups.main() - show_synced_agent_mock.assert_called_once_with("003") - - # -r -i agent_id - agent_groups.args = Arguments(remove=True, agent_id='004') - await agent_groups.main() - unset_group_mock.assert_called_once_with('004', None, False) - unset_group_mock.reset_mock() - - # -r -i agent_id -g group_id - agent_groups.args = Arguments(remove=True, agent_id='004', group_id='group1') - await agent_groups.main() - unset_group_mock.assert_called_once_with('004', 'group1', False) - unset_group_mock.reset_mock() - - # -r -i agent_id -q - agent_groups.args = Arguments(remove=True, agent_id='004', quiet=True) - await agent_groups.main() - unset_group_mock.assert_called_once_with('004', None, True) - - # -r -g group_id - agent_groups.args = Arguments(remove=True, group_id='group2') - await agent_groups.main() - remove_group_mock.assert_called_once_with('group2', False) - remove_group_mock.reset_mock() - - # -r -g group_id -q - agent_groups.args = Arguments(remove=True, group_id='group2', quiet=True) - await agent_groups.main() - remove_group_mock.assert_called_once_with('group2', True) - - # -r - agent_groups.args = Arguments(remove=True) - await agent_groups.main() - invalid_option_mock.assert_called_once_with("Missing agent ID or group.") - invalid_option_mock.reset_mock() diff --git a/framework/scripts/tests/test_cluster_control.py b/framework/scripts/tests/test_cluster_control.py deleted file mode 100644 index 3190fee0a46..00000000000 --- a/framework/scripts/tests/test_cluster_control.py +++ /dev/null @@ -1,410 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# Created by Wazuh, Inc. . -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import logging -import sys -import asyncio -from datetime import timedelta -from unittest.mock import patch, call, MagicMock -from uvloop import EventLoopPolicy, Loop - -import pytest - -import scripts.cluster_control as cluster_control - -@pytest.fixture(scope="session") -def event_loop() -> Loop: - asyncio.set_event_loop_policy(EventLoopPolicy()) - policy = asyncio.get_event_loop_policy() - loop = policy.new_event_loop() - yield loop - loop.close() - -@patch('builtins.map') -@patch('builtins.print') -def test_print_table(print_mock, map_mock): - """Test if the table is being properly printed.""" - data = '' - headers = 'headers' - cluster_control.__print_table(data=data, headers=headers, show_header=False) - - print_mock.assert_called_once_with(data) - assert map_mock.call_count == 2 - - print_mock.reset_mock() - map_mock.reset_mock() - - cluster_control.__print_table(data=data, headers=headers, show_header=True) - - print_mock.assert_called_once_with(data) - assert map_mock.call_count == 3 - - -@pytest.mark.asyncio -@patch('builtins.map', return_value="") -@patch('operator.itemgetter', return_value="") -@patch('scripts.cluster_control.__print_table') -@patch('scripts.cluster_control.control.get_agents', return_value={'items': ''}) -@patch('scripts.cluster_control.local_client.LocalClient', return_value='LocalClient return value') -async def test_print_agents(local_client_mock, get_agents_mock, print_table_mock, itemgetter_mock, map_mock): - """Test if the function is properly printing the requested agents' information.""" - filter_status = 'active' - filter_node = 'wazuh_worker' - headers = {'id': 'ID', 'name': 'Name', 'ip': 'IP', 'status': 'Status', 'version': 'Version', - 'node_name': 'Node name'} - - await cluster_control.print_agents(filter_status=filter_status, filter_node=filter_node) - - local_client_mock.assert_called_once_with() - get_agents_mock.assert_called_once_with(local_client_mock.return_value, filter_node=filter_node, - filter_status=filter_status) - print_table_mock.assert_called_once_with(map_mock.return_value, list(headers.values()), True) - map_mock.assert_called_once_with(itemgetter_mock.return_value, get_agents_mock.return_value['items']) - itemgetter_mock.assert_called_once_with(*headers.keys()) - - -@pytest.mark.asyncio -@patch('builtins.map', return_value="") -@patch('scripts.cluster_control.__print_table') -@patch('scripts.cluster_control.control.get_nodes', return_value={'items': ''}) -@patch('scripts.cluster_control.local_client.LocalClient', return_value='LocalClient return value') -async def test_print_nodes(local_client_mock, get_agents_mock, print_table_mock, map_mock): - """Test if the function is properly printing the requested nodes' information.""" - filter_node = 'wazuh_worker' - headers = ["Name", "Type", "Version", "Address"] - - await cluster_control.print_nodes(filter_node=filter_node) - - local_client_mock.assert_called_once_with() - get_agents_mock.assert_called_once_with(local_client_mock.return_value, filter_node=filter_node) - print_table_mock.assert_called_once_with(map_mock.return_value, headers, True) - map_mock.assert_called_once() - - -@pytest.mark.asyncio -@patch('builtins.print') -@patch('scripts.cluster_control.get_utc_strptime') -@patch('scripts.cluster_control.local_client.LocalClient', return_value='LocalClient return value') -@patch('scripts.cluster_control.control.get_nodes', return_value={'items': [{'name': 'wazuh_worker'}]}) -@patch('scripts.cluster_control.control.get_health', - return_value={'n_connected_nodes': '1', - 'nodes': {'wazuh_worker2': { - 'info': {'ip': '0.0.0.0', 'version': '1.0', 'type': 'worker', 'n_active_agents': '0'}, - 'status': {'last_keep_alive': '11/02/1998', - 'last_check_integrity': {'date_start_master': 'n/a', - 'date_end_master': 'n/a'}, - 'last_sync_integrity': {'date_start_master': '1', - 'date_end_master': '2', - 'total_files': {'shared': 0, 'missing': 0, 'extra': 0, - 'extra_valid': 0}, - 'total_extra_valid': 0}, - 'sync_integrity_free': 'True', - 'last_sync_agentinfo': {'date_start_master': '0', 'date_end_master': '0', - 'n_synced_chunks': 0}, - 'last_sync_agentgroup': {'date_start': 0, 'date_end': 0, - 'n_synced_chunks': 0}, - 'last_sync_full_agentgroup': {'date_start': 0, 'date_end': 0, - 'n_synced_chunks': 0}, - 'sync_agent_info_free': 'True'}}}}) -async def test_print_health(get_health_mock, get_nodes_mock, local_client_mock, get_utc_strptime_mock, print_mock): - """Test if the current status of the cluster is properly printed.""" - - def seconds_mock(time, format=None): - """Auxiliary mock function.""" - return timedelta(seconds=int(time)) - - # Common variables - config = {'name': 'cluster_name'} - more = True - worker_status = get_health_mock.return_value['nodes']['wazuh_worker2']['status'] - worker_info = get_health_mock.return_value['nodes']['wazuh_worker2']['info'] - get_utc_strptime_mock.side_effect = seconds_mock - - # Test cases 1 and 2 - for filter_node in ['wazuh_worker', None]: - # Reset mocks - print_mock.reset_mock() - local_client_mock.reset_mock() - get_nodes_mock.reset_mock() - get_health_mock.reset_mock() - - # Call print_health - await cluster_control.print_health(config=config, more=more, filter_node=filter_node) - print_mock.assert_has_calls([call(f"Cluster name: {config['name']}\n\n" - f"Connected nodes ({get_health_mock.return_value['n_connected_nodes']}):"), - call(f"\n wazuh_worker2 ({worker_info['ip']})\n " - f"Version: {worker_info['version']}\n " - f"Type: {worker_info['type']}\n " - f" Active agents: {worker_info['n_active_agents']}\n " - f"Status:\n " - f" Last keep Alive:\n Last received: " - f"{worker_status['last_keep_alive']}.\n " - f"Integrity check:\n " - f" Last integrity check: n/a " - f"({worker_status['last_check_integrity']['date_end_master']} - " - f"{worker_status['last_check_integrity']['date_start_master']})." - f"\n Permission to check integrity: " - f"{worker_status['sync_integrity_free']}.\n " - f"Integrity sync:\n Last integrity synchronization: 1.0s " - f"({worker_status['last_sync_integrity']['date_start_master']} - " - f"{worker_status['last_sync_integrity']['date_end_master']})." - f"\n Synchronized files: Shared: " - f"{worker_status['last_sync_integrity']['total_files']['shared']} | Missing: " - f"{worker_status['last_sync_integrity']['total_files']['missing']} | Extra: " - f"{worker_status['last_sync_integrity']['total_files']['extra']}." - f"\n Agents-info:\n Last synchronization: 0.001s (" - f"{worker_status['last_sync_agentinfo']['date_start_master']} - " - f"{worker_status['last_sync_agentinfo']['date_start_master']}).\n " - f" Number of synchronized chunks: " - f"{worker_status['last_sync_agentinfo']['n_synced_chunks']}." - f"\n Permission to synchronize agent-info: " - f"{worker_status['sync_agent_info_free']}.\n" - " Agents-groups:\n" - f" Last synchronization: 0.001s " - f"({worker_status['last_sync_agentgroup']['date_start']} - " - f"{worker_status['last_sync_agentgroup']['date_end']}).\n" - f" Number of synchronized chunks: " - f"{worker_status['last_sync_agentgroup']['n_synced_chunks']}.\n" - " Agents-groups full:\n" - f" Last synchronization: 0.001s " - f"({worker_status['last_sync_full_agentgroup']['date_start']} - " - f"{worker_status['last_sync_full_agentgroup']['date_end']}).\n" - f" Number of synchronized chunks: " - f"{worker_status['last_sync_full_agentgroup']['n_synced_chunks']}.\n" - )]) - - # Common assertions - local_client_mock.assert_called_once() - get_utc_strptime_mock.assert_has_calls( - [call(worker_status['last_sync_integrity']['date_end_master'], '%Y-%m-%dT%H:%M:%S.%fZ'), - call(worker_status['last_sync_integrity']['date_start_master'], '%Y-%m-%dT%H:%M:%S.%fZ'), - call(worker_status['last_sync_agentinfo']['date_end_master'], '%Y-%m-%dT%H:%M:%S.%fZ'), - call(worker_status['last_sync_agentinfo']['date_start_master'], '%Y-%m-%dT%H:%M:%S.%fZ')]) - - # filter_node dependant assertions - filter_node and get_nodes_mock.assert_not_called() - filter_node or get_nodes_mock.assert_called_once() - get_health_mock.assert_called_once_with( - local_client_mock.return_value, - filter_node=filter_node or [get_nodes_mock.return_value['items'][0]['name']]) - - # Test case 3 - more = False - filter_node = 'wazuh_worker' - print_mock.reset_mock() - await cluster_control.print_health(config=config, more=more, filter_node=filter_node) - print_mock.assert_called_once_with(f"Cluster name: {config['name']}\n\nLast completed synchronization for connected" - f" nodes ({get_health_mock.return_value['n_connected_nodes']}):\n " - f"wazuh_worker2 " - f"({get_health_mock.return_value['nodes']['wazuh_worker2']['info']['ip']}): " - f"Integrity check: {worker_status['last_check_integrity']['date_end_master']} " - f"| Integrity sync: {worker_status['last_sync_integrity']['date_end_master']} |" - f" Agents-info: {worker_status['last_sync_agentinfo']['date_end_master']} | " - f"Agent-groups: {worker_status['last_sync_agentgroup']['date_end']} | " - f"Agent-groups full: {worker_status['last_sync_full_agentgroup']['date_end']} | " - f"Last keep alive: {worker_status['last_keep_alive']}.\n") - - -@patch('builtins.print') -@patch('scripts.cluster_control.path.basename', return_value="mock basename") -def test_usage(basename_mock, print_mock): - """Test if the usage is being correctly printed.""" - cluster_control.usage() - - msg = """ - {0} [-h] [-d] [-fn [FILTER_NODE ...]] [-fs [FILTER_STATUS ...]][-a | -l | -i [HEALTH]] - Usage: - \t-l # List all nodes present in a cluster - \t-l -fn # List certain nodes that belong to the cluster - \t-a # List all agents connected to the cluster - \t-a -fn # Check which agents are reporting to certain nodes - \t-a -fs # List agents with certain status - \t-a -fn # List agents reporting to certain node and with certain status - \t-i # Check cluster health - \t-i -fn # Check certain node's health - - - Params: - \t-l, --list - \t-d, --debug - \t-h, --help - \t-fn, --filter-node - \t-fs, --filter-agent-status - \t-a, --list-agents - \t-i, --health - - """.format(basename_mock.return_value) - print_mock.assert_called_once_with(msg) - - basename_mock.assert_called_once_with(sys.argv[0]) - - -@pytest.mark.asyncio -@patch('scripts.cluster_control.sys.exit') -@patch('scripts.cluster_control.asyncio.run') -@patch('logging.error') -@patch('logging.basicConfig') -@patch('argparse.ArgumentParser') -@patch('wazuh.core.cluster.cluster.check_cluster_config') -@patch('wazuh.core.cluster.utils.read_config', return_value='') -@patch('wazuh.core.cluster.utils.get_cluster_status', return_value={'enabled': 'no', 'running': 'yes'}) -async def test_main(get_cluster_status_mock, read_config_mock, check_cluster_config, parser_mock, logging_mock, - logging_error_mock, asyncio_run_mock: MagicMock, exit_mock, event_loop): - """Test the main function.""" - - class ArgsMock: - """Auxiliary class.""" - - def __init__(self): - self.filter_status = True - self.list_agents = False - self.list_nodes = False - self.health = False - self.usage = False - self.debug = False - self.filter_node = False - - class ExclusiveMock: - """Auxiliary class.""" - - def __init__(self): - self.exclusive = [] - - def add_argument(self, flag, name, action=None, nargs=None, const=None, type=None, dest=None, help=None): - self.exclusive.append( - {'flag': flag, 'name': name, 'action': action, 'nargs': nargs, 'const': const, 'type': type, - 'dest': dest, 'help': help}) - - class ParserMock: - """Auxiliary class.""" - - def __init__(self): - self.storage = [] - self.exclusive = [] - self.called = False - - def add_argument(self, flag, name, action=None, nargs=None, const=None, type=None, dest=None, help=None): - self.storage.append( - {'flag': flag, 'name': name, 'action': action, 'nargs': nargs, 'const': const, 'type': type, - 'dest': dest, 'help': help}) - - def add_mutually_exclusive_group(self): - return exclusive_mock - - def parse_args(self): - return args_mock - - def print_help(self): - self.called = True - - def run_mock(*args, **kwargs): - asyncio.gather(args[0]) - - asyncio_run_mock.side_effect = run_mock - parser_mock.return_value = ParserMock() - args_mock = ArgsMock() - exclusive_mock = ExclusiveMock() - - with patch('scripts.cluster_control.usage', return_value='') as usage_mock: - # Check if cluster is disabled and first condition - cluster_control.main() - logging_error_mock.assert_has_calls([call('Cluster is not running.'), call('Wrong arguments.')]) - usage_mock.assert_called_once_with() - exit_mock.assert_called_with(1) - read_config_mock.assert_called_once_with() - check_cluster_config.assert_called_once_with(config=read_config_mock.return_value) - logging_mock.assert_called_once_with(level=logging.ERROR, format='%(levelname)s: %(message)s') - exit_mock.reset_mock() - - # Here we will check if the expected parameters were not modified - assert parser_mock.return_value.storage == [ - {'flag': '-d', 'name': '--debug', 'action': 'store_true', 'nargs': None, 'const': None, 'type': None, - 'dest': 'debug', 'help': 'Enable debug mode'}, {'flag': '-fn', 'name': '--filter-node', 'action': None, - 'nargs': '*', 'const': None, 'type': str, - 'dest': 'filter_node', 'help': 'Filter by node name'}, - {'flag': '-fs', 'name': '--filter-agent-status', 'action': None, 'nargs': '*', 'const': None, 'type': str, - 'dest': 'filter_status', 'help': 'Filter by agent status'}] - - assert exclusive_mock.exclusive == [{'action': 'store_const', 'const': 'list_agents', 'dest': None, - 'flag': '-a', 'help': 'List agents', 'name': '--list-agents', - 'nargs': None, 'type': None}, {'action': 'store_const', - 'const': 'list_nodes', - 'dest': None, 'flag': '-l', - 'help': 'List nodes', - 'name': '--list-nodes', 'nargs': None, - 'type': None}, {'action': 'store', - 'const': 'health', - 'dest': None, - 'flag': '-i', - 'help': 'Show cluster ' - 'health', - 'name': '--health', - 'nargs': '?', - 'type': None}, - {'action': 'store_true', 'const': None, 'dest': None, 'flag': '-u', - 'help': 'Show usage', 'name': '--usage', 'nargs': None, 'type': None}] - - # Test the fifth condition - get_cluster_status_mock.return_value['enabled'] = 'yes' - args_mock.filter_status = False - args_mock.usage = True - - cluster_control.main() - exit_mock.assert_called_with(0) - - # Test the first exception - usage_mock.side_effect = KeyboardInterrupt() - cluster_control.main() - - logging_mock.reset_mock() - - # Test the second exception - args_mock.debug = True - usage_mock.side_effect = Exception() - with pytest.raises(Exception): - cluster_control.main() - logging_error_mock.assert_called_with("local variable 'my_function' referenced before assignment") - logging_mock.assert_called_once_with(level=logging.DEBUG, format='%(levelname)s: %(message)s') - - with patch('scripts.cluster_control.print_agents', return_value='') as print_agents_mock: - # Test the second condition - args_mock.usage = False - args_mock.list_agents = True - - cluster_control.main() - asyncio_run_mock.assert_called_once() - - asyncio_run_mock.reset_mock() - print_agents_mock.assert_called_once() - - with patch('scripts.cluster_control.print_nodes', return_value='') as print_nodes_mock: - # Test the third condition - args_mock.list_agents = False - args_mock.list_nodes = True - - cluster_control.main() - asyncio_run_mock.assert_called_once() - - asyncio_run_mock.reset_mock() - print_nodes_mock.assert_called_once() - - with patch('scripts.cluster_control.print_health', return_value='') as print_health_mock: - # Test the fourth condition - args_mock.list_nodes = False - args_mock.health = 'MORE' - - cluster_control.main() - asyncio_run_mock.assert_called_once() - - asyncio_run_mock.reset_mock() - print_health_mock.assert_called_once() - - # Test the sixth condition - args_mock.health = False - args_mock.debug = False - - cluster_control.main() - - exit_mock.assert_called_with(0) - assert parser_mock.called is True diff --git a/framework/scripts/tests/test_wazuh_clusterd.py b/framework/scripts/tests/test_wazuh_clusterd.py deleted file mode 100644 index 1bb78ca97de..00000000000 --- a/framework/scripts/tests/test_wazuh_clusterd.py +++ /dev/null @@ -1,401 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# Created by Wazuh, Inc. . -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import asyncio -import sys -from unittest.mock import call, patch - -import pytest -import scripts.wazuh_clusterd as wazuh_clusterd -from wazuh.core.cluster.utils import HAPROXY_DISABLED, HAPROXY_HELPER - - -def test_set_logging(): - """Check and set the behavior of set_logging function.""" - import wazuh.core.cluster.utils as cluster_utils - - wazuh_clusterd.cluster_utils = cluster_utils - with patch.object(cluster_utils, 'ClusterLogger') as clusterlogger_mock: - assert wazuh_clusterd.set_logging(foreground_mode=False, debug_mode=0) - clusterlogger_mock.assert_called_once_with( - foreground_mode=False, log_path='logs/cluster.log', debug_level=0, - tag='%(asctime)s %(levelname)s: [%(tag)s] [%(subtag)s] %(message)s') - - -@patch('builtins.print') -def test_print_version(print_mock): - """Set the scheme to be printed.""" - with patch('wazuh.core.cluster.__version__', 'TEST'): - wazuh_clusterd.print_version() - print_mock.assert_called_once_with( - '\nWazuh TEST - Wazuh Inc\n\nThis program is free software; you can redistribute it and/or modify\n' - 'it under the terms of the GNU General Public License (version 2) as \npublished by the ' - 'Free Software Foundation. For more details, go to \nhttps://www.gnu.org/licenses/gpl.html\n') - - -@patch('scripts.wazuh_clusterd.os.kill') -@patch('scripts.wazuh_clusterd.os.getpid', return_value=1001) -def test_exit_handler(os_getpid_mock, os_kill_mock): - """Set the behavior when exiting the script.""" - from wazuh.core import pyDaemonModule - - class SignalMock: - SIG_DFL = 1 - - class Signals: - def __init__(self, signum): - self.name = signum - - @staticmethod - def signal(signalnum, handler): - assert signalnum == 9 - assert handler == SignalMock.SIG_DFL - - class LoggerMock: - def __init__(self): - pass - - def info(self, msg): - pass - - def original_sig_handler(signum, frame): - pass - - original_sig_handler_not_callable = 1 - - wazuh_clusterd.main_logger = LoggerMock() - wazuh_clusterd.pyDaemonModule = pyDaemonModule - wazuh_clusterd.original_sig_handler = original_sig_handler - with patch('scripts.wazuh_clusterd.signal', SignalMock): - with patch.object(wazuh_clusterd, 'main_logger') as main_logger_mock: - with patch.object(wazuh_clusterd.pyDaemonModule, 'delete_child_pids') as delete_child_pids_mock: - with patch.object(wazuh_clusterd.pyDaemonModule, 'delete_pid') as delete_pid_mock: - with patch.object(wazuh_clusterd, 'original_sig_handler') as original_sig_handler_mock: - wazuh_clusterd.exit_handler(9, 99) - main_logger_mock.assert_has_calls([call.info('SIGNAL [(9)-(9)] received. Exit...')]) - delete_child_pids_mock.assert_called_once_with( - 'wazuh-clusterd', os_getpid_mock.return_value, main_logger_mock) - delete_pid_mock.assert_called_once_with('wazuh-clusterd', os_getpid_mock.return_value) - original_sig_handler_mock.assert_called_once_with(9, 99) - main_logger_mock.reset_mock() - delete_child_pids_mock.reset_mock() - delete_pid_mock.reset_mock() - original_sig_handler_mock.reset_mock() - - wazuh_clusterd.original_sig_handler = original_sig_handler_not_callable - wazuh_clusterd.exit_handler(9, 99) - main_logger_mock.assert_has_calls([call.info('SIGNAL [(9)-(9)] received. Exit...')]) - delete_child_pids_mock.assert_called_once_with('wazuh-clusterd', 1001, main_logger_mock) - delete_pid_mock.assert_called_once_with('wazuh-clusterd', 1001) - original_sig_handler_mock.assert_not_called() - -@pytest.mark.parametrize('helper_disabled', (True, False)) -@pytest.mark.asyncio -async def test_master_main(helper_disabled: bool): - """Check and set the behavior of master_main function.""" - import wazuh.core.cluster.utils as cluster_utils - cluster_config = {'test': 'config', HAPROXY_HELPER: {HAPROXY_DISABLED: helper_disabled}} - - class Arguments: - def __init__(self, performance_test, concurrency_test, ssl): - self.performance_test = performance_test - self.concurrency_test = concurrency_test - self.ssl = ssl - - class TaskPoolMock: - def __init__(self): - self._max_workers = 1 - - def map(self, first, second): - assert first == cluster_utils.process_spawn_sleep - assert second == range(1) - - class MasterMock: - def __init__(self, performance_test, concurrency_test, configuration, enable_ssl, logger, cluster_items): - assert performance_test == 'test_performance' - assert concurrency_test == 'concurrency_test' - assert configuration == cluster_config - assert enable_ssl is True - assert logger == 'test_logger' - assert cluster_items == {'node': 'item'} - self.task_pool = TaskPoolMock() - - def start(self): - return 'MASTER_START' - - class LocalServerMasterMock: - def __init__(self, performance_test, logger, concurrency_test, node, configuration, enable_ssl, cluster_items): - assert performance_test == 'test_performance' - assert logger == 'test_logger' - assert concurrency_test == 'concurrency_test' - assert configuration == cluster_config - assert enable_ssl is True - assert cluster_items == {'node': 'item'} - - def start(self): - return 'LOCALSERVER_START' - - class HAPHElperMock: - @classmethod - def start(cls): - return 'HAPHELPER_START' - - - async def gather(first, second, third=None): - assert first == 'MASTER_START' - assert second == 'LOCALSERVER_START' - if third is not None: - assert third == 'HAPHELPER_START' - - - wazuh_clusterd.cluster_utils = cluster_utils - args = Arguments(performance_test='test_performance', concurrency_test='concurrency_test', ssl=True) - with patch('scripts.wazuh_clusterd.asyncio.gather', gather): - with patch('wazuh.core.cluster.master.Master', MasterMock): - with patch('wazuh.core.cluster.local_server.LocalServerMaster', LocalServerMasterMock): - with patch('wazuh.core.cluster.hap_helper.hap_helper.HAPHelper', HAPHElperMock): - await wazuh_clusterd.master_main( - args=args, - cluster_config=cluster_config, - cluster_items={'node': 'item'}, - logger='test_logger' - ) - - -@pytest.mark.asyncio -@patch("asyncio.sleep", side_effect=IndexError) -async def test_worker_main(asyncio_sleep_mock): - """Check and set the behavior of worker_main function.""" - import wazuh.core.cluster.utils as cluster_utils - - class Arguments: - def __init__(self, performance_test, concurrency_test, ssl, send_file, send_string): - self.performance_test = performance_test - self.concurrency_test = concurrency_test - self.ssl = ssl - self.send_file = send_file - self.send_string = send_string - - class TaskPoolMock: - def __init__(self): - self._max_workers = 1 - - def map(self, first, second): - assert first == cluster_utils.process_spawn_sleep - assert second == range(1) - - class LoggerMock: - def __init__(self): - pass - - def warning(self, msg): - pass - - class WorkerMock: - def __init__(self, performance_test, concurrency_test, configuration, - enable_ssl, logger, cluster_items, file, string, task_pool): - assert performance_test == 'test_performance' - assert concurrency_test == 'concurrency_test' - assert configuration == {'test': 'config'} - assert enable_ssl is True - assert file is True - assert string is True - assert logger == 'test_logger' - assert cluster_items == {'intervals': {'worker': {'connection_retry': 34}}} - assert task_pool is None - self.task_pool = TaskPoolMock() - - def start(self): - return 'WORKER_START' - - class LocalServerWorkerMock: - def __init__(self, performance_test, logger, concurrency_test, node, configuration, enable_ssl, cluster_items): - assert performance_test == 'test_performance' - assert logger == 'test_logger' - assert concurrency_test == 'concurrency_test' - assert configuration == {'test': 'config'} - assert enable_ssl is True - assert cluster_items == {'intervals': {'worker': {'connection_retry': 34}}} - - def start(self): - return 'LOCALSERVER_START' - - async def gather(first, second): - assert first == 'WORKER_START' - assert second == 'LOCALSERVER_START' - raise asyncio.CancelledError() - - wazuh_clusterd.cluster_utils = cluster_utils - wazuh_clusterd.main_logger = LoggerMock - args = Arguments(performance_test='test_performance', concurrency_test='concurrency_test', ssl=True, - send_file=True, send_string=True) - - with patch.object(wazuh_clusterd, 'main_logger') as main_logger_mock: - with patch('concurrent.futures.ProcessPoolExecutor', side_effect=FileNotFoundError) as processpoolexecutor_mock: - with patch('scripts.wazuh_clusterd.asyncio.gather', gather): - with patch('scripts.wazuh_clusterd.logging.info') as logging_info_mock: - with patch('wazuh.core.cluster.worker.Worker', WorkerMock): - with patch('wazuh.core.cluster.local_server.LocalServerWorker', LocalServerWorkerMock): - with pytest.raises(IndexError): - await wazuh_clusterd.worker_main( - args=args, cluster_config={'test': 'config'}, - cluster_items={'intervals': {'worker': {'connection_retry': 34}}}, - logger='test_logger') - processpoolexecutor_mock.assert_called_once_with(max_workers=1) - main_logger_mock.assert_has_calls([ - call.warning( - "In order to take advantage of Wazuh 4.3.0 cluster improvements, the directory " - "'/dev/shm' must be accessible by the 'wazuh' user. Check that this file has " - "permissions to be accessed by all users. Changing the file permissions to 777 " - "will solve this issue."), - call.warning( - 'The Wazuh cluster will be run without the improvements added in Wazuh 4.3.0 and ' - 'higher versions.') - ]) - logging_info_mock.assert_called_once_with('Connection with server has been lost. ' - 'Reconnecting in 10 seconds.') - asyncio_sleep_mock.assert_called_once_with(34) - - -@patch('scripts.wazuh_clusterd.argparse.ArgumentParser') -def test_get_script_arguments(argument_parser_mock): - """Set the wazuh_clusterd script parameters.""" - from wazuh.core import common - - wazuh_clusterd.common = common - with patch.object(wazuh_clusterd.common, 'OSSEC_CONF', 'testing/path'): - wazuh_clusterd.get_script_arguments() - argument_parser_mock.assert_called_once_with() - argument_parser_mock.return_value.add_argument.assert_has_calls( - [call('--performance_test', type=int, dest='performance_test', help='==SUPPRESS=='), - call('--concurrency_test', type=int, dest='concurrency_test', help='==SUPPRESS=='), - call('--string', help='==SUPPRESS==', type=int, dest='send_string'), - call('--file', help='==SUPPRESS==', type=str, dest='send_file'), - call('--ssl', help='Enable communication over SSL', action='store_true', dest='ssl', default=False), - call('-f', help='Run in foreground', action='store_true', dest='foreground'), - call('-d', help='Enable debug messages. Use twice to increase verbosity.', action='count', - dest='debug_level'), - call('-V', help='Print version', action='store_true', dest='version'), - call('-r', help='Run as root', action='store_true', dest='root'), - call('-t', help='Test configuration', action='store_true', dest='test_config'), - call('-c', help='Configuration file to use', type=str, metavar='config', dest='config_file', - default=common.OSSEC_CONF)]) - - -@patch('scripts.wazuh_clusterd.sys.exit', side_effect=sys.exit) -@patch('scripts.wazuh_clusterd.os.getpid', return_value=543) -@patch('scripts.wazuh_clusterd.os.setgid') -@patch('scripts.wazuh_clusterd.os.setuid') -@patch('scripts.wazuh_clusterd.os.chmod') -@patch('scripts.wazuh_clusterd.os.chown') -@patch('scripts.wazuh_clusterd.os.path.exists', return_value=True) -@patch('builtins.print') -def test_main(print_mock, path_exists_mock, chown_mock, chmod_mock, setuid_mock, setgid_mock, getpid_mock, exit_mock): - """Check and set the behavior of wazuh_clusterd main function.""" - import wazuh.core.cluster.utils as cluster_utils - from wazuh.core import common, pyDaemonModule - - class Arguments: - def __init__(self, config_file, test_config, foreground, root): - self.config_file = config_file - self.test_config = test_config - self.foreground = foreground - self.root = root - - class LoggerMock: - def __init__(self): - pass - - def info(self, msg): - pass - - def error(self, msg): - pass - - args = Arguments(config_file='test', test_config=True, foreground=False, root=False) - wazuh_clusterd.main_logger = LoggerMock() - wazuh_clusterd.args = args - wazuh_clusterd.common = common - wazuh_clusterd.pyDaemonModule = pyDaemonModule - wazuh_clusterd.cluster_utils = cluster_utils - with patch.object(common, 'wazuh_uid', return_value='uid_test'): - with patch.object(common, 'wazuh_gid', return_value='gid_test'): - - with patch.object(wazuh_clusterd.cluster_utils, 'read_config', - return_value={'disabled': False, 'node_type': 'master'}): - with patch.object(wazuh_clusterd.main_logger, 'error') as main_logger_mock: - with patch.object(wazuh_clusterd.main_logger, 'info') as main_logger_info_mock: - with patch.object(wazuh_clusterd.cluster_utils, 'read_config', side_effect=Exception): - with pytest.raises(SystemExit): - wazuh_clusterd.main() - main_logger_mock.assert_called_once() - main_logger_mock.reset_mock() - path_exists_mock.assert_any_call(f'{common.WAZUH_PATH}/logs/cluster.log') - chown_mock.assert_called_with(f'{common.WAZUH_PATH}/logs/cluster.log', 'uid_test', - 'gid_test') - chmod_mock.assert_called_with(f'{common.WAZUH_PATH}/logs/cluster.log', 432) - exit_mock.assert_called_once_with(1) - exit_mock.reset_mock() - - with patch.object(wazuh_clusterd.cluster_utils, 'read_config', return_value={'disabled': True}): - with pytest.raises(SystemExit): - wazuh_clusterd.main() - exit_mock.assert_called_once_with(0) - exit_mock.reset_mock() - - with patch('wazuh.core.cluster.cluster.check_cluster_config', side_effect=IndexError): - with pytest.raises(SystemExit): - wazuh_clusterd.main() - main_logger_mock.assert_called_once() - exit_mock.assert_called_once_with(1) - exit_mock.reset_mock() - - with patch('wazuh.core.cluster.cluster.check_cluster_config', return_value=None): - with pytest.raises(SystemExit): - wazuh_clusterd.main() - main_logger_mock.assert_called_once() - exit_mock.assert_called_once_with(0) - main_logger_mock.reset_mock() - exit_mock.reset_mock() - - args.test_config = False - wazuh_clusterd.args = args - with patch('wazuh.core.cluster.cluster.clean_up') as clean_up_mock: - with patch('scripts.wazuh_clusterd.clean_pid_files') as clean_pid_files_mock: - with patch.object(wazuh_clusterd.pyDaemonModule, 'pyDaemon') as pyDaemon_mock: - with patch.object(wazuh_clusterd.pyDaemonModule, - 'create_pid') as create_pid_mock: - with patch.object(wazuh_clusterd.pyDaemonModule, 'delete_child_pids'): - with patch.object(wazuh_clusterd.pyDaemonModule, - 'delete_pid') as delete_pid_mock: - wazuh_clusterd.main() - main_logger_mock.assert_any_call( - "Unhandled exception: name 'cluster_items' is not defined") - clean_up_mock.assert_called_once() - clean_pid_files_mock.assert_called_once_with('wazuh-clusterd') - pyDaemon_mock.assert_called_once() - setuid_mock.assert_called_once_with('uid_test') - setgid_mock.assert_called_once_with('gid_test') - getpid_mock.assert_called() - create_pid_mock.assert_called_once_with('wazuh-clusterd', 543) - delete_pid_mock.assert_called_once_with('wazuh-clusterd', 543) - - args.foreground = True - wazuh_clusterd.main() - print_mock.assert_called_once_with( - 'Starting cluster in foreground (pid: 543)') - - wazuh_clusterd.cluster_items = {} - with patch('scripts.wazuh_clusterd.master_main', - side_effect=KeyboardInterrupt('TESTING')): - wazuh_clusterd.main() - main_logger_info_mock.assert_any_call( - 'SIGINT received. Bye!') - - with patch('scripts.wazuh_clusterd.master_main', - side_effect=MemoryError('TESTING')): - wazuh_clusterd.main() - main_logger_mock.assert_any_call( - "Directory '/tmp' needs read, write & execution " - "permission for 'wazuh' user") diff --git a/framework/scripts/tests/test_wazuh_logtest.py b/framework/scripts/tests/test_wazuh_logtest.py deleted file mode 100644 index 5845ea33263..00000000000 --- a/framework/scripts/tests/test_wazuh_logtest.py +++ /dev/null @@ -1,607 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2015, Wazuh Inc. -# Created by Wazuh, Inc. . -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import logging -import socket -import sys -from datetime import timedelta -from unittest.mock import patch, call - -import pytest - -import scripts.wazuh_logtest as wazuh_logtest - - -class WazuhSocketMock: - """Auxiliary mock.""" - - def __init__(self): - self.request = None - self.exception = False - - def send(self, request): - self.request = request - - if not self.exception: - return b'' - else: - raise ConnectionError() - - -class WazuhDeamonProtocolMock: - """Auxiliary mock.""" - - def __init__(self): - self.msg = None - self.data = None - self.recv_package = None - self.reply = {'codemsg': 0, 'token': 'last token', - 'output': {'rule': {'id': 1, 'level': 1}, 'decoder': {'name': 'name'}}} - - def wrap(self, msg, data): - self.msg = msg - self.data = data - - return '' - - def unwrap(self, recv_package): - self.recv_package = recv_package - - return self.reply - - -@patch('argparse.ArgumentParser') -def test_init_argparse(argument_parser_mock): - """Check if argparse is being properly handling command line parameters.""" - class ArgumentParserMock: - """Auxiliary class.""" - def __init__(self): - self.flag = [] - self.help = [] - self.action = [] - self.dest = [] - self.metavar = [] - self.default = [] - - def add_argument(self, flag, help='', action='', dest='', metavar='', default=''): - self.flag.append(flag) - self.help.append(help) - self.action.append(action) - self.dest.append(dest) - self.metavar.append(metavar) - self.default.append(default) - - argument_parser_mock.return_value = ArgumentParserMock() - wazuh_logtest.init_argparse() - - argument_parser_mock.assert_called_once_with(description='Tool for developing, tuning, and debugging rules.') - assert argument_parser_mock.return_value.flag == ['-V', '-d', '-U', '-l', '-q', '-v'] - assert argument_parser_mock.return_value.help == ['Version and license message', 'Execute in debug mode', - 'Unit test. Refer to ruleset/testing/runtests.py', - 'Use custom location. Default "stdin"', - 'Quiet execution', 'Verbose (full) output/rule debugging'] - assert argument_parser_mock.return_value.action == ['store_true', 'store_true', '', '', 'store_true', 'store_true'] - assert argument_parser_mock.return_value.dest == ['version', 'debug', 'ut', 'location', 'quiet', 'verbose'] - assert argument_parser_mock.return_value.metavar == ['', '', 'rule:alert:decoder', 'location', '', ''] - assert argument_parser_mock.return_value.default == ['', '', '', 'stdin', '', ''] - - -@patch('sys.exit') -@patch('logging.info') -@patch('logging.error') -@patch('logging.warning') -@patch('atexit.register') -@patch('scripts.wazuh_logtest.init_logger') -@patch('scripts.wazuh_logtest.WazuhLogtest') -@patch('scripts.wazuh_logtest.init_argparse') -@patch('builtins.input', return_value='mock') -def test_main(input_mock, argparse_mock, wazuh_logtest_class_mock, init_logger_mock, register_mock, logger_warning_mock, - logger_error_mock, logger_info_mock, sys_exit_mock): - """Test the main function.""" - - class ArgsMock: - """Auxiliary class.""" - - def __init__(self): - self.ut = "mock:mock" - self.version = "1.0.0" - self.location = "World" - self.verbose = True - - class ParserMock: - """Auxiliary class.""" - - def __init__(self): - self.args = ArgsMock() - - def parse_args(self): - return self.args - - class WazuhLogtestMock: - """Auxiliary class.""" - - def __init__(self, get_last_ut_mock=False, process_log_exception=None): - self.location = None - self.show_last_ut_result_called = False - self.remove_last_session_called = False - self.get_last_ut_called = False - self.process_log_called = False - self.get_last_ut_mock = get_last_ut_mock - self.process_log_exception = process_log_exception - - def show_last_ut_result(self, ut): - self.show_last_ut_result_called = True - raise Exception("Break the 'while'") - - def remove_last_session(self): - self.remove_last_session_called = True - pass - - def get_last_ut(self): - self.get_last_ut_called = True - if not self.get_last_ut_mock: - return "mock:mock" - else: - return ['3', '3', '3'] - - def process_log(self, event, session_token, options): - self.process_log_called = True - if self.process_log_exception == 'ValueError': - raise ValueError() - elif self.process_log_exception == 'ConnectionError': - raise ConnectionError() - else: - return {'token': 'sth', 'messages': ['WARNING']} - - argparse_mock.return_value = ParserMock() - wazuh_logtest_class_mock.return_value = WazuhLogtestMock() - - # Test the first 'try' present in the 'while' - try: - wazuh_logtest.main() - except Exception as e: - pass - - argparse_mock.assert_called_once_with() - init_logger_mock.assert_called_once_with(argparse_mock.return_value.args) - input_mock.assert_called_once_with('\n') - register_mock.assert_called_once_with(wazuh_logtest_class_mock.return_value.remove_last_session) - sys_exit_mock.assert_has_calls([call(0), call(1)]) - - logger_info_mock.assert_has_calls([call('%s', 'Wazuh ERROR - Wazuh Inc.'), - call('%s', '\nThis program is free software; you can redistribute it and/or ' - 'modify\nit under the terms of the GNU General Public License ' - '(version 2) as\npublished by the Free Software Foundation. For more ' - 'details, go to\nhttps://www.gnu.org/licenses/gpl.html\n'), - call('Starting wazuh-logtest %s', 'ERROR'), - call('Type one log per line')]) - logger_error_mock.assert_called_once_with('Unit test configuration wrong syntax: %s', - wazuh_logtest_class_mock.return_value.get_last_ut()) - logger_warning_mock.assert_has_calls([call('** Wazuh-Logtest: %s', 'WARNING'), call('')]) - - assert wazuh_logtest_class_mock.return_value.show_last_ut_result_called is True - assert wazuh_logtest_class_mock.return_value.remove_last_session_called is False - assert wazuh_logtest_class_mock.return_value.get_last_ut_called is True - assert wazuh_logtest_class_mock.return_value.process_log_called is True - - # Test the first exception -> first condition - input_mock.side_effect = EOFError() - argparse_mock.return_value.args.ut = False - argparse_mock.return_value.args.version = False - - try: - wazuh_logtest.main() - except Exception: - pass - - sys_exit_mock.assert_called_with(0) - - # Test the first exception -> third condition - argparse_mock.return_value.args.ut = '3:3:3' - try: - wazuh_logtest.main() - except Exception: - pass - - sys_exit_mock.assert_called_with(1) - - # Test the first exception -> second condition - wazuh_logtest_class_mock.return_value = WazuhLogtestMock(True) - - try: - wazuh_logtest.main() - except Exception: - pass - - # Test the second exception - argparse_mock.return_value.args.ut = False - input_mock.side_effect = None - wazuh_logtest_class_mock.return_value = WazuhLogtestMock(process_log_exception='ValueError') - logger_error_mock.side_effect = Exception() - logger_error_mock.reset_mock() - - try: - wazuh_logtest.main() - except Exception: - pass - - logger_error_mock.assert_called_once_with('** Wazuh-logtest error ') - - # Test the third exception - logger_error_mock.reset_mock() - wazuh_logtest_class_mock.return_value = WazuhLogtestMock(process_log_exception='ConnectionError') - logger_error_mock.side_effect = Exception() - - try: - wazuh_logtest.main() - except Exception: - pass - - logger_error_mock.assert_called_once_with('** Wazuh-logtest error when connecting with wazuh-analysisd') - - -# Test WazuhDaemonProtocol class methods - -def create_wazuh_daemon_protocol_class(): - """Create new WazuhDaemonProtocol class.""" - return wazuh_logtest.WazuhDeamonProtocol() - - -def test_wdp_init(): - """Test the init method, checking the initial status of its attributes.""" - wdp = create_wazuh_daemon_protocol_class() - - assert isinstance(wdp.protocol, dict) - assert wdp.protocol['version'] == 1 - assert isinstance(wdp.protocol['origin'], dict) - assert wdp.protocol['origin']['name'] == 'wazuh-logtest' - assert wdp.protocol['origin']['module'] == 'wazuh-logtest' - - -@patch('json.dumps', return_value='') -def test_wdp_wrap(json_dumps_mock): - """Test if the data is being properly wrapped with wazuh daemon protocol information.""" - wdp = create_wazuh_daemon_protocol_class() - assert wdp.wrap(command='command', parameters={'parameters': 'parameters'}) == json_dumps_mock.return_value - json_dumps_mock.assert_called_once_with({'version': 1, 'origin': {'name': 'wazuh-logtest', 'module': - 'wazuh-logtest'}, 'command': 'command', 'parameters': - {'parameters': 'parameters'}}) - - -@patch('json.loads', return_value={'error': 'error', 'message': 'message'}) -def test_wdp_unwrap(json_loads_mock): - """Test if the data is being properly unwrapped from the wazuh daemon protocol.""" - wdp = create_wazuh_daemon_protocol_class() - msg = {} - - # Test if - with pytest.raises(ValueError, match=f"{json_loads_mock.return_value['error']}: " - f"{json_loads_mock.return_value['message']}") as e: - wdp.unwrap(msg=msg) - - json_loads_mock.assert_called_once_with(msg) - - # Test the rest of the method - json_loads_mock.return_value = {'data': 'data', 'error': ''} - assert wdp.unwrap(msg) == json_loads_mock.return_value['data'] - - -# Test WazuhSocket methods - -def create_wazuh_socket_class(file): - """Create a new WazuhSocket class.""" - return wazuh_logtest.WazuhSocket(file=file) - - -def test_ws_init(): - """Test the correct start of the WazuhSocket class.""" - file = '' - assert create_wazuh_socket_class(file).file == file - - -@patch('socket.socket') -@patch('socket.AF_UNIX') -@patch('socket.SOCK_STREAM') -@patch('socket.MSG_WAITALL') -@patch('struct.pack', return_value=b'pack') -@patch('struct.unpack', return_value=[1, 'unpack']) -def test_ws_sent(unpack_mock, pack_mock, msg_waitall_mock, stream_mock, unix_mock, socket_socket_mock): - """Test the correct data sending and reception.""" - - class WLogtestConn: - """Auxiliary class.""" - - def __init__(self): - self.connected = False - self.sent = False - self.received = False - self.closed = False - self.socket = [] - self.size = [] - self.msg = [] - - def connect(self, file): - self.connected = True - - def send(self, msg): - self.msg.append(msg) - self.sent = True - - def recv(self, size, socket): - self.received = True - self.socket.append(socket) - self.size.append(size) - return '' - - def close(self): - self.closed = True - - file = '' - socket_socket_mock.return_value = WLogtestConn() - ws = create_wazuh_socket_class(file=file) - - # Test the try - assert ws.send(file) == '' - socket_socket_mock.assert_called_once_with(unix_mock, stream_mock) - assert socket_socket_mock.return_value.connected is True - pack_mock.assert_called_once_with('. -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import argparse -import asyncio -import logging -import os -import signal -import sys - -from wazuh.core.utils import clean_pid_files -from wazuh.core.wlogging import WazuhLogger - -# -# Aux functions -# - -def set_logging(foreground_mode=False, debug_mode=0) -> WazuhLogger: - """Set cluster logger. - - Parameters - ---------- - foreground_mode : bool - Whether to log in the standard output or not. - debug_mode : int - Debug mode. - - Returns - ------- - WazuhLogger - Cluster logger. - """ - cluster_logger = cluster_utils.ClusterLogger(foreground_mode=foreground_mode, log_path='logs/cluster.log', - debug_level=debug_mode, - tag='%(asctime)s %(levelname)s: [%(tag)s] [%(subtag)s] %(message)s') - cluster_logger.setup_logger() - return cluster_logger - - -def print_version(): - """Print Wazuh metadata.""" - from wazuh.core.cluster import __author__, __licence__, __version__, __wazuh_name__ - print(f"\n{__wazuh_name__} {__version__} - {__author__}\n\n{__licence__}") - - -def exit_handler(signum, frame): - cluster_pid = os.getpid() - main_logger.info(f'SIGNAL [({signum})-({signal.Signals(signum).name})] received. Exit...') - - # Terminate cluster's child processes - pyDaemonModule.delete_child_pids('wazuh-clusterd', cluster_pid, main_logger) - - # Remove cluster's pidfile - pyDaemonModule.delete_pid('wazuh-clusterd', cluster_pid) - - if callable(original_sig_handler): - original_sig_handler(signum, frame) - elif original_sig_handler == signal.SIG_DFL: - # Call default handler if the original one can't be run - signal.signal(signum, signal.SIG_DFL) - os.kill(os.getpid(), signum) - - -# -# Master main -# -async def master_main(args: argparse.Namespace, cluster_config: dict, cluster_items: dict, logger: WazuhLogger): - """Start main process of the master node. - - Parameters - ---------- - args : argparse.Namespace - Script arguments. - cluster_config : dict - Cluster configuration. - cluster_items : dict - Content of the cluster.json file. - logger : WazuhLogger - Cluster logger. - """ - from wazuh.core.cluster import local_server, master - from wazuh.core.cluster.hap_helper.hap_helper import HAPHelper - - cluster_utils.context_tag.set('Master') - my_server = master.Master(performance_test=args.performance_test, concurrency_test=args.concurrency_test, - configuration=cluster_config, enable_ssl=args.ssl, logger=logger, - cluster_items=cluster_items) - # Spawn pool processes - if my_server.task_pool is not None: - my_server.task_pool.map(cluster_utils.process_spawn_sleep, range(my_server.task_pool._max_workers)) - - my_local_server = local_server.LocalServerMaster(performance_test=args.performance_test, logger=logger, - concurrency_test=args.concurrency_test, node=my_server, - configuration=cluster_config, enable_ssl=args.ssl, - cluster_items=cluster_items) - tasks = [my_server, my_local_server] - if not cluster_config.get(cluster_utils.HAPROXY_HELPER, {}).get(cluster_utils.HAPROXY_DISABLED, True): - tasks.append(HAPHelper) - await asyncio.gather(*[task.start() for task in tasks]) - - -# -# Worker main -# -async def worker_main(args: argparse.Namespace, cluster_config: dict, cluster_items: dict, logger: WazuhLogger): - """Start main process of a worker node. - - Parameters - ---------- - args : argparse.Namespace - Script arguments. - cluster_config : dict - Cluster configuration. - cluster_items : dict - Content of the cluster.json file. - logger : WazuhLogger - Cluster logger. - """ - from concurrent.futures import ProcessPoolExecutor - - from wazuh.core.cluster import local_server, worker - cluster_utils.context_tag.set('Worker') - - # Pool is defined here so the child process is not recreated when the connection with master node is broken. - try: - task_pool = ProcessPoolExecutor(max_workers=1) - # Handle exception when the user running Wazuh cannot access /dev/shm - except (FileNotFoundError, PermissionError): - main_logger.warning( - "In order to take advantage of Wazuh 4.3.0 cluster improvements, the directory '/dev/shm' must be " - "accessible by the 'wazuh' user. Check that this file has permissions to be accessed by all users. " - "Changing the file permissions to 777 will solve this issue.") - main_logger.warning( - "The Wazuh cluster will be run without the improvements added in Wazuh 4.3.0 and higher versions.") - task_pool = None - - while True: - my_client = worker.Worker(configuration=cluster_config, enable_ssl=args.ssl, - performance_test=args.performance_test, concurrency_test=args.concurrency_test, - file=args.send_file, string=args.send_string, logger=logger, - cluster_items=cluster_items, task_pool=task_pool) - my_local_server = local_server.LocalServerWorker(performance_test=args.performance_test, logger=logger, - concurrency_test=args.concurrency_test, node=my_client, - configuration=cluster_config, enable_ssl=args.ssl, - cluster_items=cluster_items) - # Spawn pool processes - if my_client.task_pool is not None: - my_client.task_pool.map(cluster_utils.process_spawn_sleep, range(my_client.task_pool._max_workers)) - try: - await asyncio.gather(my_client.start(), my_local_server.start()) - except asyncio.CancelledError: - logging.info("Connection with server has been lost. Reconnecting in 10 seconds.") - await asyncio.sleep(cluster_items['intervals']['worker']['connection_retry']) - - -def get_script_arguments() -> argparse.Namespace: - """Get script arguments. - - Returns - ------- - argparse.Namespace - Arguments passed to the script. - """ - - parser = argparse.ArgumentParser() - #################################################################################################################### - # Dev options - Silenced in the help message. - #################################################################################################################### - # Performance test - value stored in args.performance_test will be used to send a request of that size in bytes to - # all clients/to the server. - parser.add_argument('--performance_test', type=int, dest='performance_test', help=argparse.SUPPRESS) - # Concurrency test - value stored in args.concurrency_test will be used to send that number of requests in a row, - # without sleeping. - parser.add_argument('--concurrency_test', type=int, dest='concurrency_test', help=argparse.SUPPRESS) - # Send string test - value stored in args.send_string variable will be used to send a string with that size in bytes - # to the server. Only implemented in worker nodes. - parser.add_argument('--string', help=argparse.SUPPRESS, type=int, dest='send_string') - # Send file test - value stored in args.send_file variable is the path of a file to send to the server. Only - # implemented in worker nodes. - parser.add_argument('--file', help=argparse.SUPPRESS, type=str, dest='send_file') - #################################################################################################################### - parser.add_argument('--ssl', help="Enable communication over SSL", action='store_true', dest='ssl', default=False) - parser.add_argument('-f', help="Run in foreground", action='store_true', dest='foreground') - parser.add_argument('-d', help="Enable debug messages. Use twice to increase verbosity.", action='count', - dest='debug_level') - parser.add_argument('-V', help="Print version", action='store_true', dest="version") - parser.add_argument('-r', help="Run as root", action='store_true', dest='root') - parser.add_argument('-t', help="Test configuration", action='store_true', dest='test_config') - parser.add_argument('-c', help="Configuration file to use", type=str, metavar='config', dest='config_file', - default=common.OSSEC_CONF) - - return parser - - -def main(): - """Main function of the wazuh-clusterd script in charge of starting the cluster process.""" - import wazuh.core.cluster.cluster - - # Set correct permissions on cluster.log file - if os.path.exists(f'{common.WAZUH_PATH}/logs/cluster.log'): - os.chown(f'{common.WAZUH_PATH}/logs/cluster.log', common.wazuh_uid(), common.wazuh_gid()) - os.chmod(f'{common.WAZUH_PATH}/logs/cluster.log', 0o660) - - try: - cluster_configuration = cluster_utils.read_config(config_file=args.config_file) - except Exception as e: - main_logger.error(e) - sys.exit(1) - - if cluster_configuration['disabled']: - sys.exit(0) - try: - wazuh.core.cluster.cluster.check_cluster_config(cluster_configuration) - except Exception as e: - main_logger.error(e) - sys.exit(1) - - if args.test_config: - sys.exit(0) - - # Clean cluster files from previous executions - wazuh.core.cluster.cluster.clean_up() - - # Check for unused PID files - clean_pid_files('wazuh-clusterd') - - # Foreground/Daemon - if not args.foreground: - pyDaemonModule.pyDaemon() - - # Drop privileges to wazuh - if not args.root: - os.setgid(common.wazuh_gid()) - os.setuid(common.wazuh_uid()) - - pid = os.getpid() - pyDaemonModule.create_pid('wazuh-clusterd', pid) - if args.foreground: - print(f"Starting cluster in foreground (pid: {pid})") - - main_function = master_main if cluster_configuration['node_type'] == 'master' else worker_main - try: - asyncio.run(main_function(args, cluster_configuration, cluster_items, main_logger)) - except KeyboardInterrupt: - main_logger.info("SIGINT received. Bye!") - except MemoryError: - main_logger.error("Directory '/tmp' needs read, write & execution " - "permission for 'wazuh' user") - except Exception as e: - main_logger.error(f"Unhandled exception: {e}") - finally: - pyDaemonModule.delete_child_pids('wazuh-clusterd', pid, main_logger) - pyDaemonModule.delete_pid('wazuh-clusterd', pid) - - -if __name__ == '__main__': - import wazuh.core.cluster.utils as cluster_utils - from wazuh.core import common, configuration, pyDaemonModule - - cluster_items = cluster_utils.get_cluster_items() - original_sig_handler = signal.signal(signal.SIGTERM, exit_handler) - - args = get_script_arguments().parse_args() - if args.version: - print_version() - sys.exit(0) - - # Set logger - try: - debug_mode_ = configuration.get_internal_options_value('wazuh_clusterd', 'debug', 2, 0) or args.debug_level - except Exception: - debug_mode_ = 0 - - main_logger = set_logging(foreground_mode=args.foreground, debug_mode=debug_mode_) - main() diff --git a/framework/scripts/wazuh_logtest.py b/framework/scripts/wazuh_logtest.py deleted file mode 100644 index a05e50a8388..00000000000 --- a/framework/scripts/wazuh_logtest.py +++ /dev/null @@ -1,597 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2015, Wazuh Inc. -# Created by Wazuh, Inc. . -# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -import argparse -import atexit -import json -import logging -import os -import socket -import struct -import subprocess -import sys -import textwrap -from typing import Union - -from wazuh.core import common -from wazuh.core.common import LOGTEST_SOCKET - - -def init_argparse() -> argparse.Namespace: - """Setup argparse for handle command line parameters. - - Returns - ------- - argparse.Namespace - Arguments passed to the script. - """ - parser = argparse.ArgumentParser( - description="Tool for developing, tuning, and debugging rules." - ) - parser.add_argument( - "-V", help='Version and license message', - action="store_true", - dest='version' - ) - parser.add_argument( - "-d", help='Execute in debug mode', - action="store_true", - dest='debug' - ) - parser.add_argument( - "-U", help='Unit test. Refer to ruleset/testing/runtests.py', - metavar='rule:alert:decoder', - dest='ut' - ) - parser.add_argument( - "-l", help='Use custom location. Default "stdin"', - default='stdin', - metavar='location', - dest='location' - ) - parser.add_argument( - "-q", help='Quiet execution', - dest='quiet', - action="store_true" - ) - parser.add_argument( - '-v', help='Verbose (full) output/rule debugging', - dest='verbose', - action='store_true' - ) - return parser - - -def main(): - """wazuh-logtest main function.""" - # Parse cmdline args - parser = init_argparse() - args = parser.parse_args() - init_logger(args) - - # Handle version request - if args.version: - logging.info('%s', Wazuh.get_description()) - logging.info('%s', Wazuh.get_license()) - sys.exit(0) - - # Handle unit test request - if args.ut: - ut = args.ut.split(":") - if len(ut) != 3: - logging.error('Unit test configuration wrong syntax: %s', args.ut) - sys.exit(1) - options = dict() - if args.verbose: - options['rules_debug'] = True - - # Initialize wazuh-logtest component - w_logtest = WazuhLogtest(location=args.location) - logging.info('Starting wazuh-logtest %s', Wazuh.get_version_str()) - logging.info('Type one log per line') - - # Cleanup: remove session before exit - atexit.register(w_logtest.remove_last_session) - - # Main processing loop - session_token = str() - - while True: - # Get user input - try: - event = input('\n') - - # Handle user interrupt execution or EOF - except (EOFError, KeyboardInterrupt): - # Exit normally if ut is not selected - if not args.ut: - sys.exit(0) - # Check if ut match - elif ut == w_logtest.get_last_ut(): - # Workarround to support runtest.py - sys.exit(ut.count('')) - # Exit with error - else: - sys.exit(1) - - # Avoid empty events - if not event: - continue - # Empty line to separate input from processing - logging.info('') - - # Process log event - try: - output = w_logtest.process_log(event, session_token, options) - except ValueError as error: - logging.error('** Wazuh-logtest error ' + str(error)) - continue - except ConnectionError: - logging.error('** Wazuh-logtest error when connecting with wazuh-analysisd') - continue - # Check and alert to user if new session was created - if session_token and session_token != output['token']: - logging.warning('New session was created with token "%s"', output['token']) - - # Show the warning messages - if 'messages' in output.keys(): - do_print_newline = False - for message in output['messages']: - if message.startswith("WARNING"): - logging.warning('** Wazuh-Logtest: %s', message) - do_print_newline = True - if do_print_newline: - logging.warning('') - - # Continue using last available session - session_token = output['token'] - - # Show wazuh-logtest output - WazuhLogtest.show_output(output) - - # Show UT info - if args.ut: - w_logtest.show_last_ut_result(ut) - - -class WazuhDeamonProtocol: - """Encapsulate logic communication aspects between Wazuh daemons.""" - - def __init__(self, version: int = 1, origin_module: str = "wazuh-logtest", module_name: str = "wazuh-logtest"): - """Class constructor. - - Parameters - ---------- - version :int - Protocol version. Default: 1 - origin_module : str - Origin source module. Default: "wazuh-logtest" - module_name : str - Source module name. Default: "wazuh-logtest" - """ - self.protocol = dict() - self.protocol['version'] = version - self.protocol['origin'] = dict() - self.protocol['origin']['name'] = origin_module - self.protocol['origin']['module'] = module_name - - def wrap(self, command: str, parameters: dict) -> str: - """Wrap data with Wazuh daemon protocol information. - - Parameters - ---------- - command : str - Endpoint command. - parameters : dict - Data to wrap. - - Returns - ------- - dict - Wrapped data. - """ - # Use default protocol template - msg = self.protocol - msg['command'] = command - msg['parameters'] = parameters - # Dump dict to str - str_msg = json.dumps(msg) - return str_msg - - def unwrap(self, msg: dict) -> dict: - """Unwrap data from Wazuh daemon protocol information. - - Parameters - ---------- - msg :dict - Data to unwrap - - Returns - ------- - dict - Unwrapped data. - """ - # Convert string to json - json_msg = json.loads(msg) - # Get only the payload - if json_msg['error']: - error_msg = json_msg['message'] - error_n = json_msg['error'] - raise ValueError(f'{error_n}: {error_msg}') - data = json_msg['data'] - return data - - -class WazuhSocket: - """Encapsulate wazuh-socket communication (header with message size).""" - - def __init__(self, file: str): - """Class constructor. - - Parameters - ---------- - file : str - Socket path. - """ - self.file = file - - def send(self, msg: str) -> bytes: - """Send and receive data to wazuh-socket (header with message size). - - Parameters - ---------- - msg : str - Data to send. - - Returns - ------- - bytes - Received data. - """ - try: - wlogtest_conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - wlogtest_conn.connect(self.file) - encoded_msg = msg.encode('utf-8') - wlogtest_conn.send(struct.pack("/var/log/syslog" - log_format : str - Type of log. Default: "syslog" - """ - self.protocol = WazuhDeamonProtocol() - self.socket = WazuhSocket(LOGTEST_SOCKET) - self.fixed_fields = dict() - self.fixed_fields['location'] = location - self.fixed_fields['log_format'] = log_format - self.last_token = "" - self.ut = [''] * 3 - - def process_log(self, log, token: str = None, options: str = None) -> dict: - """Send log event to wazuh-logtest and receive the outcome. - - Parameters - ---------- - log : str - Event log to process. - token : str - Session token. Default: None. - - Raises - ------ - ValueError - - Returns - ------- - dict - Logtest outcome. - """ - - # Use basic logtest template - data = self.fixed_fields - - # Use token if specified - if token: - data['token'] = token - data['event'] = log - - if options: - data['options'] = options - - # Create a wrapper to log_processing - request = self.protocol.wrap('log_processing', data) - logging.debug('Request: %s\n', request) - recv_packet = self.socket.send(request) - - # Get logtest reply - logging.debug(f'Reply: %s\n', str(recv_packet, 'utf-8')) - reply = self.protocol.unwrap(recv_packet) - - if reply['codemsg'] < 0: - error_msg = ['\n\t{0}'.format(i) for i in reply['messages']] - error_n = reply['codemsg'] - raise ValueError(f'{error_n}: {"".join(error_msg)}') - - # Save the token - self.last_token = reply['token'] - - # Store unit test data - self.ut = [''] * 3 - if 'rule' in reply['output']: - self.ut[0] = reply['output']['rule']['id'] - self.ut[1] = str(reply['output']['rule']['level']) - if 'decoder' in reply['output'] and reply['output']['decoder']: - self.ut[2] = reply['output']['decoder']['name'] - # Return logtest payload - return reply - - def remove_session(self, token: str) -> bool: - """Remove session by token. - - Parameters - ---------- - token : str - Token of the session to be removed. - - Returns - ------- - bool - True if the session was removed successfully, False otherwise. - """ - - # Use basic logtest template - data = self.fixed_fields - data['token'] = token - logging.debug('Removing session with token %s.', data['token']) - # Create a wrapper to remove_session - request = self.protocol.wrap('remove_session', data) - try: - recv_packet = self.socket.send(request) - except ConnectionError: - return False - - # Get logtest payload - reply = self.protocol.unwrap(recv_packet) - - if reply['codemsg'] < 0: - return False - else: - return True - - def remove_last_session(self) -> Union[bool, None]: - """Remove last known session. - - Returns - ------- - bool or None - True if the session was removed successfully, False if the session was not removed, and None if the last - session is unknown. - """ - if self.last_token: - self.remove_session(self.last_token) - - def get_last_ut(self) -> list[str]: - """Get last known UT info (rule, alert, decoder). - - Returns - ------- - list[str] - List containing the last rule, alert, and decoder. - """ - return self.ut - - def show_output(output: dict): - """Display logtest event processing outcome. - - Parameters - ---------- - output : dict - Logtest outcome. - """ - logging.debug(json.dumps(output, indent=2)) - WazuhLogtest.show_ossec_logtest_like(output) - - def show_ossec_logtest_like(output: dict): - """Show wazuh-logtest output like ossec-logtest. - - Parameters - ---------- - output : dict - Wazuh-logtest outcome. - """ - output_data = output['output'] - # Pre-decoding phase - logging.info('**Phase 1: Completed pre-decoding.') - # Check in case rule has no_full_log attribute - if 'full_log' in output_data: - logging.info("\tfull event: '%s'", output_data.pop('full_log')) - if 'predecoder' in output_data: - WazuhLogtest.show_phase_info(output_data['predecoder'], ['timestamp', 'hostname', 'program_name']) - # Decoding phase - logging.info('') - logging.info('**Phase 2: Completed decoding.') - if 'decoder' in output_data and output_data['decoder']: - WazuhLogtest.show_phase_info(output_data['decoder'], ['name', 'parent']) - if 'data' in output_data: - WazuhLogtest.show_phase_info(output_data['data']) - else: - logging.info('\tNo decoder matched.') - - # Rule phase - - ## Rules Debugging - if 'rules_debug' in output: - logging.info('') - logging.info('**Rule debugging:') - for debug_msg in output['rules_debug']: - logging.info(('\t\t' if debug_msg[0] == '*' else '\t') + debug_msg) - - if 'rule' in output_data: - logging.info('') - logging.info('**Phase 3: Completed filtering (rules).') - WazuhLogtest.show_phase_info(output_data['rule'], ['id', 'level', 'description', 'groups', 'firedtimes']) - if output['alert']: - logging.info('**Alert to be generated.') - - def show_phase_info(phase_data: dict, show_first: list = None, prefix: str = ""): - """Show wazuh-logtest processing phase information. - - Parameters - ---------- - phase_data : dict - Phase info to display. - show_first : list - Fields to be shown first. - prefix : str - Add prefix to the name of the field to print. - """ - show_first = show_first or [] - # Ordered fields first - for field in show_first: - if field in phase_data: - logging.info("\t%s: '%s'", field, phase_data.pop(field)) - # Remaining fields then - for field in sorted(phase_data.keys()): - if isinstance(phase_data.get(field), dict): - WazuhLogtest.show_phase_info(phase_data.pop(field), [], prefix + field + '.') - else: - logging.info("\t%s: '%s'", prefix + field, phase_data.pop(field)) - - def show_last_ut_result(self, ut: list[str]): - """Display unit test result. - - Parameters - ---------- - ut : list[str] - Expected rule,alert,decoder - """ - result = self.get_last_ut() == ut - logging.info('') - if result: - logging.info('Unit test OK') - else: - logging.info('Unit test FAIL. Expected %s , Result %s', ut, self.get_last_ut()) - - -class Wazuh: - def get_install_path() -> str: - """Get Wazuh installation path, obtained relative to the path of this file. - - Returns - ------- - str - Wazuh installation path. - """ - return common.find_wazuh_path() - - def get_info(field: str) -> str: - """Get Wazuh information from wazuh-control. - - Parameters - ---------- - field : str - Field to get. - - Returns - ------- - str - Field value. - """ - wazuh_control = os.path.join(Wazuh.get_install_path(), "bin", "wazuh-control") - wazuh_env_vars = dict() - try: - proc = subprocess.Popen([wazuh_control, "info"], stdout=subprocess.PIPE) - (stdout, stderr) = proc.communicate() - except: - return "ERROR" - - env_variables = stdout.decode().rsplit("\n") - env_variables.remove("") - for env_variable in env_variables: - key, value = env_variable.split("=") - wazuh_env_vars[key] = value.replace("\"", "") - - return wazuh_env_vars[field] - - def get_version_str() -> str: - """Get Wazuh version string. - - Returns - ------- - str - Wazuh version. - """ - return Wazuh.get_info('WAZUH_VERSION') - - def get_description() -> str: - """Get Wazuh description, contact info and version. - - Returns - ------- - str - Wazuh description. - """ - return f"Wazuh {Wazuh.get_version_str()} - Wazuh Inc." - - def get_license() -> str: - """Get Wazuh License statement. - - Returns - ------- - str - Wazuh License. - """ - return textwrap.dedent(''' - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License (version 2) as - published by the Free Software Foundation. For more details, go to - https://www.gnu.org/licenses/gpl.html - ''') - - -def init_logger(args: argparse.Namespace): - """Initialize wazuh-logtest logger. - - Parameters - ------- - argparse.Namespace - Arguments passed to the script. - """ - # Default logger configs - logger_level = 'INFO' - logger_fmt = '%(message)s' - - # Debug level if requested - if args.debug: - logger_level = 'DEBUG' - logger_fmt = '%(asctime)-15s %(module)s[%(levelname)s] %(message)s' - - # Handle quiet request - if args.quiet: - logger_level = 'ERROR' - logger_fmt = '' - - # Set logging configs - logging.basicConfig(format=logger_fmt, level=logger_level) - - -if __name__ == "__main__": - main() diff --git a/src/Makefile b/src/Makefile index a131a854fb3..8324c50c743 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1599,7 +1599,6 @@ ifneq (,$(filter ${TEST},YES yes y Y 1)) AR_LDFLAGS+=${CFLAGS_TEST} OSSEC_LIBS+=${LIBS_TEST} - UNIT_TEST_WRAPPERS:=${wrappers_common_o} UNIT_TEST_WRAPPERS+=${wrappers_externals_o} UNIT_TEST_WRAPPERS+=${wrappers_externals_bzip2_o} UNIT_TEST_WRAPPERS+=${wrappers_externals_zlib_o} @@ -1611,23 +1610,9 @@ ifneq (,$(filter ${TEST},YES yes y Y 1)) UNIT_TEST_WRAPPERS+=${wrappers_posix_o} UNIT_TEST_WRAPPERS+=${wrappers_wazuh_o} UNIT_TEST_WRAPPERS+=${wrappers_wazuh_os_crypto_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_os_execd_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_os_net_o} UNIT_TEST_WRAPPERS+=${wrappers_wazuh_os_regex_o} UNIT_TEST_WRAPPERS+=${wrappers_wazuh_os_xml_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_shared_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_syscheckd_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_wazuh_db_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_wazuh_modules_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_monitord_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_os_auth_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_addagent_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_config_o} - UNIT_TEST_WRAPPERS+=${wrappers_client_agent_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_remoted_o} - UNIT_TEST_WRAPPERS+=${wrappers_wazuh_analysisd_o} UNIT_TEST_WRAPPERS+=${wrappers_data_provider_o} - UNIT_TEST_WRAPPERS+=${wrappers_logcollector_o} ifeq (${TARGET},winagent) UNIT_TEST_WRAPPERS+=${wrappers_windows_o} @@ -1708,7 +1693,7 @@ crypto_o := ${crypto_blowfish_o} \ #### libwazuh ######### -libwazuh.a: ${crypto_o} ${shared_o} ${os_zlib_o} ${UNIT_TEST_WRAPPERS} ${manage_agents} +libwazuh.a: ${crypto_o} ${os_zlib_o} ${UNIT_TEST_WRAPPERS} ${manage_agents} ${OSSEC_LINK} $@ $^ ${OSSEC_RANLIB} $@ @@ -2115,31 +2100,7 @@ clean-internals: clean-unit-tests rm -f ${os_zlib_o} rm -f ${os_xml_o} rm -f ${os_regex_o} - rm -f ${os_net_o} - rm -f ${shared_o} shared/debug_op_proc.o shared/file_op_proc.o - rm -f ${config_o} - rm -f ${os_maild_o} rm -f ${crypto_o} - rm -f ${os_csyslogd_o} - rm -f ${os_dbd_o} - rm -f ${os_agentlessd_o} - rm -f ${os_execd_o} - rm -f ${os_logcollector_o} ${os_logcollector_eventchannel_o} - rm -f ${remoted_o} - rm -f ${report_o} - rm -f ${client_agent_o} - rm -f ${addagent_o} - rm -f ${active_response_o} ${active_response_programs} firewall-drop - rm -f ${util_o} ${util_programs} - rm -f ${rootcheck_o} librootcheck.a - rm -f ${monitor_o} - rm -f ${os_auth_o} - rm -f ${all_analysisd_o} ${all_analysisd_libs} analysisd/compiled_rules/compiled_rules.h analysisd/logmsg.o - rm -f ${integrator_o} - rm -f ${wmodulesd_o} ${wmodules_o} $(wildcard wazuh_modules/agent_upgrade/agent/*.o) - rm -f ${wdb_o} - rm -f wazuh_db/*.o - rm -f wazuh_db/helpers/*.o rm -f ${SELINUX_MODULE} rm -f ${SELINUX_POLICY} rm -f $(WAZUH_LIB) @@ -2149,20 +2110,15 @@ clean-internals: clean-unit-tests rm -rf $(SHARED_MODULES)utils/flatbuffers/include/ rm -rf $(wildcard $(VULNERABILITY_SCANNER)include/*_generated.h) rm -rf $(SYSINFO)build - rm -rf $(SYSCHECK)build rm -rf ${SHARED_MODULES}http-request/build rm -rf build rm -rf libwazuhext rm -rf libstdc++.so.6 rm -rf libgcc_s.so.1 rm -f libwazuh.a - rm -f shared/*.o clean-unit-tests: - rm -f ${wrappers_syscheck_o} - rm -f ${wrappers_shared_o} - rm -f ${wrappers_common_o} rm -f ${wrappers_externals_o} rm -f ${wrappers_externals_audit_o} rm -f ${wrappers_externals_bzip2_o} @@ -2180,25 +2136,11 @@ clean-unit-tests: rm -f ${wrappers_posix_o} rm -f ${wrappers_wazuh_o} rm -f ${wrappers_wazuh_os_crypto_o} - rm -f ${wrappers_wazuh_os_execd_o} - rm -f ${wrappers_wazuh_os_net_o} rm -f ${wrappers_wazuh_os_regex_o} rm -f ${wrappers_wazuh_os_xml_o} - rm -f ${wrappers_wazuh_shared_o} - rm -f ${wrappers_wazuh_syscheckd_o} - rm -f ${wrappers_wazuh_wazuh_db_o} - rm -f ${wrappers_wazuh_wazuh_modules_o} - rm -f ${wrappers_wazuh_monitord_o} - rm -f ${wrappers_wazuh_os_auth_o} - rm -f ${wrappers_wazuh_addagent_o} - rm -f ${wrappers_wazuh_config_o} rm -f ${wrappers_windows_o} rm -f ${wrappers_windows_lib_o} rm -f ${wrappers_windows_posix_o} - rm -f ${wrappers_client_agent_o} - rm -f ${wrappers_wazuh_remoted_o} - rm -f ${wrappers_wazuh_analysisd_o} - rm -f ${wrappers_logcollector_o} rm -f ${wrappers_macos_o} rm -f ${wrappers_data_provider_o} diff --git a/src/unit_tests/active-response/CMakeLists.txt b/src/unit_tests/active-response/CMakeLists.txt deleted file mode 100644 index 9c7512873f0..00000000000 --- a/src/unit_tests/active-response/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Generate active-response library -file(GLOB active-response_files - ${SRC_FOLDER}/active-response/*.o) - -add_library(ACTIVE-RESPONSE_O STATIC ${active-response_files}) - -set_source_files_properties( - ${active-response_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - ACTIVE-RESPONSE_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(ACTIVE-RESPONSE_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -# Generate active-response tests -if(NOT ${TARGET} STREQUAL "winagent") - list(APPEND active-response_names "test_active-response") - list(APPEND active-response_flags "-Wl,--wrap,getaddrinfo -Wl,--wrap,fcntl") -endif() - -list(LENGTH active-response_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET active-response_names ${counter} active-response_test_name) - list(GET active-response_flags ${counter} active-response_test_flags) - - add_executable(${active-response_test_name} ${active-response_test_name}.c) - - target_link_libraries( - ${active-response_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - ACTIVE-RESPONSE_O - ${TEST_DEPS} - ) - if(NOT active-response_test_flags STREQUAL " ") - target_link_libraries( - ${active-response_test_name} - ${active-response_test_flags} - ) - endif() - add_test(NAME ${active-response_test_name} COMMAND ${active-response_test_name}) -endforeach() \ No newline at end of file diff --git a/src/unit_tests/active-response/test_active-response.c b/src/unit_tests/active-response/test_active-response.c deleted file mode 100644 index 062d27da431..00000000000 --- a/src/unit_tests/active-response/test_active-response.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../active-response/active_responses.h" - -#include "../wrappers/common.h" - -// Structs -typedef struct test_struct { - struct addrinfo *addr; -} test_struct_t; - -// Setup / Teardown - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1, sizeof(struct addrinfo), init_data->addr); - os_calloc(1, sizeof(struct sockaddr), init_data->addr->ai_addr); - - *state = init_data; - - test_mode = 1; - - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - os_free(data->addr->ai_addr); - os_free(data->addr); - os_free(data); - - test_mode = 0; - - return OS_SUCCESS; -} - -// Tests -void test_get_ip_version_success_ipv4(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *dummy_ipaddr = ""; - - data->addr->ai_family = AF_INET; - - expect_string(__wrap_getaddrinfo, node, dummy_ipaddr); - will_return(__wrap_getaddrinfo, data->addr); - will_return(__wrap_getaddrinfo, 0); //0 means success - - int ret = get_ip_version(dummy_ipaddr); - - assert_int_equal(ret, 4); -} - -void test_get_ip_version_success_ipv6(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *dummy_ipaddr = ""; - - data->addr->ai_family = AF_INET6; - - expect_string(__wrap_getaddrinfo, node, dummy_ipaddr); - will_return(__wrap_getaddrinfo, data->addr); - will_return(__wrap_getaddrinfo, 0); //0 means success - - int ret = get_ip_version(dummy_ipaddr); - - assert_int_equal(ret, 6); -} - -void test_get_ip_version_no_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *dummy_ipaddr = ""; - - data->addr->ai_family = AF_INET6; - - expect_string(__wrap_getaddrinfo, node, dummy_ipaddr); - will_return(__wrap_getaddrinfo, data->addr); - will_return(__wrap_getaddrinfo, 1); - - int ret = get_ip_version(dummy_ipaddr); - - assert_int_equal(ret, -1); //OS_INVALID -} - -void test_get_ip_version_success_invalid_ip(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *dummy_ipaddr = ""; - - data->addr->ai_family = -1; //invalid family - - expect_string(__wrap_getaddrinfo, node, dummy_ipaddr); - will_return(__wrap_getaddrinfo, data->addr); - will_return(__wrap_getaddrinfo, 0); //0 means success - - int ret = get_ip_version(dummy_ipaddr); - - assert_int_equal(ret, -1); //OS_INVALID -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_get_ip_version_success_ipv4, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_ip_version_success_ipv6, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_ip_version_no_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_ip_version_success_invalid_ip, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/addagent/CMakeLists.txt b/src/unit_tests/addagent/CMakeLists.txt deleted file mode 100644 index 9bc4e067382..00000000000 --- a/src/unit_tests/addagent/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Generate addagent library -file(GLOB addagent_files - ${SRC_FOLDER}/addagent/*.o) - -list(REMOVE_ITEM addagent_files ${SRC_FOLDER}/addagent/main.o) - -add_library(ADDAGENT_O STATIC ${addagent_files}) - -set_source_files_properties( - ${addagent_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - ADDAGENT_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(ADDAGENT_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -list(APPEND addagent_names "test_manage_keys") -list(APPEND addagent_flags "${DEBUG_OP_WRAPPERS} ${STDIO_OP_WRAPPERS} \ - -Wl,--wrap,mkstemp_ex \ - -Wl,--wrap,stat -Wl,--wrap,chmod -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fprintf -Wl,--wrap,fgets -Wl,--wrap,rename_ex\ - -Wl,--wrap,encode_base64 -Wl,--wrap,decode_base64 -Wl,--wrap,wfopen -Wl,--wrap,popen") - -list(LENGTH addagent_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET addagent_names ${counter} addagent_test_name) - list(GET addagent_flags ${counter} addagent_test_flags) - - add_executable(${addagent_test_name} ${addagent_test_name}.c) - - target_link_libraries( - ${addagent_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - ADDAGENT_O - ${TEST_DEPS} - ) - if(NOT addagent_test_flags STREQUAL " ") - target_link_libraries( - ${addagent_test_name} - ${addagent_test_flags} - ) - endif() - add_test(NAME ${addagent_test_name} COMMAND ${addagent_test_name}) -endforeach() diff --git a/src/unit_tests/addagent/test_manage_keys.c b/src/unit_tests/addagent/test_manage_keys.c deleted file mode 100644 index 88e19da16d7..00000000000 --- a/src/unit_tests/addagent/test_manage_keys.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../addagent/manage_agents.h" -#include "../wrappers/common.h" -#include "../wrappers/libc/stdlib_wrappers.h" -#include "../wrappers/wazuh/shared/b64_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" - -#define CLIENT_KEYS_FILENAME "tmp/client.keysXXXXXX" -#define KEY_ENCODED "MDEzIHVidW50dTIyYWdlbnQgYW55IDVmMjIwMmI2MmVkNTJjYTY3ZWIwZGMyZmRmZDZmODlmNmNlMDllZjNjNTY3NTk2ZTNhMTU3MzEzNmI3NjNkYmY=" -#define KEY_DECODED_SUCCESSFUL "013 ubuntu22agent any 5f2202b62ed52ca67eb0dc2fdfd6f89f6ce09ef3c567596e3a1573136b763dbf" -#define KEY_DECODED_INVALID "013-invalidformat-any 5f2202b62ed52ca67eb0dc2fdfd6f89f6ce09ef3c567596e3a1573136b763dbf" - -char shost[512]; - -static int test_setup(void **state) { - (void) state; - test_mode = 1; - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - (void) state; - test_mode = 0; - return OS_SUCCESS; -} - -void test_k_import_successful(void **state) { - (void) state; - - expect_decode_base64( - KEY_ENCODED, - KEY_DECODED_SUCCESSFUL - ); - - expect_mkstemp_ex(CLIENT_KEYS_FILENAME, 0); - - expect_string(__wrap_chmod, path, CLIENT_KEYS_FILENAME); - will_return(__wrap_chmod, 0); - - expect_string(__wrap_wfopen, path, CLIENT_KEYS_FILENAME); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, "test"); - - expect_value(__wrap_fprintf, __stream, "test"); - expect_string(__wrap_fprintf, formatted_msg, KEY_DECODED_SUCCESSFUL "\n"); - will_return(__wrap_fprintf, 0); - - expect_value(__wrap_fclose, _File, "test"); - will_return(__wrap_fclose, 1); - - expect_rename_ex(CLIENT_KEYS_FILENAME, KEYS_FILE, 0); - - putenv("OSSEC_ACTION_CONFIRMED=y"); - - int retval = k_import(KEY_ENCODED); - assert_int_equal(retval, 1); -} - -void test_k_import_keyinvalid(void **state) { - (void) state; - - expect_decode_base64( - KEY_ENCODED, - KEY_DECODED_INVALID - ); - - expect_value(__wrap_fgets, __stream, stdin); - will_return(__wrap_fgets, "\r\n"); - - int retval = k_import(KEY_ENCODED); - assert_int_equal(retval, 0); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_k_import_successful, NULL, NULL), - cmocka_unit_test_setup_teardown(test_k_import_keyinvalid, NULL, NULL), - }; - - return cmocka_run_group_tests(tests, test_setup, test_teardown); -} diff --git a/src/unit_tests/analysisd/CMakeLists.txt b/src/unit_tests/analysisd/CMakeLists.txt deleted file mode 100644 index f2a7f83bbaf..00000000000 --- a/src/unit_tests/analysisd/CMakeLists.txt +++ /dev/null @@ -1,197 +0,0 @@ -# Generate analysisd library -file(GLOB analysisd_files - ${SRC_FOLDER}/analysisd/*.o - ${SRC_FOLDER}/analysisd/alerts/*.o - ${SRC_FOLDER}/analysisd/cdb/*.o - ${SRC_FOLDER}/analysisd/compiled_rules/*.o - ${SRC_FOLDER}/analysisd/decoders/*.o - ${SRC_FOLDER}/analysisd/output/*.o - ${SRC_FOLDER}/analysisd/format/*.o - ${SRC_FOLDER}/analysisd/decoders/plugins/*.o - ${SRC_FOLDER}/analysisd/format/*.o - ${SRC_FOLDER}/analysisd/output/*.o - ) - -add_library(ANALYSISD_O STATIC ${analysisd_files}) - -include_directories(${SRC_FOLDER}/analysisd) - -set_source_files_properties( - ${analysisd_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - ANALYSISD_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(ANALYSISD_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate Analysisd tests -list(APPEND analysisd_names "test_analysisd_syscheck") -list(APPEND analysisd_flags "-Wl,--wrap,wdbc_query_ex -Wl,--wrap,wdbc_parse_result ${DEBUG_OP_WRAPPERS}") - -list(APPEND analysisd_names "test_cleanevent") -list(APPEND analysisd_flags "${DEBUG_OP_WRAPPERS}") - -list(APPEND analysisd_names "test_dbsync") -list(APPEND analysisd_flags "-Wl,--wrap,OS_ConnectUnixDomain -Wl,--wrap,OS_SendSecureTCP \ - -Wl,--wrap,connect_to_remoted -Wl,--wrap,send_msg_to_agent -Wl,--wrap,wdbc_query_ex \ - -Wl,--wrap,wdbc_parse_result ${DEBUG_OP_WRAPPERS}") - -list(APPEND analysisd_names "test_exec") -list(APPEND analysisd_flags "-Wl,--wrap,OS_SendUnix -Wl,--wrap,wdb_get_agent_info -Wl,--wrap,Eventinfo_to_jsonstr \ - -Wl,--wrap,OS_ReadXML -Wl,--wrap,OS_GetOneContentforElement -Wl,--wrap,OS_ClearXML -Wl,--wrap,StartMQ \ - -Wl,--wrap,wdb_get_agents_by_connection_status -Wl,--wrap,labels_find -Wl,--wrap,labels_get -Wl,--wrap,labels_free \ - -Wl,--wrap,OS_IPFoundList \ - -Wl,--wrap,OSMatch_Execute \ - -Wl,--wrap,OSRegex_Compile -Wl,--wrap,OSRegex_Execute_ex -Wl,--wrap,OSRegex_Execute \ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND analysisd_names "test_log") -list(APPEND analysisd_flags "-Wl,--wrap,fprintf,-wrap,fflush,--wrap,fclose,--wrap,fgets,--wrap,fgetpos,--wrap,fopen \ - -Wl,--wrap,fread,--wrap,fseek,--wrap,fwrite,--wrap,remove,--wrap,fgetc,--wrap,fputc \ - -Wl,--wrap,ctime_r -Wl,--wrap,wfopen -Wl,--wrap,popen") - -list(APPEND analysisd_names "test_labels") -list(APPEND analysisd_flags "-Wl,--wrap,wdb_get_agent_labels") - -list(APPEND analysisd_names "test_mitre") -list(APPEND analysisd_flags "-Wl,--wrap,wdbc_query_ex -Wl,--wrap,wdbc_query_parse_json ${HASH_OP_WRAPPERS} ${DEBUG_OP_WRAPPERS}") - -list(APPEND analysisd_names "test_rules") -LIST(APPEND analysisd_flags "-Wl,--wrap,_mwarn -Wl,--wrap,_merror -Wl,--wrap,_os_analysisd_add_logmsg \ - -Wl,--wrap,OS_ClearNode -Wl,--wrap,w_get_attr_val_by_name ${DEBUG_OP_WRAPPERS}") - -LIST(APPEND analysisd_names "test_same_different_loop") -LIST(APPEND analysisd_flags "-W") - -LIST(APPEND analysisd_names "test_logtest") -LIST(APPEND analysisd_flags "-Wl,--wrap,ReadConfig -Wl,--wrap,_merror -Wl,--wrap,OS_BindUnixDomain -Wl,--wrap,OSHash_Create \ - -Wl,--wrap,pthread_mutex_init -Wl,--wrap,_minfo -Wl,--wrap,_w_mutex_init -Wl,--wrap,w_create_thread \ - -Wl,--wrap,mutex_destroy -Wl,--wrap,close -Wl,--wrap,getDefine_Int -Wl,--wrap,OSList_Create \ - -Wl,--wrap,OSList_SetMaxSize -Wl,--wrap,OSHash_setSize -Wl,--wrap,OSHash_Delete_ex \ - -Wl,--wrap,OSHash_Free -Wl,--wrap,os_remove_rules_list -Wl,--wrap,os_remove_decoders_list \ - -Wl,--wrap,os_remove_cdblist -Wl,--wrap,os_remove_cdbrules -Wl,--wrap,os_remove_eventlist \ - -Wl,--wrap,sleep -Wl,--wrap,OSHash_Begin -Wl,--wrap,OSHash_Begin_ex -Wl,--wrap,time -Wl,--wrap,difftime \ - -Wl,--wrap,OSHash_Next -Wl,--wrap,FOREVER -Wl,--wrap,OS_CreateEventList \ - -Wl,--wrap,ReadDecodeXML -Wl,--wrap,Lists_OP_LoadList -Wl,--wrap,Lists_OP_MakeAll \ - -Wl,--wrap,Rules_OP_ReadRules -Wl,--wrap,OS_ListLoadRules -Wl,--wrap,_setlevels \ - -Wl,--wrap,AddHash_Rule -Wl,--wrap,Accumulate_Init -Wl,--wrap,OSStore_Free \ - -Wl,--wrap,SetDecodeXML -Wl,--wrap,randombytes -Wl,--wrap,cJSON_IsNumber \ - -Wl,--wrap,cJSON_GetObjectItemCaseSensitive -Wl,--wrap,_mdebug1 \ - -Wl,--wrap,_os_analysisd_add_logmsg -Wl,--wrap,OSHash_Get_ex -Wl,--wrap,pthread_mutex_lock \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,OSHash_Add_ex -Wl,--wrap,OSList_GetFirstNode \ - -Wl,--wrap,cJSON_CreateArray -Wl,--wrap,cJSON_AddItemToObject -Wl,--wrap,wm_strcat \ - -Wl,--wrap,cJSON_CreateString -Wl,--wrap,cJSON_AddItemToArray \ - -Wl,--wrap,os_analysisd_free_log_msg -Wl,--wrap,OSList_DeleteCurrentlyNode \ - -Wl,--wrap,os_analysisd_string_log_msg -Wl,--wrap,cJSON_ParseWithOpts \ - -Wl,--wrap,cJSON_IsString -Wl,--wrap,cJSON_DeleteItemFromObjectCaseSensitive \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_AddNumberToObject \ - -Wl,--wrap,cJSON_PrintUnformatted -Wl,--wrap,cJSON_Delete \ - -Wl,--wrap,pthread_mutex_destroy -Wl,--wrap,cJSON_IsObject -Wl,--wrap,DecodeEvent \ - -Wl,--wrap,cJSON_GetStringValue -Wl,--wrap,OS_CleanMSG -Wl,--wrap,cJSON_GetObjectItem \ - -Wl,--wrap,OS_CheckIfRuleMatch -Wl,--wrap,OS_AddEvent -Wl,--wrap,IGnore \ - -Wl,--wrap,OSList_AddData -Wl,--wrap,accept -Wl,--wrap,OS_RecvSecureTCP \ - -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,CreateThreadJoinable -Wl,--wrap,_merror_exit \ - -Wl,--wrap,CreateThread -Wl,--wrap,pthread_join -Wl,--wrap,unlink \ - -Wl,--wrap,Eventinfo_to_jsonstr -Wl,--wrap,cJSON_Parse -Wl,--wrap,ParseRuleComment \ - -Wl,--wrap,Accumulate -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_AddBoolToObject \ - -Wl,--wrap,OSHash_SetFreeDataPointer -Wl,--wrap,OSHash_Delete \ - -Wl,--wrap,pthread_rwlock_init -Wl,--wrap,pthread_rwlock_rdlock \ - -Wl,--wrap,pthread_rwlock_unlock -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,pthread_mutex_trylock -Wl,--wrap,OSHash_Get -Wl,--wrap,OSHash_Add \ - -Wl,--wrap,OSList_CleanOnlyNodes -Wl,--wrap,w_analysisd_accumulate_free \ - -Wl,--wrap,w_get_attr_val_by_name -Wl,--wrap,OS_GetElementsbyNode -Wl,--wrap,OS_ClearNode \ - -Wl,--wrap,OS_ClearXML -Wl,--wrap,OS_ReadXML -Wl,--wrap,Read_Rules -Wl,--wrap,Read_Alerts") - -LIST(APPEND analysisd_names "test_logtest-config") -LIST(APPEND analysisd_flags "-Wl,--wrap,get_nproc -Wl,--wrap,cJSON_CreateObject \ - -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_AddNumberToObject -Wl,--wrap,cJSON_AddItemToObject \ - ${DEBUG_OP_WRAPPERS}") - -LIST(APPEND analysisd_names "test_decoder_list") -LIST(APPEND analysisd_flags "-Wl,--wrap,FreeDecoderInfo") - -LIST(APPEND analysisd_names "test_decode-xml") -LIST(APPEND analysisd_flags "-Wl,--wrap,_os_analysisd_add_logmsg -Wl,--wrap,OSStore_Create \ - -Wl,--wrap,OSStore_Put ${DEBUG_OP_WRAPPERS}") - -LIST(APPEND analysisd_names "test_lists_list") -LIST(APPEND analysisd_flags "-Wl,--wrap,OSMatch_FreePattern") - -LIST(APPEND analysisd_names "test_rule_list") -LIST(APPEND analysisd_flags "-Wl,--wrap,OSMatch_FreePattern -Wl,--wrap,OSRegex_FreePattern -Wl,--wrap,os_remove_cdbrules \ - -Wl,--wrap,_os_analysisd_add_logmsg -Wl,--wrap,OS_IsValidIP") - -LIST(APPEND analysisd_names "test_eventinfo_list") -LIST(APPEND analysisd_flags "-Wl,--wrap,Free_Eventinfo") - -LIST(APPEND analysisd_names "test_logmsg") -LIST(APPEND analysisd_flags "-Wl,--wrap,isDebug -Wl,--wrap,OSList_AddData -Wl,--wrap,vsnprintf -Wl,--wrap,_mverror \ - -Wl,--wrap,_mverror -Wl,--wrap,_mvinfo -Wl,--wrap,_mvwarn") -LIST(APPEND analysisd_names "test_decoder_rootcheck") -LIST(APPEND analysisd_flags "-Wl,--wrap,send_rootcheck_log ${DEBUG_OP_WRAPPERS}") - -LIST(APPEND analysisd_names "test_decoder_syscollector") -LIST(APPEND analysisd_flags "-Wl,--wrap,wdbc_query_ex ${DEBUG_OP_WRAPPERS}") - -LIST(APPEND analysisd_names "test_decoder_winevtchannel") -LIST(APPEND analysisd_flags "${DEBUG_OP_WRAPPERS} -Wl,--wrap,cJSON_ParseWithOpts -Wl,--wrap,cJSON_GetObjectItem \ - -Wl,--wrap,cJSON_Delete -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_CreateObject \ - -Wl,--wrap,cJSON_PrintUnformatted -Wl,--wrap,cJSON_AddItemToObject -Wl,--wrap,cJSON_AddStringToObject \ - -Wl,--wrap,JSON_Decoder_Exec \ - -Wl,--wrap,OS_ReadXMLString -Wl,--wrap,OS_GetElementsbyNode -Wl,--wrap,OS_ClearXML \ - -Wl,--wrap,w_get_attr_val_by_name") - -LIST(APPEND analysisd_names "test_decoder_winevtchannel_input") -LIST(APPEND analysisd_flags "${DEBUG_OP_WRAPPERS}") - - -list(APPEND analysisd_names "test_analysis-state") -list(APPEND analysisd_flags "-Wl,--wrap,time -Wl,--wrap,rem_get_qsize -Wl,--wrap,rem_get_tsize \ - -Wl,--wrap,OSHash_Create -Wl,--wrap,OSHash_Add -Wl,--wrap,OSHash_Add_ex -Wl,--wrap,OSHash_Begin -Wl,--wrap,OSHash_Begin_ex \ - -Wl,--wrap,OSHash_Delete_ex -Wl,--wrap,OSHash_Delete -Wl,--wrap,OSHash_Get -Wl,--wrap,OSHash_Clean \ - -Wl,--wrap,OSHash_Get_ex -Wl,--wrap,OSHash_Next -Wl,--wrap,OSHash_SetFreeDataPointer \ - -Wl,--wrap,OSHash_Update_ex -Wl,--wrap,OSHash_Update -Wl,--wrap,OSHash_Get_Elem_ex \ - -Wl,--wrap,wdb_get_agents_ids_of_current_node -Wl,--wrap,_merror -Wl,--wrap,limit_reached") - -list(APPEND analysisd_names "test_asyscom") -list(APPEND analysisd_flags "-Wl,--wrap,asys_create_state_json -Wl,--wrap,OS_BindUnixDomain -Wl,--wrap,select -Wl,--wrap,close -Wl,--wrap,accept \ - -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,getGlobalConfig -Wl,--wrap,asys_create_agents_state_json \ - -Wl,--wrap,wdb_get_agents_ids_of_current_node -Wl,--wrap,json_parse_agents -Wl,--wrap,getpid ${DEBUG_OP_WRAPPERS}") - -LIST(APPEND analysisd_names "test_limits") -LIST(APPEND analysisd_flags "-Wl,--wrap,_minfo -Wl,--wrap,_mwarn") - -list(LENGTH analysisd_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET analysisd_names ${counter} analysisd_test_name) - list(GET analysisd_flags ${counter} analysisd_test_flags) - - add_executable(${analysisd_test_name} ${analysisd_test_name}.c) - - target_link_libraries( - ${analysisd_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - ANALYSISD_O - ${TEST_DEPS} - ) - - if(NOT analysisd_test_flags STREQUAL " ") - target_link_libraries( - ${analysisd_test_name} - ${analysisd_test_flags} - ) - endif() - add_test(NAME ${analysisd_test_name} COMMAND ${analysisd_test_name}) -endforeach() diff --git a/src/unit_tests/analysisd/test_analysis-state.c b/src/unit_tests/analysisd/test_analysis-state.c deleted file mode 100644 index fe9e4f1393e..00000000000 --- a/src/unit_tests/analysisd/test_analysis-state.c +++ /dev/null @@ -1,815 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../analysisd/analysisd.h" -#include "../../analysisd/state.h" -#include "../../analysisd/config.h" - -#include "../wrappers/common.h" -#include "../wrappers/posix/time_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/shared/cluster_utils_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" - -typedef struct test_struct { - analysisd_agent_state_t *agent_state; - OSHashNode *hash_node; - cJSON * state_json; -} test_struct_t; - -extern analysisd_state_t analysisd_state; -extern queue_status_t queue_status; -extern OSHash *analysisd_agents_state; - -analysisd_agent_state_t * get_node(const char *agent_id); -void w_analysisd_clean_agents_state(int *sock); -/* setup/teardown */ - -static int test_setup(void ** state) { - Config.eps.maximum = 100; - Config.eps.timeframe = 30; - - analysisd_state.uptime = 123456789; - analysisd_state.received_bytes = 123654789; - analysisd_state.events_received = 4589; - analysisd_state.events_decoded_breakdown.agent = 1; - analysisd_state.events_decoded_breakdown.agentless = 15; - analysisd_state.events_decoded_breakdown.dbsync = 350; - analysisd_state.events_decoded_breakdown.monitor = 2; - analysisd_state.events_decoded_breakdown.remote = 8; - analysisd_state.events_decoded_breakdown.syslog = 48; - analysisd_state.events_decoded_breakdown.integrations.virustotal = 13; - analysisd_state.events_decoded_breakdown.modules.aws = 19; - analysisd_state.events_decoded_breakdown.modules.azure = 46; - analysisd_state.events_decoded_breakdown.modules.ciscat = 11; - analysisd_state.events_decoded_breakdown.modules.command = 25; - analysisd_state.events_decoded_breakdown.modules.docker = 36; - analysisd_state.events_decoded_breakdown.modules.gcp = 6; - analysisd_state.events_decoded_breakdown.modules.github = 98; - analysisd_state.events_decoded_breakdown.modules.office365 = 114; - analysisd_state.events_decoded_breakdown.modules.oscap = 2; - analysisd_state.events_decoded_breakdown.modules.osquery = 55; - analysisd_state.events_decoded_breakdown.modules.rootcheck = 149; - analysisd_state.events_decoded_breakdown.modules.sca = 1352; - analysisd_state.events_decoded_breakdown.modules.syscheck = 1258; - analysisd_state.events_decoded_breakdown.modules.syscollector = 589; - analysisd_state.events_decoded_breakdown.modules.upgrade = 1; - analysisd_state.events_decoded_breakdown.modules.vulnerability = 18; - analysisd_state.events_decoded_breakdown.modules.logcollector.eventchannel = 695; - analysisd_state.events_decoded_breakdown.modules.logcollector.eventlog = 125; - analysisd_state.events_decoded_breakdown.modules.logcollector.macos = 36; - analysisd_state.events_decoded_breakdown.modules.logcollector.others = 2011; - analysisd_state.events_dropped_breakdown.agent = 0; - analysisd_state.events_dropped_breakdown.agentless = 2; - analysisd_state.events_dropped_breakdown.dbsync = 39; - analysisd_state.events_dropped_breakdown.monitor = 0; - analysisd_state.events_dropped_breakdown.remote = 0; - analysisd_state.events_dropped_breakdown.syslog = 4; - analysisd_state.events_dropped_breakdown.integrations.virustotal = 1; - analysisd_state.events_dropped_breakdown.modules.aws = 0; - analysisd_state.events_dropped_breakdown.modules.azure = 0; - analysisd_state.events_dropped_breakdown.modules.ciscat = 0; - analysisd_state.events_dropped_breakdown.modules.command = 3; - analysisd_state.events_dropped_breakdown.modules.docker = 0; - analysisd_state.events_dropped_breakdown.modules.gcp = 1; - analysisd_state.events_dropped_breakdown.modules.github = 8; - analysisd_state.events_dropped_breakdown.modules.office365 = 12; - analysisd_state.events_dropped_breakdown.modules.oscap = 0; - analysisd_state.events_dropped_breakdown.modules.osquery = 0; - analysisd_state.events_dropped_breakdown.modules.rootcheck = 33; - analysisd_state.events_dropped_breakdown.modules.sca = 25; - analysisd_state.events_dropped_breakdown.modules.syscheck = 98; - analysisd_state.events_dropped_breakdown.modules.syscollector = 14; - analysisd_state.events_dropped_breakdown.modules.upgrade = 0; - analysisd_state.events_dropped_breakdown.modules.vulnerability = 1; - analysisd_state.events_dropped_breakdown.modules.logcollector.eventchannel = 25; - analysisd_state.events_dropped_breakdown.modules.logcollector.eventlog = 2; - analysisd_state.events_dropped_breakdown.modules.logcollector.macos = 1; - analysisd_state.events_dropped_breakdown.modules.logcollector.others = 36; - analysisd_state.events_processed = 4256; - analysisd_state.events_written_breakdown.alerts_written = 2154; - analysisd_state.events_written_breakdown.firewall_written = 148; - analysisd_state.events_written_breakdown.fts_written = 19; - analysisd_state.events_written_breakdown.stats_written = 564; - analysisd_state.events_written_breakdown.archives_written = 4200; - analysisd_state.eps_state_breakdown.events_dropped = 552; - analysisd_state.eps_state_breakdown.events_dropped_not_eps = 120; - analysisd_state.eps_state_breakdown.seconds_over_limit = 1254; - analysisd_state.eps_state_breakdown.available_credits_prev = 12; - - decode_queue_syscheck_input = queue_init(4096); - decode_queue_syscollector_input = queue_init(4096); - decode_queue_rootcheck_input = queue_init(4096); - decode_queue_sca_input = queue_init(4096); - decode_queue_hostinfo_input = queue_init(4096); - decode_queue_winevt_input = queue_init(4096); - dispatch_dbsync_input = queue_init(4096); - upgrade_module_input = queue_init(4096); - decode_queue_event_input = queue_init(4096); - decode_queue_event_output = queue_init(4096); - writer_queue_log = queue_init(4096); - writer_queue_log_firewall = queue_init(4096); - writer_queue_log_fts = queue_init(4096); - writer_queue_log_statistical = queue_init(4096); - writer_queue = queue_init(4096); - - decode_queue_syscheck_input->size = queue_status.syscheck_queue_size = 4096; - decode_queue_syscollector_input->size = queue_status.syscollector_queue_size = 4096; - decode_queue_rootcheck_input->size = queue_status.rootcheck_queue_size = 4096; - decode_queue_sca_input->size = queue_status.sca_queue_size = 4096; - decode_queue_hostinfo_input->size = queue_status.hostinfo_queue_size = 4096; - decode_queue_winevt_input->size = queue_status.winevt_queue_size = 4096; - dispatch_dbsync_input->size = queue_status.dbsync_queue_size = 4096; - upgrade_module_input->size = queue_status.upgrade_queue_size = 4096; - decode_queue_event_input->size = queue_status.events_queue_size = 4096; - decode_queue_event_output->size = queue_status.processed_queue_size = 4096; - writer_queue_log->size = queue_status.alerts_queue_size = 4096; - writer_queue_log_firewall->size = queue_status.firewall_queue_size = 4096; - writer_queue_log_fts->size = queue_status.fts_queue_size = 4096; - writer_queue_log_statistical->size = queue_status.stats_queue_size = 4096; - writer_queue->size = queue_status.archives_queue_size = 4096; - - decode_queue_syscheck_input->elements = 128; - decode_queue_syscollector_input->elements = 46; - decode_queue_rootcheck_input->elements = 87; - decode_queue_sca_input->elements = 15; - decode_queue_hostinfo_input->elements = 1; - decode_queue_winevt_input->elements = 23; - dispatch_dbsync_input->elements = 456; - upgrade_module_input->elements = 0; - decode_queue_event_input->elements = 259; - decode_queue_event_output->elements = 154; - writer_queue_log->elements = 5; - writer_queue_log_firewall->elements = 1; - writer_queue_log_fts->elements = 0; - writer_queue_log_statistical->elements = 2; - writer_queue->elements = 24; - - return 0; -} - -static int test_setup_agent(void ** state) { - test_struct_t *test_data = NULL; - os_calloc(1, sizeof(test_struct_t),test_data); - os_calloc(1, sizeof(analysisd_agent_state_t), test_data->agent_state); - os_calloc(1, sizeof(OSHashNode), test_data->hash_node); - - test_mode = 0; - will_return(__wrap_time, 123456789); - analysisd_agents_state = __wrap_OSHash_Create(); - - test_data->agent_state->uptime = 123456789; - test_data->agent_state->events_processed = 1286; - test_data->agent_state->alerts_written = 269; - test_data->agent_state->archives_written = 1286; - test_data->agent_state->firewall_written = 15; - test_data->agent_state->events_decoded_breakdown.agent = 1; - test_data->agent_state->events_decoded_breakdown.dbsync = 154; - test_data->agent_state->events_decoded_breakdown.monitor = 2; - test_data->agent_state->events_decoded_breakdown.remote = 2; - test_data->agent_state->events_decoded_breakdown.modules.aws = 39; - test_data->agent_state->events_decoded_breakdown.modules.azure = 14; - test_data->agent_state->events_decoded_breakdown.modules.ciscat = 22; - test_data->agent_state->events_decoded_breakdown.modules.command = 5; - test_data->agent_state->events_decoded_breakdown.modules.docker = 39; - test_data->agent_state->events_decoded_breakdown.modules.gcp = 12; - test_data->agent_state->events_decoded_breakdown.modules.github = 44; - test_data->agent_state->events_decoded_breakdown.modules.office365 = 6; - test_data->agent_state->events_decoded_breakdown.modules.oscap = 0; - test_data->agent_state->events_decoded_breakdown.modules.osquery = 12; - test_data->agent_state->events_decoded_breakdown.modules.rootcheck = 25; - test_data->agent_state->events_decoded_breakdown.modules.sca = 68; - test_data->agent_state->events_decoded_breakdown.modules.syscheck = 514; - test_data->agent_state->events_decoded_breakdown.modules.syscollector = 320; - test_data->agent_state->events_decoded_breakdown.modules.upgrade = 10; - test_data->agent_state->events_decoded_breakdown.modules.vulnerability = 14; - test_data->agent_state->events_decoded_breakdown.modules.logcollector.eventchannel = 37; - test_data->agent_state->events_decoded_breakdown.modules.logcollector.eventlog = 15; - test_data->agent_state->events_decoded_breakdown.modules.logcollector.macos = 36; - test_data->agent_state->events_decoded_breakdown.modules.logcollector.others = 55; - test_data->agent_state->events_decoded_breakdown.integrations.virustotal = 1; - - OSHash_Add_ex(analysisd_agents_state, "001", test_data->agent_state); - test_mode = 1; - - test_data->hash_node->key = "001"; - test_data->hash_node->data = test_data->agent_state; - - *state = test_data; - - return 0; -} - -static int test_teardown(void ** state) { - os_free(decode_queue_syscheck_input->data); - os_free(decode_queue_syscollector_input->data); - os_free(decode_queue_rootcheck_input->data); - os_free(decode_queue_sca_input->data); - os_free(decode_queue_hostinfo_input->data); - os_free(decode_queue_winevt_input->data); - os_free(dispatch_dbsync_input->data); - os_free(upgrade_module_input->data); - os_free(decode_queue_event_input->data); - os_free(decode_queue_event_output->data); - os_free(writer_queue_log->data); - os_free(writer_queue_log_firewall->data); - os_free(writer_queue_log_fts->data); - os_free(writer_queue_log_statistical->data); - os_free(writer_queue->data); - os_free(decode_queue_syscheck_input); - os_free(decode_queue_syscollector_input); - os_free(decode_queue_rootcheck_input); - os_free(decode_queue_sca_input); - os_free(decode_queue_hostinfo_input); - os_free(decode_queue_winevt_input); - os_free(dispatch_dbsync_input); - os_free(upgrade_module_input); - os_free(decode_queue_event_input); - os_free(decode_queue_event_output); - os_free(writer_queue_log); - os_free(writer_queue_log_firewall); - os_free(writer_queue_log_fts); - os_free(writer_queue_log_statistical); - os_free(writer_queue); - - return 0; -} - -static int test_teardown_agent(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - cJSON_Delete(test_data->state_json); - - if (analysisd_agents_state) { - OSHash_Free(analysisd_agents_state); - analysisd_agents_state = NULL; - } - - os_free(test_data->hash_node); - os_free(test_data); - - return 0; -} - -static int test_setup_empty_hash_table(void ** state) { - test_struct_t *test_data = NULL; - os_calloc(1, sizeof(test_struct_t),test_data); - os_calloc(1, sizeof(analysisd_agent_state_t), test_data->agent_state); - - test_data->agent_state->uptime = 123456789; - - test_mode = 0; - will_return(__wrap_time, 123456789); - analysisd_agents_state = __wrap_OSHash_Create(); - test_mode = 1; - - *state = test_data; - - return 0; -} - -static int test_teardown_empty_hash_table(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - if (analysisd_agents_state) { - OSHash_Free(analysisd_agents_state); - analysisd_agents_state = NULL; - } - - os_free(test_data->agent_state); - os_free(test_data); - - return 0; -} - -/* Tests */ - -void test_asys_create_state_json(void ** state) { - will_return(__wrap_time, 123456789); - - will_return(__wrap_limit_reached, 31); - will_return(__wrap_limit_reached, false); - - cJSON* state_json = asys_create_state_json(); - - assert_non_null(state_json); - - assert_int_equal(cJSON_GetObjectItem(state_json, "uptime")->valueint, 123456789); - - assert_non_null(cJSON_GetObjectItem(state_json, "metrics")); - cJSON* metrics = cJSON_GetObjectItem(state_json, "metrics"); - - assert_non_null(cJSON_GetObjectItem(metrics, "bytes")); - cJSON* bytes = cJSON_GetObjectItem(metrics, "bytes"); - - assert_non_null(cJSON_GetObjectItem(bytes, "received")); - assert_int_equal(cJSON_GetObjectItem(bytes, "received")->valueint, 123654789); - - assert_non_null(cJSON_GetObjectItem(metrics, "eps")); - cJSON* eps = cJSON_GetObjectItem(metrics, "eps"); - - assert_non_null(cJSON_GetObjectItem(eps, "available_credits")); - assert_int_equal(cJSON_GetObjectItem(eps, "available_credits")->valueint, 31); - - assert_non_null(cJSON_GetObjectItem(eps, "available_credits_prev")); - assert_int_equal(cJSON_GetObjectItem(eps, "available_credits_prev")->valueint, 12); - - assert_non_null(cJSON_GetObjectItem(eps, "events_dropped")); - assert_int_equal(cJSON_GetObjectItem(eps, "events_dropped")->valueint, 552); - - assert_non_null(cJSON_GetObjectItem(eps, "events_dropped_not_eps")); - assert_int_equal(cJSON_GetObjectItem(eps, "events_dropped_not_eps")->valueint, 120); - - assert_non_null(cJSON_GetObjectItem(eps, "seconds_over_limit")); - assert_int_equal(cJSON_GetObjectItem(eps, "seconds_over_limit")->valueint, 1254); - - assert_non_null(cJSON_GetObjectItem(metrics, "events")); - cJSON* events = cJSON_GetObjectItem(metrics, "events"); - - assert_non_null(cJSON_GetObjectItem(events, "processed")); - assert_int_equal(cJSON_GetObjectItem(events, "processed")->valueint, 4256); - - assert_non_null(cJSON_GetObjectItem(events, "received")); - assert_int_equal(cJSON_GetObjectItem(events, "received")->valueint, 4589); - - assert_non_null(cJSON_GetObjectItem(events, "received_breakdown")); - cJSON* recv = cJSON_GetObjectItem(events, "received_breakdown"); - - assert_non_null(cJSON_GetObjectItem(recv, "decoded_breakdown")); - cJSON* decoded = cJSON_GetObjectItem(recv, "decoded_breakdown"); - - assert_non_null(cJSON_GetObjectItem(decoded, "agent")); - assert_int_equal(cJSON_GetObjectItem(decoded, "agent")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(decoded, "agentless")); - assert_int_equal(cJSON_GetObjectItem(decoded, "agentless")->valueint, 15); - assert_non_null(cJSON_GetObjectItem(decoded, "dbsync")); - assert_int_equal(cJSON_GetObjectItem(decoded, "dbsync")->valueint, 350); - assert_non_null(cJSON_GetObjectItem(decoded, "monitor")); - assert_int_equal(cJSON_GetObjectItem(decoded, "monitor")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(decoded, "remote")); - assert_int_equal(cJSON_GetObjectItem(decoded, "remote")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(decoded, "syslog")); - assert_int_equal(cJSON_GetObjectItem(decoded, "syslog")->valueint, 48); - - assert_non_null(cJSON_GetObjectItem(decoded, "integrations_breakdown")); - cJSON* decoded_int = cJSON_GetObjectItem(decoded, "integrations_breakdown"); - - assert_non_null(cJSON_GetObjectItem(decoded_int, "virustotal")); - assert_int_equal(cJSON_GetObjectItem(decoded_int, "virustotal")->valueint, 13); - - assert_non_null(cJSON_GetObjectItem(decoded, "modules_breakdown")); - cJSON* decoded_mod = cJSON_GetObjectItem(decoded, "modules_breakdown"); - - assert_non_null(cJSON_GetObjectItem(decoded_mod, "aws")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "aws")->valueint, 19); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "azure")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "azure")->valueint, 46); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "ciscat")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "ciscat")->valueint, 11); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "command")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "command")->valueint, 25); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "docker")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "docker")->valueint, 36); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "gcp")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "gcp")->valueint, 6); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "github")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "github")->valueint, 98); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "office365")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "office365")->valueint, 114); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "oscap")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "oscap")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "osquery")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "osquery")->valueint, 55); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "rootcheck")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "rootcheck")->valueint, 149); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "sca")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "sca")->valueint, 1352); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "syscheck")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "syscheck")->valueint, 1258); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "syscollector")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "syscollector")->valueint, 589); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "upgrade")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "upgrade")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(decoded_mod, "vulnerability")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod, "vulnerability")->valueint, 18); - - assert_non_null(cJSON_GetObjectItem(decoded_mod, "logcollector_breakdown")); - cJSON* decoded_mod_log = cJSON_GetObjectItem(decoded_mod, "logcollector_breakdown"); - - assert_non_null(cJSON_GetObjectItem(decoded_mod_log, "eventchannel")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod_log, "eventchannel")->valueint, 695); - assert_non_null(cJSON_GetObjectItem(decoded_mod_log, "eventlog")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod_log, "eventlog")->valueint, 125); - assert_non_null(cJSON_GetObjectItem(decoded_mod_log, "macos")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod_log, "macos")->valueint, 36); - assert_non_null(cJSON_GetObjectItem(decoded_mod_log, "others")); - assert_int_equal(cJSON_GetObjectItem(decoded_mod_log, "others")->valueint, 2011); - - assert_non_null(cJSON_GetObjectItem(recv, "dropped_breakdown")); - cJSON* dropped = cJSON_GetObjectItem(recv, "dropped_breakdown"); - - assert_non_null(cJSON_GetObjectItem(dropped, "agent")); - assert_int_equal(cJSON_GetObjectItem(dropped, "agent")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped, "agentless")); - assert_int_equal(cJSON_GetObjectItem(dropped, "agentless")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(dropped, "dbsync")); - assert_int_equal(cJSON_GetObjectItem(dropped, "dbsync")->valueint, 39); - assert_non_null(cJSON_GetObjectItem(dropped, "monitor")); - assert_int_equal(cJSON_GetObjectItem(dropped, "monitor")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped, "remote")); - assert_int_equal(cJSON_GetObjectItem(dropped, "remote")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped, "syslog")); - assert_int_equal(cJSON_GetObjectItem(dropped, "syslog")->valueint, 4); - - assert_non_null(cJSON_GetObjectItem(dropped, "integrations_breakdown")); - cJSON* dropped_int = cJSON_GetObjectItem(dropped, "integrations_breakdown"); - - assert_non_null(cJSON_GetObjectItem(dropped_int, "virustotal")); - assert_int_equal(cJSON_GetObjectItem(dropped_int, "virustotal")->valueint, 1); - - assert_non_null(cJSON_GetObjectItem(dropped, "modules_breakdown")); - cJSON* dropped_mod = cJSON_GetObjectItem(dropped, "modules_breakdown"); - - assert_non_null(cJSON_GetObjectItem(dropped_mod, "aws")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "aws")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "azure")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "azure")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "ciscat")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "ciscat")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "command")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "command")->valueint, 3); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "docker")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "docker")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "gcp")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "gcp")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "github")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "github")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "office365")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "office365")->valueint, 12); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "oscap")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "oscap")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "osquery")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "osquery")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "rootcheck")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "rootcheck")->valueint, 33); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "sca")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "sca")->valueint, 25); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "syscheck")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "syscheck")->valueint, 98); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "syscollector")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "syscollector")->valueint, 14); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "upgrade")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "upgrade")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(dropped_mod, "vulnerability")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod, "vulnerability")->valueint, 1); - - assert_non_null(cJSON_GetObjectItem(dropped_mod, "logcollector_breakdown")); - cJSON* dropped_mod_log = cJSON_GetObjectItem(dropped_mod, "logcollector_breakdown"); - - assert_non_null(cJSON_GetObjectItem(dropped_mod_log, "eventchannel")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod_log, "eventchannel")->valueint, 25); - assert_non_null(cJSON_GetObjectItem(dropped_mod_log, "eventlog")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod_log, "eventlog")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(dropped_mod_log, "macos")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod_log, "macos")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(dropped_mod_log, "others")); - assert_int_equal(cJSON_GetObjectItem(dropped_mod_log, "others")->valueint, 36); - - assert_non_null(cJSON_GetObjectItem(events, "written_breakdown")); - cJSON* written = cJSON_GetObjectItem(events, "written_breakdown"); - - assert_non_null(cJSON_GetObjectItem(written, "alerts")); - assert_int_equal(cJSON_GetObjectItem(written, "alerts")->valueint, 2154); - - assert_non_null(cJSON_GetObjectItem(written, "firewall")); - assert_int_equal(cJSON_GetObjectItem(written, "firewall")->valueint, 148); - - assert_non_null(cJSON_GetObjectItem(written, "fts")); - assert_int_equal(cJSON_GetObjectItem(written, "fts")->valueint, 19); - - assert_non_null(cJSON_GetObjectItem(written, "stats")); - assert_int_equal(cJSON_GetObjectItem(written, "stats")->valueint, 564); - - assert_non_null(cJSON_GetObjectItem(written, "archives")); - assert_int_equal(cJSON_GetObjectItem(written, "archives")->valueint, 4200); - - assert_non_null(cJSON_GetObjectItem(metrics, "queues")); - cJSON* queue = cJSON_GetObjectItem(metrics, "queues"); - - cJSON* syscheck = cJSON_GetObjectItem(queue, "syscheck"); - assert_non_null(cJSON_GetObjectItem(syscheck, "usage")); - assert_float_equal(cJSON_GetObjectItem(syscheck, "usage")->valuedouble, 0.031, 0.001); - assert_non_null(cJSON_GetObjectItem(syscheck, "size")); - assert_int_equal(cJSON_GetObjectItem(syscheck, "size")->valueint, 4096); - cJSON* syscollector = cJSON_GetObjectItem(queue, "syscollector"); - assert_non_null(cJSON_GetObjectItem(syscollector, "usage")); - assert_float_equal(cJSON_GetObjectItem(syscollector, "usage")->valuedouble, 0.011, 0.001); - assert_non_null(cJSON_GetObjectItem(syscollector, "size")); - assert_int_equal(cJSON_GetObjectItem(syscollector, "size")->valueint, 4096); - cJSON* rootcheck = cJSON_GetObjectItem(queue, "rootcheck"); - assert_non_null(cJSON_GetObjectItem(rootcheck, "usage")); - assert_float_equal(cJSON_GetObjectItem(rootcheck, "usage")->valuedouble, 0.021, 0.001); - assert_non_null(cJSON_GetObjectItem(rootcheck, "size")); - assert_int_equal(cJSON_GetObjectItem(rootcheck, "size")->valueint, 4096); - cJSON* sca = cJSON_GetObjectItem(queue, "sca"); - assert_non_null(cJSON_GetObjectItem(sca, "usage")); - assert_float_equal(cJSON_GetObjectItem(sca, "usage")->valuedouble, 0.003, 0.001); - assert_non_null(cJSON_GetObjectItem(sca, "size")); - assert_int_equal(cJSON_GetObjectItem(sca, "size")->valueint, 4096); - cJSON* hostinfo = cJSON_GetObjectItem(queue, "hostinfo"); - assert_non_null(cJSON_GetObjectItem(hostinfo, "usage")); - assert_float_equal(cJSON_GetObjectItem(hostinfo, "usage")->valuedouble, 0, 0.001); - assert_non_null(cJSON_GetObjectItem(hostinfo, "size")); - assert_int_equal(cJSON_GetObjectItem(hostinfo, "size")->valueint, 4096); - cJSON* eventchannel = cJSON_GetObjectItem(queue, "eventchannel"); - assert_non_null(cJSON_GetObjectItem(eventchannel, "usage")); - assert_float_equal(cJSON_GetObjectItem(eventchannel, "usage")->valuedouble, 0.005, 0.001); - assert_non_null(cJSON_GetObjectItem(eventchannel, "size")); - assert_int_equal(cJSON_GetObjectItem(eventchannel, "size")->valueint, 4096); - cJSON* dbsync = cJSON_GetObjectItem(queue, "dbsync"); - assert_non_null(cJSON_GetObjectItem(dbsync, "usage")); - assert_float_equal(cJSON_GetObjectItem(dbsync, "usage")->valuedouble, 0.111, 0.001); - assert_non_null(cJSON_GetObjectItem(dbsync, "size")); - assert_int_equal(cJSON_GetObjectItem(dbsync, "size")->valueint, 4096); - cJSON* upgrade = cJSON_GetObjectItem(queue, "upgrade"); - assert_non_null(cJSON_GetObjectItem(upgrade, "usage")); - assert_float_equal(cJSON_GetObjectItem(upgrade, "usage")->valuedouble, 0, 0.001); - assert_non_null(cJSON_GetObjectItem(upgrade, "size")); - assert_int_equal(cJSON_GetObjectItem(upgrade, "size")->valueint, 4096); - cJSON* others = cJSON_GetObjectItem(queue, "others"); - assert_non_null(cJSON_GetObjectItem(others, "usage")); - assert_float_equal(cJSON_GetObjectItem(others, "usage")->valuedouble, 0.063, 0.001); - assert_non_null(cJSON_GetObjectItem(others, "size")); - assert_int_equal(cJSON_GetObjectItem(others, "size")->valueint, 4096); - cJSON* processed = cJSON_GetObjectItem(queue, "processed"); - assert_non_null(cJSON_GetObjectItem(processed, "usage")); - assert_float_equal(cJSON_GetObjectItem(processed, "usage")->valuedouble, 0.037, 0.001); - assert_non_null(cJSON_GetObjectItem(processed, "size")); - assert_int_equal(cJSON_GetObjectItem(processed, "size")->valueint, 4096); - cJSON* alerts = cJSON_GetObjectItem(queue, "alerts"); - assert_non_null(cJSON_GetObjectItem(alerts, "usage")); - assert_float_equal(cJSON_GetObjectItem(alerts, "usage")->valuedouble, 0.001, 0.001); - assert_non_null(cJSON_GetObjectItem(alerts, "size")); - assert_int_equal(cJSON_GetObjectItem(alerts, "size")->valueint, 4096); - cJSON* firewall = cJSON_GetObjectItem(queue, "firewall"); - assert_non_null(cJSON_GetObjectItem(firewall, "usage")); - assert_float_equal(cJSON_GetObjectItem(firewall, "usage")->valuedouble, 0, 0.001); - assert_non_null(cJSON_GetObjectItem(firewall, "size")); - assert_int_equal(cJSON_GetObjectItem(firewall, "size")->valueint, 4096); - cJSON* fts = cJSON_GetObjectItem(queue, "fts"); - assert_non_null(cJSON_GetObjectItem(fts, "usage")); - assert_float_equal(cJSON_GetObjectItem(fts, "usage")->valuedouble, 0, 0.001); - assert_non_null(cJSON_GetObjectItem(fts, "size")); - assert_int_equal(cJSON_GetObjectItem(fts, "size")->valueint, 4096); - cJSON* stats = cJSON_GetObjectItem(queue, "stats"); - assert_non_null(cJSON_GetObjectItem(stats, "usage")); - assert_float_equal(cJSON_GetObjectItem(stats, "usage")->valuedouble, 0, 0.001); - assert_non_null(cJSON_GetObjectItem(stats, "size")); - assert_int_equal(cJSON_GetObjectItem(stats, "size")->valueint, 4096); - cJSON* archives = cJSON_GetObjectItem(queue, "archives"); - assert_non_null(cJSON_GetObjectItem(archives, "usage")); - assert_float_equal(cJSON_GetObjectItem(archives, "usage")->valuedouble, 0.005, 0.001); - assert_non_null(cJSON_GetObjectItem(archives, "size")); - assert_int_equal(cJSON_GetObjectItem(archives, "size")->valueint, 4096); - - cJSON_Delete(state_json); -} - -void test_asys_create_agents_state_json(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - int *agents_ids = NULL; - os_calloc(2, sizeof(int), agents_ids); - agents_ids[0] = 1; - agents_ids[1] = OS_INVALID; - const char *agent_id = "001"; - - will_return(__wrap_time, 123456789); - - expect_value(__wrap_OSHash_Get_ex, self, analysisd_agents_state); - expect_string(__wrap_OSHash_Get_ex, key, agent_id); - will_return(__wrap_OSHash_Get_ex, test_data->hash_node->data); - - test_data->state_json = asys_create_agents_state_json(agents_ids); - - assert_non_null(test_data->state_json); - - assert_non_null(cJSON_GetObjectItem(test_data->state_json, "agents")); - cJSON* agents = cJSON_GetObjectItem(test_data->state_json, "agents"); - - assert_non_null(cJSON_GetArrayItem(agents, 0)); - cJSON* agent = cJSON_GetArrayItem(agents, 0); - assert_int_equal(cJSON_GetObjectItem(agent, "id")->valueint, 1); - assert_int_equal(cJSON_GetObjectItem(agent, "uptime")->valueint, 123456789); - - assert_non_null(cJSON_GetObjectItem(agent, "metrics")); - cJSON* agent_metrics = cJSON_GetObjectItem(agent, "metrics"); - - assert_non_null(cJSON_GetObjectItem(agent_metrics, "events")); - cJSON* events = cJSON_GetObjectItem(agent_metrics, "events"); - - assert_int_equal(cJSON_GetObjectItem(events, "processed")->valueint, 1286); - - assert_non_null(cJSON_GetObjectItem(events, "received_breakdown")); - cJSON* events_received_breakdown = cJSON_GetObjectItem(events, "received_breakdown"); - - assert_non_null(cJSON_GetObjectItem(events_received_breakdown, "decoded_breakdown")); - cJSON* events_decoded_breakdown = cJSON_GetObjectItem(events_received_breakdown, "decoded_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(events_decoded_breakdown, "agent")->valueint, 1); - assert_int_equal(cJSON_GetObjectItem(events_decoded_breakdown, "dbsync")->valueint, 154); - assert_int_equal(cJSON_GetObjectItem(events_decoded_breakdown, "monitor")->valueint, 2); - assert_int_equal(cJSON_GetObjectItem(events_decoded_breakdown, "remote")->valueint, 2); - - assert_non_null(cJSON_GetObjectItem(events_decoded_breakdown, "integrations_breakdown")); - cJSON* integrations_decoded = cJSON_GetObjectItem(events_decoded_breakdown, "integrations_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(integrations_decoded, "virustotal")->valueint, 1); - - assert_non_null(cJSON_GetObjectItem(events_decoded_breakdown, "modules_breakdown")); - cJSON* modules_decoded = cJSON_GetObjectItem(events_decoded_breakdown, "modules_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "aws")->valueint, 39); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "azure")->valueint, 14); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "ciscat")->valueint, 22); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "command")->valueint, 5); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "docker")->valueint, 39); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "gcp")->valueint, 12); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "github")->valueint, 44); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "office365")->valueint, 6); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "oscap")->valueint, 0); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "osquery")->valueint, 12); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "rootcheck")->valueint, 25); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "sca")->valueint, 68); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "syscheck")->valueint, 514); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "syscollector")->valueint, 320); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "upgrade")->valueint, 10); - assert_int_equal(cJSON_GetObjectItem(modules_decoded, "vulnerability")->valueint, 14); - - assert_non_null(cJSON_GetObjectItem(modules_decoded, "logcollector_breakdown")); - cJSON* logcollector_decoded = cJSON_GetObjectItem(modules_decoded, "logcollector_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(logcollector_decoded, "eventchannel")->valueint, 37); - assert_int_equal(cJSON_GetObjectItem(logcollector_decoded, "eventlog")->valueint, 15); - assert_int_equal(cJSON_GetObjectItem(logcollector_decoded, "macos")->valueint, 36); - assert_int_equal(cJSON_GetObjectItem(logcollector_decoded, "others")->valueint, 55); - - assert_non_null(cJSON_GetObjectItem(events, "written_breakdown")); - cJSON* written = cJSON_GetObjectItem(events, "written_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(written, "alerts")->valueint, 269); - assert_int_equal(cJSON_GetObjectItem(written, "firewall")->valueint, 15); - assert_int_equal(cJSON_GetObjectItem(written, "archives")->valueint, 1286); - - os_free(test_data->agent_state); - os_free(agents_ids); -} - -void test_asys_get_node_new_node(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - const char *agent_id = "001"; - - expect_value(__wrap_OSHash_Get_ex, self, analysisd_agents_state); - expect_string(__wrap_OSHash_Get_ex, key, agent_id); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 123456789); - - expect_value(__wrap_OSHash_Add_ex, self, analysisd_agents_state); - expect_string(__wrap_OSHash_Add_ex, key, agent_id); - expect_memory(__wrap_OSHash_Add_ex, data, test_data->agent_state, sizeof(test_data->agent_state)); - will_return(__wrap_OSHash_Add_ex, 2); - - analysisd_agent_state_t *agent_state_returned = get_node(agent_id); - - assert_non_null(agent_state_returned); - - os_free(agent_state_returned); -} - -void test_asys_get_node_existing_node(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - const char *agent_id = "001"; - - expect_value(__wrap_OSHash_Get_ex, self, analysisd_agents_state); - expect_string(__wrap_OSHash_Get_ex, key, agent_id); - will_return(__wrap_OSHash_Get_ex, test_data->agent_state); - - analysisd_agent_state_t *agent_state_returned = get_node(agent_id); - - assert_non_null(agent_state_returned); - - os_free(test_data->agent_state); -} - -void test_w_analysisd_clean_agents_state_empty_table(void ** state) { - expect_value(__wrap_OSHash_Begin, self, analysisd_agents_state); - will_return(__wrap_OSHash_Begin, NULL); - - int sock = 1; - - w_analysisd_clean_agents_state(&sock); -} - -void test_w_analysisd_clean_agents_state_completed(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - expect_value(__wrap_OSHash_Begin, self, analysisd_agents_state); - will_return(__wrap_OSHash_Begin, test_data->hash_node); - - int *connected_agents = NULL; - os_calloc(1, sizeof(int), connected_agents); - connected_agents[0] = OS_INVALID; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, -1); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_OSHash_Next, self, analysisd_agents_state); - will_return(__wrap_OSHash_Next, NULL); - - expect_value(__wrap_OSHash_Delete_ex, self, analysisd_agents_state); - expect_value(__wrap_OSHash_Delete_ex, key, "001"); - will_return(__wrap_OSHash_Delete_ex, test_data->agent_state); - - int sock = 1; - - w_analysisd_clean_agents_state(&sock); -} - -void test_w_analysisd_clean_agents_state_completed_without_delete(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - expect_value(__wrap_OSHash_Begin, self, analysisd_agents_state); - will_return(__wrap_OSHash_Begin, test_data->hash_node); - - int *connected_agents = NULL; - os_calloc(1, sizeof(int), connected_agents); - connected_agents[0] = 1; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, -1); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_OSHash_Next, self, analysisd_agents_state); - will_return(__wrap_OSHash_Next, NULL); - - int sock = 1; - - w_analysisd_clean_agents_state(&sock); - - os_free(test_data->agent_state); -} - -void test_w_analysisd_clean_agents_state_query_fail(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - expect_value(__wrap_OSHash_Begin, self, analysisd_agents_state); - will_return(__wrap_OSHash_Begin, test_data->hash_node); - - int *connected_agents = NULL; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, -1); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - int sock = 1; - - w_analysisd_clean_agents_state(&sock); - - os_free(test_data->agent_state); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test asys_create_state_json - cmocka_unit_test_setup_teardown(test_asys_create_state_json, test_setup, test_teardown), - // Test asys_create_agents_state_json - cmocka_unit_test_setup_teardown(test_asys_create_agents_state_json, test_setup_agent, test_teardown_agent), - // Test get_node - cmocka_unit_test_setup_teardown(test_asys_get_node_new_node, test_setup_empty_hash_table, test_teardown_empty_hash_table), - cmocka_unit_test_setup_teardown(test_asys_get_node_existing_node, test_setup_agent, test_teardown_agent), - // Test w_analysisd_clean_agents_state - cmocka_unit_test_setup_teardown(test_w_analysisd_clean_agents_state_empty_table, test_setup_empty_hash_table, test_teardown_empty_hash_table), - cmocka_unit_test_setup_teardown(test_w_analysisd_clean_agents_state_completed, test_setup_agent, test_teardown_agent), - cmocka_unit_test_setup_teardown(test_w_analysisd_clean_agents_state_completed_without_delete, test_setup_agent, test_teardown_agent), - cmocka_unit_test_setup_teardown(test_w_analysisd_clean_agents_state_query_fail, test_setup_agent, test_teardown_agent), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_analysisd_syscheck.c b/src/unit_tests/analysisd/test_analysisd_syscheck.c deleted file mode 100644 index 5c2355f82a4..00000000000 --- a/src/unit_tests/analysisd/test_analysisd_syscheck.c +++ /dev/null @@ -1,4006 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - -#include "../headers/wazuhdb_op.h" -#include "../headers/syscheck_op.h" - -/* Auxiliar structs */ - -typedef struct __fim_data_s { - cJSON *event; - Eventinfo *lf; -} fim_data_t; - -typedef struct __fim_adjust_checksum_data_s { - sk_sum_t *newsum; - char **checksum; -} fim_adjust_checksum_data_t; - -/* private functions to be tested */ -void fim_send_db_query(int * sock, const char * query); -void fim_send_db_delete(_sdb * sdb, const char * agent_id, const char * path); -void fim_send_db_save(_sdb * sdb, const char * agent_id, cJSON * data); -void fim_process_scan_info(_sdb * sdb, const char * agent_id, fim_scan_event event, cJSON * data); -int fim_fetch_attributes_state(cJSON *attr, Eventinfo *lf, char new_state); -int fim_fetch_attributes(cJSON *new_attrs, cJSON *old_attrs, Eventinfo *lf); -size_t fim_generate_comment(char * str, long size, const char * format, const char * a1, const char * a2); -int fim_generate_alert(Eventinfo *lf, syscheck_event_t event_type, cJSON *attributes, cJSON *old_attributes, cJSON *audit); -int fim_process_alert(_sdb *sdb, Eventinfo *lf, cJSON *event); -int decode_fim_event(_sdb *sdb, Eventinfo *lf); -char *perm_json_to_old_format(cJSON *perm_json); -void fim_adjust_checksum(sk_sum_t *newsum, char **checksum); - -/* setup/teardown */ - -static int setup_fim_event_cjson(void **state) { - const char *plain_event = "{\"type\":\"event\"," - "\"data\":{" - "\"path\":\"/a/path\"," - "\"mode\":\"whodata\"," - "\"type\":\"added\"," - "\"timestamp\":123456789," - "\"changed_attributes\":[" - "\"size\",\"permission\",\"uid\"," - "\"user_name\",\"gid\",\"group_name\"," - "\"mtime\",\"inode\",\"md5\",\"sha1\",\"sha256\"]," - "\"tags\":\"tags\"," - "\"content_changes\":\"some_changes\"," - "\"old_attributes\":{" - "\"type\":\"file\"," - "\"size\":1234," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":2345," - "\"mtime\":3456," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}," - "\"audit\":{" - "\"user_id\":\"user_id\"," - "\"user_name\":\"user_name\"," - "\"group_id\":\"group_id\"," - "\"group_name\":\"group_name\"," - "\"process_name\":\"process_name\"," - "\"audit_uid\":\"audit_uid\"," - "\"audit_name\":\"audit_name\"," - "\"effective_uid\":\"effective_uid\"," - "\"effective_name\":\"effective_name\"," - "\"ppid\":12345," - "\"process_id\":23456}}}"; - - cJSON *event = cJSON_Parse(plain_event); - - if(event == NULL) - return -1; - - *state = event; - return 0; -} - -static int teardown_cjson(void **state) { - cJSON *event = *state; - - cJSON_Delete(event); - - return 0; -} - -static int setup_event_info(void **state) { - Eventinfo *lf = calloc(1, sizeof(Eventinfo)); - if(lf == NULL) - return -1; - if(lf->fields = calloc(FIM_NFIELDS, sizeof(DynamicField)), lf->fields == NULL) - return -1; - - lf->nfields = FIM_NFIELDS; - - if(lf->decoder_info = calloc(1, sizeof(OSDecoderInfo)), lf->decoder_info == NULL) - return -1; - if(lf->decoder_info->fields = calloc(FIM_NFIELDS, sizeof(char*)), lf->decoder_info->fields == NULL) - return -1; - if(lf->full_log = calloc(OS_MAXSTR, sizeof(char)), lf->full_log == NULL) - return -1; - - if(lf->decoder_info->fields[FIM_FILE] = strdup("file"), lf->decoder_info->fields[FIM_FILE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_HARD_LINKS] = strdup("hard_links"), lf->decoder_info->fields[FIM_HARD_LINKS] == NULL) - return -1; - if (lf->decoder_info->fields[FIM_MODE] = strdup("mode"), lf->decoder_info->fields[FIM_MODE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_SIZE] = strdup("size"), lf->decoder_info->fields[FIM_SIZE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_SIZE_BEFORE] = strdup("size_before"), lf->decoder_info->fields[FIM_SIZE_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_PERM] = strdup("perm"), lf->decoder_info->fields[FIM_PERM] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_PERM_BEFORE] = strdup("perm_before"), lf->decoder_info->fields[FIM_PERM_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_UID] = strdup("uid"), lf->decoder_info->fields[FIM_UID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_UID_BEFORE] = strdup("uid_before"), lf->decoder_info->fields[FIM_UID_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_GID] = strdup("gid"), lf->decoder_info->fields[FIM_GID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_GID_BEFORE] = strdup("gid_before"), lf->decoder_info->fields[FIM_GID_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_MD5] = strdup("md5"), lf->decoder_info->fields[FIM_MD5] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_MD5_BEFORE] = strdup("md5_before"), lf->decoder_info->fields[FIM_MD5_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_SHA1] = strdup("sha1"), lf->decoder_info->fields[FIM_SHA1] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_SHA1_BEFORE] = strdup("sha1_before"), lf->decoder_info->fields[FIM_SHA1_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_UNAME] = strdup("uname"), lf->decoder_info->fields[FIM_UNAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_UNAME_BEFORE] = strdup("uname_before"), lf->decoder_info->fields[FIM_UNAME_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_GNAME] = strdup("gname"), lf->decoder_info->fields[FIM_GNAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_GNAME_BEFORE] = strdup("gname_before"), lf->decoder_info->fields[FIM_GNAME_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_MTIME] = strdup("mtime"), lf->decoder_info->fields[FIM_MTIME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_MTIME_BEFORE] = strdup("mtime_before"), lf->decoder_info->fields[FIM_MTIME_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_INODE] = strdup("inode"), lf->decoder_info->fields[FIM_INODE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_INODE_BEFORE] = strdup("inode_before"), lf->decoder_info->fields[FIM_INODE_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_SHA256] = strdup("sha256"), lf->decoder_info->fields[FIM_SHA256] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_SHA256_BEFORE] = strdup("sha256_before"), lf->decoder_info->fields[FIM_SHA256_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_DIFF] = strdup("diff"), lf->decoder_info->fields[FIM_DIFF] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_ATTRS] = strdup("attrs"), lf->decoder_info->fields[FIM_ATTRS] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_ATTRS_BEFORE] = strdup("attrs_before"), lf->decoder_info->fields[FIM_ATTRS_BEFORE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_CHFIELDS] = strdup("chfields"), lf->decoder_info->fields[FIM_CHFIELDS] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_USER_ID] = strdup("user_id"), lf->decoder_info->fields[FIM_USER_ID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_USER_NAME] = strdup("user_name"), lf->decoder_info->fields[FIM_USER_NAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_GROUP_ID] = strdup("group_id"), lf->decoder_info->fields[FIM_GROUP_ID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_GROUP_NAME] = strdup("group_name"), lf->decoder_info->fields[FIM_GROUP_NAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_PROC_NAME] = strdup("proc_name"), lf->decoder_info->fields[FIM_PROC_NAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_AUDIT_ID] = strdup("audit_id"), lf->decoder_info->fields[FIM_AUDIT_ID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_AUDIT_NAME] = strdup("audit_name"), lf->decoder_info->fields[FIM_AUDIT_NAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_EFFECTIVE_UID] = strdup("effective_uid"), lf->decoder_info->fields[FIM_EFFECTIVE_UID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_EFFECTIVE_NAME] = strdup("effective_name"), lf->decoder_info->fields[FIM_EFFECTIVE_NAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_PPID] = strdup("ppid"), lf->decoder_info->fields[FIM_PPID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_PROC_ID] = strdup("proc_id"), lf->decoder_info->fields[FIM_PROC_ID] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_TAG] = strdup("tag"), lf->decoder_info->fields[FIM_TAG] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_SYM_PATH] = strdup("sym_path"), lf->decoder_info->fields[FIM_SYM_PATH] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_AUDIT_CWD] = strdup("cwd"), lf->decoder_info->fields[FIM_AUDIT_CWD] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_PROC_PNAME] = strdup("parent_name"), lf->decoder_info->fields[FIM_PROC_PNAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_AUDIT_PCWD] = strdup("parent_cwd"), lf->decoder_info->fields[FIM_AUDIT_PCWD] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_REGISTRY_ARCH] = strdup("arch"), lf->decoder_info->fields[FIM_REGISTRY_ARCH] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_REGISTRY_VALUE_NAME] = strdup("value_name"), lf->decoder_info->fields[FIM_REGISTRY_VALUE_NAME] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_REGISTRY_VALUE_TYPE] = strdup("value_type"), lf->decoder_info->fields[FIM_REGISTRY_VALUE_TYPE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_REGISTRY_HASH] = strdup("hash_full_path"), lf->decoder_info->fields[FIM_REGISTRY_HASH] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_ENTRY_TYPE] = strdup("entry_type"), lf->decoder_info->fields[FIM_ENTRY_TYPE] == NULL) - return -1; - if(lf->decoder_info->fields[FIM_EVENT_TYPE] = strdup("event_type"), lf->decoder_info->fields[FIM_EVENT_TYPE] == NULL) - return -1; - - *state = lf; - - return 0; -} - -static int setup_fim_data(void **state) { - fim_data_t *data; - const char *plain_event = "{\"type\":\"event\"," - "\"data\":{" - "\"path\":\"/a/path\"," - "\"mode\":\"whodata\"," - "\"type\":\"added\"," - "\"timestamp\":123456789," - "\"changed_attributes\":[" - "\"size\",\"permission\",\"uid\"," - "\"user_name\",\"gid\",\"group_name\"," - "\"mtime\",\"inode\",\"md5\",\"sha1\",\"sha256\"]," - "\"tags\":\"tags\"," - "\"hard_links\":[" - "\"/a/hard1.file\"," - "\"/b/hard2.file\"]," - "\"content_changes\":\"some_changes\"," - "\"old_attributes\":{" - "\"type\":\"file\"," - "\"size\":1234," - "\"perm\":\"old_perm\"," - "\"user_name\":\"old_user_name\"," - "\"group_name\":\"old_group_name\"," - "\"uid\":\"old_uid\"," - "\"gid\":\"old_gid\"," - "\"inode\":2345," - "\"mtime\":3456," - "\"hash_md5\":\"old_hash_md5\"," - "\"hash_sha1\":\"old_hash_sha1\"," - "\"hash_sha256\":\"old_hash_sha256\"," - "\"win_attributes\":\"old_win_attributes\"," - "\"symlink_path\":\"old_symlink_path\"," - "\"checksum\":\"old_checksum\"}," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}," - "\"audit\":{" - "\"user_id\":\"user_id\"," - "\"user_name\":\"user_name\"," - "\"group_id\":\"group_id\"," - "\"group_name\":\"group_name\"," - "\"process_name\":\"process_name\"," - "\"audit_uid\":\"audit_uid\"," - "\"audit_name\":\"audit_name\"," - "\"effective_uid\":\"effective_uid\"," - "\"effective_name\":\"effective_name\"," - "\"ppid\":12345," - "\"process_id\":23456," - "\"cwd\":\"cwd\"," - "\"parent_name\":\"parent_name\"," - "\"parent_cwd\":\"parent_cwd\"}}}"; - - if(data = calloc(1, sizeof(fim_data_t)), data == NULL) - return -1; - - data->event = cJSON_Parse(plain_event); - - if(data->event == NULL) - return -1; - - if (setup_event_info((void **)&data->lf) != 0) { - return -1; - } - - if (fim_init() != 1) - return -1; - - *state = data; - - return 0; -} - -static int setup_fim_data_win_perms(void **state) { - fim_data_t *data; - const char *plain_event = "{\"type\":\"event\"," - "\"data\":{" - "\"path\":\"/a/path\"," - "\"mode\":\"whodata\"," - "\"type\":\"added\"," - "\"timestamp\":123456789," - "\"changed_attributes\":[" - "\"size\",\"permission\",\"uid\"," - "\"user_name\",\"gid\",\"group_name\"," - "\"mtime\",\"inode\",\"md5\",\"sha1\",\"sha256\"]," - "\"tags\":\"tags\"," - "\"hard_links\":[" - "\"/a/hard1.file\"," - "\"/b/hard2.file\"]," - "\"content_changes\":\"some_changes\"," - "\"old_attributes\":{" - "\"type\":\"file\"," - "\"size\":1234," - "\"perm\":{\"S-1-5-32-666\":{\"name\":\"anon\",\"denied\":[\"generic_read\",\"generic_write\",\"generic_execute\",\"generic_all\"]}}," - "\"user_name\":\"old_user_name\"," - "\"group_name\":\"old_group_name\"," - "\"uid\":\"old_uid\"," - "\"gid\":\"old_gid\"," - "\"inode\":2345," - "\"mtime\":3456," - "\"hash_md5\":\"old_hash_md5\"," - "\"hash_sha1\":\"old_hash_sha1\"," - "\"hash_sha256\":\"old_hash_sha256\"," - "\"win_attributes\":\"old_win_attributes\"," - "\"symlink_path\":\"old_symlink_path\"," - "\"checksum\":\"old_checksum\"}," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":{\"S-1-5-32-636\":{\"name\":\"username\",\"allowed\":[\"generic_read\",\"generic_write\",\"generic_execute\",\"generic_all\"]}}," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}}"; - - if(data = calloc(1, sizeof(fim_data_t)), data == NULL) - return -1; - - data->event = cJSON_Parse(plain_event); - - if(data->event == NULL) - return -1; - - if (setup_event_info((void **)&data->lf) != 0) { - return -1; - } - - if (fim_init() != 1) - return -1; - - *state = data; - - return 0; -} - - -static int setup_registry_key_data(void **state) { - fim_data_t *data; - const char *plain_event = "{\"type\":\"event\"," - "\"data\":{" - "\"path\":\"HKEY_LOCAL_MACHINE\\\\software\\\\test\"," - "\"index\":\"234567890ABCDEF1234567890ABCDEF123456111\"," - "\"version\":3," - "\"arch\":\"[x64]\"," - "\"mode\":\"scheduled\"," - "\"type\":\"added\"," - "\"timestamp\":123456789," - "\"changed_attributes\":[" - "\"permission\",\"uid\"," - "\"user_name\",\"gid\",\"group_name\"," - "\"mtime\"]," - "\"tags\":\"tags\"," - "\"old_attributes\":{" - "\"type\":\"registry_key\"," - "\"perm\":\"old_perm\"," - "\"user_name\":\"old_user_name\"," - "\"group_name\":\"old_group_name\"," - "\"uid\":\"old_uid\"," - "\"gid\":\"old_gid\"," - "\"mtime\":3456," - "\"checksum\":\"old_checksum\"}," - "\"attributes\":{" - "\"type\":\"registry_key\"," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"mtime\":6789," - "\"checksum\":\"checksum\"}}}"; - - if(data = calloc(1, sizeof(fim_data_t)), data == NULL) - return -1; - - data->event = cJSON_Parse(plain_event); - - if(data->event == NULL) - return -1; - - if (setup_event_info((void **)&data->lf) != 0) { - return -1; - } - - if (fim_init() != 1) - return -1; - - *state = data; - - return 0; -} - -extern OSHash *fim_agentinfo; - -static int setup_registry_value_data(void **state) { - fim_data_t *data; - const char *plain_event = "{\"type\":\"event\"," - "\"data\":{" - "\"path\":\"HKEY_LOCAL_MACHINE\\\\software\\\\test\"," - "\"index\":\"234567890ABCDEF1234567890ABCDEF123456111\"," - "\"version\":3," - "\"arch\":\"[x64]\"," - "\"value_name\":\"some:value\"," - "\"value_type\":\"REG_SZ\"," - "\"mode\":\"scheduled\"," - "\"type\":\"added\"," - "\"timestamp\":123456789," - "\"changed_attributes\":[" - "\"size\",\"md5\",\"sha1\",\"sha256\"]," - "\"tags\":\"tags\"," - "\"old_attributes\":{" - "\"type\":\"registry_value\"," - "\"size\":1234," - "\"hash_md5\":\"old_hash_md5\"," - "\"hash_sha1\":\"old_hash_sha1\"," - "\"hash_sha256\":\"old_hash_sha256\"," - "\"checksum\":\"old_checksum\"}," - "\"attributes\":{" - "\"type\":\"registry_value\"," - "\"size\":4567," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"checksum\":\"checksum\"}}}"; - - if(data = calloc(1, sizeof(fim_data_t)), data == NULL) - return -1; - - data->event = cJSON_Parse(plain_event); - - if(data->event == NULL) - return -1; - - if (setup_event_info((void **)&data->lf) != 0) { - return -1; - } - - if (fim_init() != 1) - return -1; - - *state = data; - - return 0; -} - -static int teardown_fim_data(void **state) { - fim_data_t *data = *state; - int i; - - if (data->lf->fields[FIM_MODE].value) { - free(data->lf->fields[FIM_ENTRY_TYPE].value); - data->lf->fields[FIM_ENTRY_TYPE].value = NULL; - } - - if (data->lf->fields[FIM_ENTRY_TYPE].value) { - free(data->lf->fields[FIM_ENTRY_TYPE].value); - data->lf->fields[FIM_ENTRY_TYPE].value = NULL; - } - - for(i = 0; i < FIM_NFIELDS; i++) { - free(data->lf->decoder_info->fields[i]); - } - - free(data->lf->decoder_info->fields); - free(data->lf->decoder_info); - - cJSON_Delete(data->event); - - Free_Eventinfo(data->lf); - - free(data); - - OSHash_Free(fim_agentinfo); - - return 0; -} - -static int setup_decode_fim_event(void **state) { - Eventinfo *data; - const char *plain_event = "{\"type\":\"event\"," - "\"data\":{" - "\"path\":\"/a/path\"," - "\"mode\":\"whodata\"," - "\"type\":\"added\"," - "\"timestamp\":123456789," - "\"changed_attributes\":[" - "\"size\",\"permission\",\"uid\"," - "\"user_name\",\"gid\",\"group_name\"," - "\"mtime\",\"inode\",\"md5\",\"sha1\",\"sha256\"]," - "\"tags\":\"tags\"," - "\"hard_links\":[" - "\"/a/hard1.file\"," - "\"/b/hard2.file\"]," - "\"content_changes\":\"some_changes\"," - "\"old_attributes\":{" - "\"type\":\"file\"," - "\"size\":1234," - "\"perm\":\"old_perm\"," - "\"user_name\":\"old_user_name\"," - "\"group_name\":\"old_group_name\"," - "\"uid\":\"old_uid\"," - "\"gid\":\"old_gid\"," - "\"inode\":2345," - "\"mtime\":3456," - "\"hash_md5\":\"old_hash_md5\"," - "\"hash_sha1\":\"old_hash_sha1\"," - "\"hash_sha256\":\"old_hash_sha256\"," - "\"win_attributes\":\"old_win_attributes\"," - "\"symlink_path\":\"old_symlink_path\"," - "\"checksum\":\"old_checksum\"}," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}," - "\"audit\":{" - "\"user_id\":\"user_id\"," - "\"user_name\":\"user_name\"," - "\"group_id\":\"group_id\"," - "\"group_name\":\"group_name\"," - "\"process_name\":\"process_name\"," - "\"audit_uid\":\"audit_uid\"," - "\"audit_name\":\"audit_name\"," - "\"effective_uid\":\"effective_uid\"," - "\"effective_name\":\"effective_name\"," - "\"ppid\":12345," - "\"process_id\":23456," - "\"cwd\":\"cwd\"," - "\"parent_name\":\"parent_name\"," - "\"parent_cwd\":\"parent_cwd\"}}}"; - - if (setup_event_info((void **)&data) != 0) { - return -1; - } - - if(data->log = strdup(plain_event), data->log == NULL) - return -1; - - *state = data; - - return 0; -} - -static int teardown_decode_fim_event(void **state) { - Eventinfo *data = *state; - int i; - - if(data->log){ - free(data->log); - data->log = NULL; - } - - for(i = 0; i < FIM_NFIELDS; i++) { - free(data->decoder_info->fields[i]); - } - free(data->decoder_info->fields); - free(data->decoder_info); - - Free_Eventinfo(data); - - return 0; -} - -static int setup_fim_adjust_checksum(void **state) { - fim_adjust_checksum_data_t *data; - - if(data = calloc(1, sizeof(fim_adjust_checksum_data_t)), data == NULL) - return -1; - if(data->newsum = calloc(1, sizeof(sk_sum_t)), data->newsum == NULL) - return -1; - if(data->checksum = calloc(1, sizeof(char*)), data->checksum == NULL) - return -1; - - *state = data; - - return 0; -} - -static int teardown_fim_adjust_checksum(void **state) { - fim_adjust_checksum_data_t *data = *state; - - sk_sum_clean(data->newsum); - free(data->newsum); - - if(*data->checksum) { - free(*data->checksum); - } - if(data->checksum) { - free(data->checksum); - } - - if(data) { - free(data); - data = NULL; - } - - return 0; -} - -/* tests */ -/* fim_send_db_query */ -static void test_fim_send_db_query_success(void **state) { - const char *query = "This is a mock query, it wont go anywhere"; - const char *result = "This is a mock query result, it wont go anywhere"; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_send_db_query(&sock, query); -} - -static void test_fim_send_db_query_communication_error(void **state) { - const char *query = "This is a mock query, it wont go anywhere"; - const char *result = "This is a mock query result, it wont go anywhere"; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -2); - - expect_string(__wrap__merror, formatted_msg, "FIM decoder: Cannot communicate with database."); - - fim_send_db_query(&sock, query); -} - -static void test_fim_send_db_query_no_response(void **state) { - const char *query = "This is a mock query, it wont go anywhere"; - const char *result = "This is a mock query result, it wont go anywhere"; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - - expect_string(__wrap__merror, formatted_msg, "FIM decoder: Cannot get response from database."); - - fim_send_db_query(&sock, query); -} - -static void test_fim_send_db_query_format_error(void **state) { - const char *query = "This is a mock query, it wont go anywhere"; - const char *result = "This is a mock query result, it wont go anywhere"; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - expect_string(__wrap__merror, formatted_msg, - "FIM decoder: Bad response from database: is a mock query result, it wont go anywhere"); - - fim_send_db_query(&sock, query); -} - -/* fim_send_db_delete */ -static void test_fim_send_db_delete_success(void **state) { - _sdb sdb = {.socket=10}; - const char *agent_id = "001"; - const char *path = "/a/path"; - const char *result = "This is a mock query result, it wont go anywhere"; - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 001 syscheck delete /a/path"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_send_db_delete(&sdb, agent_id, path); -} - -static void test_fim_send_db_delete_query_too_long(void **state) { - _sdb sdb = {.socket=10}; - const char *agent_id = "001"; - char path[OS_SIZE_6144]; - - memset(path, 'a', OS_SIZE_6144); - path[OS_SIZE_6144 - 1] = '\0'; - - // This test should fail due to path being larger than the query buffer - // but it doesn't... - expect_string(__wrap__merror, formatted_msg, "FIM decoder: Cannot build delete query: input is too long."); - - fim_send_db_delete(&sdb, agent_id, path); -} - -static void test_fim_send_db_delete_null_agent_id(void **state) { - _sdb sdb = {.socket=10}; - const char *path = "/a/path"; - const char *result = "This is a mock query result, it wont go anywhere"; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent (null) syscheck delete /a/path"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_send_db_delete(&sdb, NULL, path); -} - -static void test_fim_send_db_delete_null_path(void **state) { - _sdb sdb = {.socket=10}; - const char *agent_id = "001"; - const char *result = "This is a mock query result, it wont go anywhere"; - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 001 syscheck delete (null)"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_send_db_delete(&sdb, agent_id, NULL); -} - -/* fim_send_db_save */ -static void test_fim_send_db_save_success(void **state) { - _sdb sdb = {.socket = 10}; - const char *agent_id = "007"; - const char *result = "This is a mock query result, it wont go anywhere"; - cJSON *event = *state; - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_send_db_save(&sdb, agent_id, data); -} - -static void test_fim_send_db_save_event_too_long(void **state) { - _sdb sdb = {.socket = 10}; - const char *agent_id = "007"; - char buffer[OS_MAXSTR]; - cJSON *event = *state; - - memset(buffer, 'a', OS_MAXSTR); - buffer[OS_MAXSTR - 1] = '\0'; - - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - cJSON_DeleteItemFromObject(data, "attributes"); - cJSON_AddStringToObject(data, "attributes", buffer); - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_string(__wrap__merror, formatted_msg, "FIM decoder: Cannot build save2 query: input is too long."); - - fim_send_db_save(&sdb, agent_id, data); -} - -static void test_fim_send_db_save_null_agent_id(void **state) { - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - cJSON *event = *state; - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent (null) syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_send_db_save(&sdb, NULL, data); -} - -static void test_fim_send_db_save_null_data(void **state) { - _sdb sdb = {.socket = 10}; - const char *agent_id = "007"; - const char *result = "This is a mock query result, it wont go anywhere"; - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 (null)"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_send_db_save(&sdb, agent_id, NULL); -} - -/* fim_process_scan_info */ -static void test_fim_process_scan_info_scan_start(void **state) { - _sdb sdb = {.socket = 10}; - const char *agent_id = "007"; - const char *result = "This is a mock query result, it wont go anywhere"; - cJSON *event = *state; - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck scan_info_update start_scan 123456789"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_process_scan_info(&sdb, agent_id, FIM_SCAN_START, data); -} - -static void test_fim_process_scan_info_scan_end(void **state) { - _sdb sdb = {.socket = 10}; - const char *agent_id = "007"; - const char *result = "This is a mock query result, it wont go anywhere"; - cJSON *event = *state; - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck scan_info_update end_scan 123456789"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_process_scan_info(&sdb, agent_id, FIM_SCAN_END, data); -} - -static void test_fim_process_scan_info_timestamp_not_a_number(void **state) { - _sdb sdb = {.socket = 10}; - const char *agent_id = "007"; - cJSON *event = *state; - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - cJSON_DeleteItemFromObject(data, "timestamp"); - cJSON_AddStringToObject(data, "timestamp", "not_a_number"); - - expect_string(__wrap__mdebug1, formatted_msg, "No such member \"timestamp\" in FIM scan info event."); - - fim_process_scan_info(&sdb, agent_id, FIM_SCAN_START, data); -} - -static void test_fim_process_scan_info_query_too_long(void **state) { - _sdb sdb = {.socket = 10}; - char buffer[OS_SIZE_6144]; - cJSON *event = *state; - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - memset(buffer, 'a', OS_SIZE_6144); - buffer[OS_SIZE_6144 - 1] = '\0'; - - expect_string(__wrap__merror, formatted_msg, "FIM decoder: Cannot build save query: input is too long."); - - fim_process_scan_info(&sdb, buffer, FIM_SCAN_START, data); -} - -static void test_fim_process_scan_info_null_agent_id(void **state) { - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - cJSON *event = *state; - - cJSON *data = cJSON_GetObjectItem(event, "data"); - - // Assertion of this test is done through fim_send_db_query. - // The following lines configure the test to check a correct input message. - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent (null) syscheck scan_info_update start_scan 123456789"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - fim_process_scan_info(&sdb, NULL, FIM_SCAN_START, data); -} - -static void test_fim_process_scan_info_null_data(void **state) { - _sdb sdb = {.socket = 10}; - const char *agent_id = "007"; - - expect_string(__wrap__mdebug1, formatted_msg, "No such member \"timestamp\" in FIM scan info event."); - - fim_process_scan_info(&sdb, agent_id, FIM_SCAN_START, NULL); -} - -/* fim_fetch_attributes_state */ -static void test_fim_fetch_attributes_state_new_attr(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attr = cJSON_GetObjectItem(data, "attributes"); - - ret = fim_fetch_attributes_state(attr, input->lf, 1); - - assert_int_equal(ret, 0); - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); -} - -static void test_fim_fetch_attributes_state_old_attr(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attr = cJSON_GetObjectItem(data, "attributes"); - - ret = fim_fetch_attributes_state(attr, input->lf, 0); - - assert_int_equal(ret, 0); - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "hash_sha256"); -} - -static void test_fim_fetch_attributes_state_item_with_no_key(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attr = cJSON_GetObjectItem(data, "attributes"); - - cJSON *corrupted_element = cJSON_GetObjectItem(attr, "mtime"); - free(corrupted_element->string); - corrupted_element->string = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "FIM attribute set contains an item with no key."); - - ret = fim_fetch_attributes_state(attr, input->lf, 1); - - assert_int_equal(ret, -1); -} - -static void test_fim_fetch_attributes_state_invalid_element_type(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attr = cJSON_GetObjectItem(data, "attributes"); - - cJSON_AddArrayToObject(attr, "invalid_element"); - - expect_string(__wrap__mdebug1, formatted_msg, "Unknown FIM data type."); - - ret = fim_fetch_attributes_state(attr, input->lf, 1); - - assert_int_equal(ret, 0); - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); -} - -static void test_fim_fetch_attributes_state_null_attr(void **state) { - fim_data_t *input = *state; - int ret; - - ret = fim_fetch_attributes_state(NULL, input->lf, 1); - - assert_int_equal(ret, 0); -} - -static void test_fim_fetch_attributes_state_null_lf(void **state) { - fim_data_t *input = *state; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attr = cJSON_GetObjectItem(data, "attributes"); - - expect_assert_failure(fim_fetch_attributes_state(attr, NULL, 1)); -} - -/* fim_fetch_attributes */ -static void test_fim_fetch_attributes_success(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *new_attrs = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attrs = cJSON_GetObjectItem(data, "old_attributes"); - - ret = fim_fetch_attributes(new_attrs, old_attrs, input->lf); - - assert_int_equal(ret, 0); - - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); -} - -static void test_fim_fetch_attributes_invalid_attribute(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *new_attrs = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attrs = cJSON_GetObjectItem(data, "old_attributes"); - - cJSON *corrupted_element = cJSON_GetObjectItem(new_attrs, "mtime"); - free(corrupted_element->string); - corrupted_element->string = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "FIM attribute set contains an item with no key."); - - ret = fim_fetch_attributes(new_attrs, old_attrs, input->lf); - - assert_int_equal(ret, -1); -} - -static void test_fim_fetch_attributes_null_new_attrs(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *old_attrs = cJSON_GetObjectItem(data, "old_attributes"); - - ret = fim_fetch_attributes(NULL, old_attrs, input->lf); - - assert_int_equal(ret, 0); - - /* assert new attributes */ - assert_null(input->lf->fields[FIM_SIZE].value); - assert_null(input->lf->fields[FIM_INODE].value); - assert_null(input->lf->fields[FIM_MTIME].value); - assert_null(input->lf->fields[FIM_PERM].value); - assert_null(input->lf->fields[FIM_UNAME].value); - assert_null(input->lf->fields[FIM_GNAME].value); - assert_null(input->lf->fields[FIM_UID].value); - assert_null(input->lf->fields[FIM_GID].value); - assert_null(input->lf->fields[FIM_MD5].value); - assert_null(input->lf->fields[FIM_SHA1].value); - assert_null(input->lf->fields[FIM_SHA256].value); - assert_null(input->lf->fields[FIM_SYM_PATH].value); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); -} - -static void test_fim_fetch_attributes_null_old_attrs(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *new_attrs = cJSON_GetObjectItem(data, "attributes"); - - ret = fim_fetch_attributes(new_attrs, NULL, input->lf); - - assert_int_equal(ret, 0); - - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_null(input->lf->fields[FIM_SIZE_BEFORE].value); - assert_int_equal(input->lf->fields[FIM_INODE_BEFORE].value, 0); - assert_int_equal(input->lf->fields[FIM_MTIME_BEFORE].value, 0); - assert_null(input->lf->fields[FIM_PERM_BEFORE].value); - assert_null(input->lf->fields[FIM_UNAME_BEFORE].value); - assert_null(input->lf->fields[FIM_GNAME_BEFORE].value); - assert_null(input->lf->fields[FIM_UID_BEFORE].value); - assert_null(input->lf->fields[FIM_GID_BEFORE].value); - assert_null(input->lf->fields[FIM_MD5_BEFORE].value); - assert_null(input->lf->fields[FIM_SHA1_BEFORE].value); - assert_null(input->lf->fields[FIM_SHA256_BEFORE].value); -} - -static void test_fim_fetch_attributes_null_lf(void **state) { - fim_data_t *input = *state; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *new_attrs = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attrs = cJSON_GetObjectItem(data, "old_attributes"); - - expect_assert_failure(fim_fetch_attributes(new_attrs, old_attrs, NULL)); -} - -static void test_fim_fetch_attributes_windows_perms(void **state) { - fim_data_t *input = *state; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *new_attrs = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attrs = cJSON_GetObjectItem(data, "old_attributes"); - - ret = fim_fetch_attributes(new_attrs, old_attrs, input->lf); - - assert_int_equal(ret, 0); - - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, - "username (allowed): GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, - "anon (denied): GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); -} - -/* fim_generate_comment */ -static void test_fim_generate_comment_both_parameters(void **state) { - char str[OS_MAXSTR]; - const char *format = "a1 is: %s - a2 is: %s"; - const char *a1 = "'a1'"; - const char *a2 = "'a2'"; - size_t ret; - - ret = fim_generate_comment(str, OS_MAXSTR, format, a1, a2); - - assert_int_equal(ret, 25); - assert_string_equal(str, "a1 is: 'a1' - a2 is: 'a2'"); -} - -static void test_fim_generate_comment_a1(void **state) { - char str[OS_MAXSTR]; - const char *format = "a1 is: %s - a2 is: %s"; - const char *a1 = "'a1'"; - size_t ret; - - ret = fim_generate_comment(str, OS_MAXSTR, format, a1, NULL); - - assert_int_equal(ret, 21); - assert_string_equal(str, "a1 is: 'a1' - a2 is: "); -} - -static void test_fim_generate_comment_a2(void **state) { - char str[OS_MAXSTR]; - const char *format = "a1 is: %s - a2 is: %s"; - const char *a2 = "'a2'"; - size_t ret; - - ret = fim_generate_comment(str, OS_MAXSTR, format, NULL, a2); - - assert_int_equal(ret, 21); - assert_string_equal(str, "a1 is: - a2 is: 'a2'"); -} - -static void test_fim_generate_comment_no_parameters(void **state) { - char str[OS_MAXSTR]; - const char *format = "a1 is: %s - a2 is: %s"; - size_t ret; - - str[0] = '\0'; - ret = fim_generate_comment(str, OS_MAXSTR, format, NULL, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(str, ""); -} - -static void test_fim_generate_comment_matching_parameters(void **state) { - char str[OS_MAXSTR]; - const char *format = "a1 is: %s - a2 is: %s"; - const char *a1 = "'a1'"; - const char *a2 = "'a1'"; - size_t ret; - - str[0] = '\0'; - ret = fim_generate_comment(str, OS_MAXSTR, format, a1, a2); - - assert_int_equal(ret, 0); - assert_string_equal(str, ""); -} - -static void test_fim_generate_comment_size_not_big_enough(void **state) { - char str[OS_MAXSTR]; - const char *format = "a1 is: %s - a2 is: %s"; - const char *a1 = "'a1'"; - const char *a2 = "'a2'"; - size_t ret; - - ret = fim_generate_comment(str, 10, format, a1, a2); - - assert_int_equal(ret, 25); - assert_string_equal(str, "a1 is: 'a"); -} - -static void test_fim_generate_comment_invalid_format(void **state) { - char str[OS_MAXSTR]; - const char *format = "This format is not valid, and won't use a1 or a2"; - const char *a1 = "'a1'"; - const char *a2 = "'a2'"; - size_t ret; - - ret = fim_generate_comment(str, OS_MAXSTR, format, a1, a2); - - assert_int_equal(ret, 48); - assert_string_equal(str, "This format is not valid, and won't use a1 or a2"); -} - -/* fim_generate_alert */ -static void test_fim_generate_alert_full_alert(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_MODIFIED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *audit = cJSON_GetObjectItem(data, "audit"); - cJSON *changed_attributes = cJSON_GetObjectItem(data, "changed_attributes"); - cJSON *array_it; - - os_strdup(SYSCHECK_EVENT_STRINGS[FIM_MODIFIED], input->lf->fields[FIM_EVENT_TYPE].value); - - if(input->lf->fields[FIM_FILE].value = strdup("/a/file"), input->lf->fields[FIM_FILE].value == NULL) - fail(); - - if (input->lf->fields[FIM_MODE].value = strdup("fim_mode"), input->lf->fields[FIM_MODE].value == NULL) - fail(); - - if(input->lf->fields[FIM_ENTRY_TYPE].value = strdup("file"), input->lf->fields[FIM_ENTRY_TYPE].value == NULL) - fail(); - - if(input->lf->fields[FIM_HARD_LINKS].value = strdup("[\"/a/hard1.file\",\"/b/hard2.file\"]"), - input->lf->fields[FIM_HARD_LINKS].value == NULL) { - - fail(); - } - - cJSON_ArrayForEach(array_it, changed_attributes) { - wm_strcat(&input->lf->fields[FIM_CHFIELDS].value, cJSON_GetStringValue(array_it), ','); - } - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, audit); - - assert_int_equal(ret, 0); - - // Assert fim_fetch_attributes - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - /* Assert actual output */ - assert_string_equal(input->lf->full_log, - "File '/a/file' modified\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: fim_mode\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n" - "Size changed from '1234' to '4567'\n" - "Permissions changed from 'old_perm' to 'perm'\n" - "Ownership was 'old_uid', now it is 'uid'\n" - "User name was 'old_user_name', now it is 'user_name'\n" - "Group ownership was 'old_gid', now it is 'gid'\n" - "Group name was 'old_group_name', now it is 'group_name'\n" - "Old modification time was: '3456', now it is '6789'\n" - "Old inode was: '2345', now it is '5678'\n" - "Old md5sum was: 'old_hash_md5'\n" - "New md5sum is : 'hash_md5'\n" - "Old sha1sum was: 'old_hash_sha1'\n" - "New sha1sum is : 'hash_sha1'\n" - "Old sha256sum was: 'old_hash_sha256'\n" - "New sha256sum is : 'hash_sha256'\n"); -} - -static void test_fim_generate_alert_registry_key_alert(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_MODIFIED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *changed_attributes = cJSON_GetObjectItem(data, "changed_attributes"); - cJSON *array_it; - - os_strdup(SYSCHECK_EVENT_STRINGS[FIM_MODIFIED], input->lf->fields[FIM_EVENT_TYPE].value); - - input->lf->fields[FIM_FILE].value = strdup("HKEY_LOCAL_MACHINE\\software\\test"); - if (input->lf->fields[FIM_FILE].value == NULL) - fail(); - - input->lf->fields[FIM_REGISTRY_ARCH].value = strdup("[x64]"); - if (input->lf->fields[FIM_REGISTRY_ARCH].value == NULL) - fail(); - - input->lf->fields[FIM_MODE].value = strdup("scheduled"); - if (input->lf->fields[FIM_MODE].value == NULL) - fail(); - - if(input->lf->fields[FIM_ENTRY_TYPE].value = strdup("registry_key"), input->lf->fields[FIM_ENTRY_TYPE].value == NULL) - fail(); - - cJSON_ArrayForEach(array_it, changed_attributes) { - wm_strcat(&input->lf->fields[FIM_CHFIELDS].value, cJSON_GetStringValue(array_it), ','); - } - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, NULL); - - assert_int_equal(ret, 0); - - // Assert fim_fetch_attributes - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - - /* Assert actual output */ - assert_string_equal(input->lf->full_log, - "Registry Key '[x64] HKEY_LOCAL_MACHINE\\software\\test' modified\n" - "Mode: scheduled\n" - "Changed attributes: permission,uid,user_name,gid,group_name,mtime\n" - "Permissions changed from 'old_perm' to 'perm'\n" - "Ownership was 'old_uid', now it is 'uid'\n" - "User name was 'old_user_name', now it is 'user_name'\n" - "Group ownership was 'old_gid', now it is 'gid'\n" - "Group name was 'old_group_name', now it is 'group_name'\n" - "Old modification time was: '3456', now it is '6789'\n"); -} - -static void test_fim_generate_alert_registry_value_alert(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_MODIFIED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *changed_attributes = cJSON_GetObjectItem(data, "changed_attributes"); - cJSON *array_it; - - os_strdup(SYSCHECK_EVENT_STRINGS[FIM_MODIFIED], input->lf->fields[FIM_EVENT_TYPE].value); - - if(input->lf->fields[FIM_FILE].value = strdup("HKEY_LOCAL_MACHINE\\software\\test"), input->lf->fields[FIM_FILE].value == NULL) - fail(); - - input->lf->fields[FIM_REGISTRY_ARCH].value = strdup("[x64]"); - if (input->lf->fields[FIM_REGISTRY_ARCH].value == NULL) - fail(); - - input->lf->fields[FIM_REGISTRY_VALUE_NAME].value = strdup("some:value"); - if (input->lf->fields[FIM_REGISTRY_VALUE_NAME].value == NULL) - fail(); - - input->lf->fields[FIM_REGISTRY_VALUE_TYPE].value = strdup("REG_SZ"); - if (input->lf->fields[FIM_REGISTRY_VALUE_TYPE].value == NULL) - fail(); - - input->lf->fields[FIM_REGISTRY_HASH].value = strdup("234567890ABCDEF1234567890ABCDEF123456111"); - if (input->lf->fields[FIM_REGISTRY_HASH].value == NULL) - fail(); - - input->lf->fields[FIM_MODE].value = strdup("scheduled"); - if (input->lf->fields[FIM_MODE].value == NULL) - fail(); - - if(input->lf->fields[FIM_ENTRY_TYPE].value = strdup("registry_value"), input->lf->fields[FIM_ENTRY_TYPE].value == NULL) - fail(); - - cJSON_ArrayForEach(array_it, changed_attributes) { - wm_strcat(&input->lf->fields[FIM_CHFIELDS].value, cJSON_GetStringValue(array_it), ','); - } - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, NULL); - - assert_int_equal(ret, 0); - - // Assert fim_fetch_attributes - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert actual output */ - assert_string_equal(input->lf->full_log, - "Registry Value '[x64] HKEY_LOCAL_MACHINE\\software\\test\\some:value' modified\n" - "Mode: scheduled\n" - "Changed attributes: size,md5,sha1,sha256\n" - "Size changed from '1234' to '4567'\n" - "Old md5sum was: 'old_hash_md5'\n" - "New md5sum is : 'hash_md5'\n" - "Old sha1sum was: 'old_hash_sha1'\n" - "New sha1sum is : 'hash_sha1'\n" - "Old sha256sum was: 'old_hash_sha256'\n" - "New sha256sum is : 'hash_sha256'\n"); -} - -static void test_fim_generate_alert_type_not_modified(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_ADDED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *audit = cJSON_GetObjectItem(data, "audit"); - cJSON *changed_attributes = cJSON_GetObjectItem(data, "changed_attributes"); - cJSON *array_it; - - os_strdup(SYSCHECK_EVENT_STRINGS[FIM_ADDED], input->lf->fields[FIM_EVENT_TYPE].value); - - if(input->lf->fields[FIM_FILE].value = strdup("/a/file"), input->lf->fields[FIM_FILE].value == NULL) - fail(); - - if (input->lf->fields[FIM_MODE].value = strdup("fim_mode"), input->lf->fields[FIM_MODE].value == NULL) - fail(); - - if(input->lf->fields[FIM_ENTRY_TYPE].value = strdup("file"), input->lf->fields[FIM_ENTRY_TYPE].value == NULL) - fail(); - - cJSON_ArrayForEach(array_it, changed_attributes) { - wm_strcat(&input->lf->fields[FIM_CHFIELDS].value, cJSON_GetStringValue(array_it), ','); - } - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, audit); - - assert_int_equal(ret, 0); - - // Assert fim_fetch_attributes - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - /* Assert actual output */ - assert_string_equal(input->lf->full_log, - "File '/a/file' added\n" - "Mode: fim_mode\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); -} - -static void test_fim_generate_alert_invalid_element_in_attributes(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_ADDED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *audit = cJSON_GetObjectItem(data, "audit"); - - cJSON *corrupted_element = cJSON_GetObjectItem(attributes, "mtime"); - free(corrupted_element->string); - corrupted_element->string = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "FIM attribute set contains an item with no key."); - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, audit); - - assert_int_equal(ret, -1); -} - -static void test_fim_generate_alert_invalid_element_in_audit(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_ADDED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *audit = cJSON_GetObjectItem(data, "audit"); - - cJSON *corrupted_element = cJSON_GetObjectItem(audit, "ppid"); - free(corrupted_element->string); - corrupted_element->string = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "FIM audit set contains an item with no key."); - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, audit); - - assert_int_equal(ret, -1); -} - -static void test_fim_generate_alert_null_mode(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_ADDED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *audit = cJSON_GetObjectItem(data, "audit"); - cJSON *changed_attributes = cJSON_GetObjectItem(data, "changed_attributes"); - cJSON *array_it; - - os_strdup(SYSCHECK_EVENT_STRINGS[FIM_ADDED], input->lf->fields[FIM_EVENT_TYPE].value); - - if(input->lf->fields[FIM_FILE].value = strdup("/a/file"), input->lf->fields[FIM_FILE].value == NULL) - fail(); - - if(input->lf->fields[FIM_ENTRY_TYPE].value = strdup("file"), input->lf->fields[FIM_ENTRY_TYPE].value == NULL) - fail(); - - cJSON_ArrayForEach(array_it, changed_attributes) { - wm_strcat(&input->lf->fields[FIM_CHFIELDS].value, cJSON_GetStringValue(array_it), ','); - } - - input->lf->fields[FIM_MODE].value = NULL; - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, audit); - - assert_int_equal(ret, 0); - - // Assert fim_fetch_attributes - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - /* Assert actual output */ - assert_string_equal(input->lf->full_log, - "File '/a/file' added\n" - "Mode: (null)\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); -} - -static void test_fim_generate_alert_null_audit(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_MODIFIED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *changed_attributes = cJSON_GetObjectItem(data, "changed_attributes"); - cJSON *array_it; - - os_strdup(SYSCHECK_EVENT_STRINGS[FIM_MODIFIED], input->lf->fields[FIM_EVENT_TYPE].value); - - if(input->lf->fields[FIM_FILE].value = strdup("/a/file"), input->lf->fields[FIM_FILE].value == NULL) - fail(); - - if (input->lf->fields[FIM_MODE].value = strdup("fim_mode"), input->lf->fields[FIM_MODE].value == NULL) - fail(); - - if(input->lf->fields[FIM_ENTRY_TYPE].value = strdup("file"), input->lf->fields[FIM_ENTRY_TYPE].value == NULL) - fail(); - - cJSON_ArrayForEach(array_it, changed_attributes) { - wm_strcat(&input->lf->fields[FIM_CHFIELDS].value, cJSON_GetStringValue(array_it), ','); - } - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, NULL); - - assert_int_equal(ret, 0); - - // Assert fim_fetch_attributes - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_null(input->lf->fields[FIM_PPID].value); - assert_null(input->lf->fields[FIM_PROC_ID].value); - assert_null(input->lf->fields[FIM_USER_ID].value); - assert_null(input->lf->fields[FIM_USER_NAME].value); - assert_null(input->lf->fields[FIM_GROUP_ID].value); - assert_null(input->lf->fields[FIM_GROUP_NAME].value); - assert_null(input->lf->fields[FIM_PROC_NAME].value); - assert_null(input->lf->fields[FIM_AUDIT_ID].value); - assert_null(input->lf->fields[FIM_AUDIT_NAME].value); - assert_null(input->lf->fields[FIM_EFFECTIVE_UID].value); - assert_null(input->lf->fields[FIM_EFFECTIVE_NAME].value); - - /* Assert actual output */ - assert_string_equal(input->lf->full_log, - "File '/a/file' modified\n" - "Mode: fim_mode\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n" - "Size changed from '1234' to '4567'\n" - "Permissions changed from 'old_perm' to 'perm'\n" - "Ownership was 'old_uid', now it is 'uid'\n" - "User name was 'old_user_name', now it is 'user_name'\n" - "Group ownership was 'old_gid', now it is 'gid'\n" - "Group name was 'old_group_name', now it is 'group_name'\n" - "Old modification time was: '3456', now it is '6789'\n" - "Old inode was: '2345', now it is '5678'\n" - "Old md5sum was: 'old_hash_md5'\n" - "New md5sum is : 'hash_md5'\n" - "Old sha1sum was: 'old_hash_sha1'\n" - "New sha1sum is : 'hash_sha1'\n" - "Old sha256sum was: 'old_hash_sha256'\n" - "New sha256sum is : 'hash_sha256'\n"); -} - -/* fim_process_alert */ -static void test_fim_process_alert_added_success(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' added\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(input->lf->decoder_info->name, FIM_NEW); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_modified_success(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - cJSON_DeleteItemFromObject(data, "type"); - cJSON_AddStringToObject(data, "type", "modified"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - /* Assert fim_generate_alert */ - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' modified\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n" - "Size changed from '1234' to '4567'\n" - "Permissions changed from 'old_perm' to 'perm'\n" - "Ownership was 'old_uid', now it is 'uid'\n" - "User name was 'old_user_name', now it is 'user_name'\n" - "Group ownership was 'old_gid', now it is 'gid'\n" - "Group name was 'old_group_name', now it is 'group_name'\n" - "Old modification time was: '3456', now it is '6789'\n" - "Old inode was: '2345', now it is '5678'\n" - "Old md5sum was: 'old_hash_md5'\n" - "New md5sum is : 'hash_md5'\n" - "Old sha1sum was: 'old_hash_sha1'\n" - "New sha1sum is : 'hash_sha1'\n" - "Old sha256sum was: 'old_hash_sha256'\n" - "New sha256sum is : 'hash_sha256'\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_MODIFIED]); - assert_string_equal(input->lf->decoder_info->name, FIM_MOD); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_deleted_success(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - cJSON_DeleteItemFromObject(data, "type"); - cJSON_AddStringToObject(data, "type", "deleted"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_delete */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck delete /a/path"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' deleted\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_DELETED]); - assert_string_equal(input->lf->decoder_info->name, FIM_DEL); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_no_event_type(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - cJSON_DeleteItemFromObject(data, "type"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_delete */ - expect_string(__wrap__mdebug1, formatted_msg, "No member 'type' in Syscheck JSON payload"); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, -1); -} - -static void test_fim_process_alert_invalid_entry_type(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - - cJSON_ReplaceItemInObject(attributes, "type", cJSON_CreateString("invalid")); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_delete */ - expect_string(__wrap__mdebug1, formatted_msg, "Invalid member 'type' in Syscheck attributes JSON payload"); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, -1); -} - -static void test_fim_process_alert_invalid_event_type(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - cJSON_DeleteItemFromObject(data, "type"); - cJSON_AddStringToObject(data, "type", "invalid"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_delete */ - expect_string(__wrap__mdebug1, formatted_msg, "Invalid 'type' value 'invalid' in JSON payload."); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, -1); -} - -static void test_fim_process_alert_invalid_object(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - cJSON *corrupted_object = cJSON_GetObjectItem(data, "type"); - free(corrupted_object->string); - corrupted_object->string = NULL; - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_delete */ - expect_string(__wrap__mdebug1, formatted_msg, "FIM event contains an item with no key."); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, -1); -} - -static void test_fim_process_alert_no_path(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "path"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - expect_string(__wrap__mdebug1, formatted_msg, "No member 'path' in Syscheck JSON payload"); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, -1); -} - -static void test_fim_process_alert_no_hard_links(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "hard_links"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' added\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(input->lf->decoder_info->name, FIM_NEW); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_no_mode(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "mode"); - - input->lf->fields[FIM_MODE].value = NULL; - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' added\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: (null)\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(input->lf->decoder_info->name, FIM_NEW); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_no_tags(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "tags"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' added\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(input->lf->decoder_info->name, FIM_NEW); - assert_int_equal(input->lf->decoder_info->id, 0); - assert_null(input->lf->fields[FIM_TAG].value); -} - -static void test_fim_process_alert_no_content_changes(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "content_changes"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' added\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(input->lf->decoder_info->name, FIM_NEW); - assert_int_equal(input->lf->decoder_info->id, 0); - assert_null(input->lf->fields[FIM_DIFF].value); -} - -static void test_fim_process_alert_no_changed_attributes(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "changed_attributes"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' added\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(input->lf->decoder_info->name, FIM_NEW); - assert_int_equal(input->lf->decoder_info->id, 0); - assert_null(input->lf->fields[FIM_CHFIELDS].value); -} - -static void test_fim_process_alert_no_attributes(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "attributes"); - cJSON_DeleteItemFromObject(data, "type"); - cJSON_AddStringToObject(data, "type", "modified"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - expect_string(__wrap__mdebug1, formatted_msg, "No member 'type' in Syscheck attributes JSON payload"); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, -1); -} - -static void test_fim_process_alert_no_old_attributes(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "old_attributes"); - cJSON_DeleteItemFromObject(data, "type"); - cJSON_AddStringToObject(data, "type", "modified"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_null(input->lf->fields[FIM_SIZE_BEFORE].value); - assert_int_equal(input->lf->fields[FIM_INODE_BEFORE].value, 0); - assert_int_equal(input->lf->fields[FIM_MTIME_BEFORE].value, 0); - assert_null(input->lf->fields[FIM_PERM_BEFORE].value); - assert_null(input->lf->fields[FIM_UNAME_BEFORE].value); - assert_null(input->lf->fields[FIM_GNAME_BEFORE].value); - assert_null(input->lf->fields[FIM_UID_BEFORE].value); - assert_null(input->lf->fields[FIM_GID_BEFORE].value); - assert_null(input->lf->fields[FIM_MD5_BEFORE].value); - assert_null(input->lf->fields[FIM_SHA1_BEFORE].value); - assert_null(input->lf->fields[FIM_SHA256_BEFORE].value); - - /* Assert values gotten from audit */ - assert_string_equal(input->lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(input->lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(input->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(input->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(input->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(input->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(input->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(input->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(input->lf->full_log, - "File '/a/path' modified\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n" - "Size changed from '' to '4567'\n" - "Permissions changed from '' to 'perm'\n" - "Ownership was '', now it is 'uid'\n" - "User name was '', now it is 'user_name'\n" - "Group ownership was '', now it is 'gid'\n" - "Group name was '', now it is 'group_name'\n" - "Old modification time was: '', now it is '6789'\n" - "Old inode was: '', now it is '5678'\n" - "Old md5sum was: ''\n" - "New md5sum is : 'hash_md5'\n" - "Old sha1sum was: ''\n" - "New sha1sum is : 'hash_sha1'\n" - "Old sha256sum was: ''\n" - "New sha256sum is : 'hash_sha256'\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_MODIFIED]); - assert_string_equal(input->lf->decoder_info->name, FIM_MOD); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_no_audit(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "audit"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(input->lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(input->lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(input->lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_null(input->lf->fields[FIM_PPID].value); - assert_null(input->lf->fields[FIM_PROC_ID].value); - assert_null(input->lf->fields[FIM_USER_ID].value); - assert_null(input->lf->fields[FIM_USER_NAME].value); - assert_null(input->lf->fields[FIM_GROUP_ID].value); - assert_null(input->lf->fields[FIM_GROUP_NAME].value); - assert_null(input->lf->fields[FIM_PROC_NAME].value); - assert_null(input->lf->fields[FIM_AUDIT_ID].value); - assert_null(input->lf->fields[FIM_AUDIT_NAME].value); - assert_null(input->lf->fields[FIM_EFFECTIVE_UID].value); - assert_null(input->lf->fields[FIM_EFFECTIVE_NAME].value); - - assert_string_equal(input->lf->full_log, - "File '/a/path' added\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(input->lf->decoder_info->name, FIM_NEW); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_remove_registry_key(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - cJSON_DeleteItemFromObject(data, "type"); - cJSON_AddStringToObject(data, "type", "deleted"); - cJSON_DeleteItemFromObject(data, "changed_attributes"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck delete 234567890ABCDEF1234567890ABCDEF123456111"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - assert_string_equal(input->lf->fields[FIM_REGISTRY_ARCH].value, "[x64]"); - assert_string_equal(input->lf->fields[FIM_FILE].value, "HKEY_LOCAL_MACHINE\\software\\test"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(input->lf->fields[FIM_REGISTRY_HASH].value, "234567890ABCDEF1234567890ABCDEF123456111"); - - assert_null(input->lf->fields[FIM_MD5].value); - assert_null(input->lf->fields[FIM_SHA1].value); - assert_null(input->lf->fields[FIM_SHA256].value); - assert_null(input->lf->fields[FIM_REGISTRY_VALUE_NAME].value); - assert_null(input->lf->fields[FIM_SIZE].value); - - assert_string_equal(input->lf->full_log, - "Registry Key '[x64] HKEY_LOCAL_MACHINE\\software\\test' deleted\nMode: scheduled\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_DELETED]); - assert_string_equal(input->lf->decoder_info->name, FIM_REG_KEY_DEL); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_remove_registry_value(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - - cJSON_DeleteItemFromObject(data, "type"); - cJSON_AddStringToObject(data, "type", "deleted"); - cJSON_DeleteItemFromObject(data, "changed_attributes"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck delete 234567890ABCDEF1234567890ABCDEF123456111"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, 0); - - // Assert fim_generate_alert - assert_string_equal(input->lf->fields[FIM_REGISTRY_ARCH].value, "[x64]"); - assert_string_equal(input->lf->fields[FIM_FILE].value, "HKEY_LOCAL_MACHINE\\software\\test"); - assert_string_equal(input->lf->fields[FIM_REGISTRY_VALUE_NAME].value, "some:value"); - assert_string_equal(input->lf->fields[FIM_REGISTRY_HASH].value, "234567890ABCDEF1234567890ABCDEF123456111"); - assert_string_equal(input->lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(input->lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(input->lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(input->lf->fields[FIM_SHA256].value, "hash_sha256"); - - assert_string_equal(input->lf->full_log, - "Registry Value '[x64] HKEY_LOCAL_MACHINE\\software\\test\\some:value' deleted\nMode: scheduled\n"); - - /* Assert actual output */ - assert_string_equal(input->lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_DELETED]); - assert_string_equal(input->lf->decoder_info->name, FIM_REG_VAL_DEL); - assert_int_equal(input->lf->decoder_info->id, 0); -} - -static void test_fim_process_alert_no_hash(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON_DeleteItemFromObject(data, "index"); - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - expect_string(__wrap__mdebug1, formatted_msg, "No member 'index' in Syscheck JSON payload"); - - ret = fim_process_alert(&sdb, input->lf, data); - - assert_int_equal(ret, -1); -} - -static void test_fim_process_alert_legacy_agents(void **state) { - fim_data_t *input = *state; - int ret; - syscheck_event_t event_type = FIM_MODIFIED; - - cJSON *data = cJSON_GetObjectItem(input->event, "data"); - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - cJSON *old_attributes = cJSON_GetObjectItem(data, "old_attributes"); - cJSON *changed_attributes = cJSON_GetObjectItem(data, "changed_attributes"); - cJSON *array_it; - - // Deleting index and version field - cJSON_DeleteItemFromObject(data, "index"); - cJSON_DeleteItemFromObject(data, "version"); - - os_strdup(SYSCHECK_EVENT_STRINGS[FIM_MODIFIED], input->lf->fields[FIM_EVENT_TYPE].value); - - input->lf->fields[FIM_FILE].value = strdup("HKEY_LOCAL_MACHINE\\software\\test"); - if (input->lf->fields[FIM_FILE].value == NULL) - fail(); - - input->lf->fields[FIM_REGISTRY_ARCH].value = strdup("[x64]"); - if (input->lf->fields[FIM_REGISTRY_ARCH].value == NULL) - fail(); - - input->lf->fields[FIM_MODE].value = strdup("scheduled"); - if (input->lf->fields[FIM_MODE].value == NULL) - fail(); - - if(input->lf->fields[FIM_ENTRY_TYPE].value = strdup("registry_key"), input->lf->fields[FIM_ENTRY_TYPE].value == NULL) - fail(); - - cJSON_ArrayForEach(array_it, changed_attributes) { - wm_strcat(&input->lf->fields[FIM_CHFIELDS].value, cJSON_GetStringValue(array_it), ','); - } - - ret = fim_generate_alert(input->lf, event_type, attributes, old_attributes, NULL); - - assert_int_equal(ret, 0); - - // Assert fim_fetch_attributes - /* assert new attributes */ - assert_string_equal(input->lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(input->lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(input->lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(input->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(input->lf->fields[FIM_GID].value, "gid"); - - /* assert old attributes */ - assert_string_equal(input->lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(input->lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(input->lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(input->lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(input->lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(input->lf->fields[FIM_GID_BEFORE].value, "old_gid"); - - /* Assert actual output */ - assert_string_equal(input->lf->full_log, - "Registry Key '[x64] HKEY_LOCAL_MACHINE\\software\\test' modified\n" - "Mode: scheduled\n" - "Changed attributes: permission,uid,user_name,gid,group_name,mtime\n" - "Permissions changed from 'old_perm' to 'perm'\n" - "Ownership was 'old_uid', now it is 'uid'\n" - "User name was 'old_user_name', now it is 'user_name'\n" - "Group ownership was 'old_gid', now it is 'gid'\n" - "Group name was 'old_group_name', now it is 'group_name'\n" - "Old modification time was: '3456', now it is '6789'\n"); -} - -static void test_fim_process_alert_null_event(void **state) { - fim_data_t *input = *state; - _sdb sdb = {.socket = 10}; - int ret; - - if(input->lf->agent_id = strdup("007"), input->lf->agent_id == NULL) - fail(); - - /* Inside fim_send_db_save */ - expect_string(__wrap__mdebug1, formatted_msg, "No member 'type' in Syscheck attributes JSON payload"); - - ret = fim_process_alert(&sdb, input->lf, NULL); - - assert_int_equal(ret, -1); -} - -/* decode_fim_event */ -static void test_decode_fim_event_type_event(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - /* Inside fim_process_alert */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck save2 " - "{\"path\":\"/a/path\"," - "\"timestamp\":123456789," - "\"attributes\":{" - "\"type\":\"file\"," - "\"size\":4567," - "\"perm\":\"perm\"," - "\"user_name\":\"user_name\"," - "\"group_name\":\"group_name\"," - "\"uid\":\"uid\"," - "\"gid\":\"gid\"," - "\"inode\":5678," - "\"mtime\":6789," - "\"hash_md5\":\"hash_md5\"," - "\"hash_sha1\":\"hash_sha1\"," - "\"hash_sha256\":\"hash_sha256\"," - "\"win_attributes\":\"win_attributes\"," - "\"symlink_path\":\"symlink_path\"," - "\"checksum\":\"checksum\"}}"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 1); - - // Assert fim_process_alert - /* assert new attributes */ - assert_string_equal(lf->fields[FIM_SIZE].value, "4567"); - assert_string_equal(lf->fields[FIM_INODE].value, "5678"); - assert_string_equal(lf->fields[FIM_MTIME].value, "6789"); - assert_string_equal(lf->fields[FIM_PERM].value, "perm"); - assert_string_equal(lf->fields[FIM_UNAME].value, "user_name"); - assert_string_equal(lf->fields[FIM_GNAME].value, "group_name"); - assert_string_equal(lf->fields[FIM_UID].value, "uid"); - assert_string_equal(lf->fields[FIM_GID].value, "gid"); - assert_string_equal(lf->fields[FIM_MD5].value, "hash_md5"); - assert_string_equal(lf->fields[FIM_SHA1].value, "hash_sha1"); - assert_string_equal(lf->fields[FIM_SHA256].value, "hash_sha256"); - assert_string_equal(lf->fields[FIM_SYM_PATH].value, "symlink_path"); - - /* assert old attributes */ - assert_string_equal(lf->fields[FIM_SIZE_BEFORE].value, "1234"); - assert_string_equal(lf->fields[FIM_INODE_BEFORE].value, "2345"); - assert_string_equal(lf->fields[FIM_MTIME_BEFORE].value, "3456"); - assert_string_equal(lf->fields[FIM_PERM_BEFORE].value, "old_perm"); - assert_string_equal(lf->fields[FIM_UNAME_BEFORE].value, "old_user_name"); - assert_string_equal(lf->fields[FIM_GNAME_BEFORE].value, "old_group_name"); - assert_string_equal(lf->fields[FIM_UID_BEFORE].value, "old_uid"); - assert_string_equal(lf->fields[FIM_GID_BEFORE].value, "old_gid"); - assert_string_equal(lf->fields[FIM_MD5_BEFORE].value, "old_hash_md5"); - assert_string_equal(lf->fields[FIM_SHA1_BEFORE].value, "old_hash_sha1"); - assert_string_equal(lf->fields[FIM_SHA256_BEFORE].value, "old_hash_sha256"); - - /* Assert values gotten from audit */ - assert_string_equal(lf->fields[FIM_PPID].value, "12345"); - assert_string_equal(lf->fields[FIM_PROC_ID].value, "23456"); - assert_string_equal(lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - - assert_string_equal(lf->full_log, - "File '/a/path' added\n" - "Hard links: /a/hard1.file,/b/hard2.file\n" - "Mode: whodata\n" - "Changed attributes: size,permission,uid,user_name,gid,group_name,mtime,inode,md5,sha1,sha256\n"); - - assert_string_equal(lf->fields[FIM_EVENT_TYPE].value, SYSCHECK_EVENT_STRINGS[FIM_ADDED]); - assert_string_equal(lf->decoder_info->name, FIM_NEW); - assert_int_equal(lf->decoder_info->id, 0); - -} - -static void test_decode_fim_event_type_scan_start(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *event = cJSON_Parse(lf->log); - cJSON_DeleteItemFromObject(event, "type"); - cJSON_AddStringToObject(event, "type", "scan_start"); - - free(lf->log); - lf->log = cJSON_PrintUnformatted(event); - - cJSON_Delete(event); - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - /* inside fim_process_scan_info */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck scan_info_update start_scan 123456789"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 0); -} - -static void test_decode_fim_event_type_scan_end(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - const char *result = "This is a mock query result, it wont go anywhere"; - int ret; - - cJSON *event = cJSON_Parse(lf->log); - cJSON_DeleteItemFromObject(event, "type"); - cJSON_AddStringToObject(event, "type", "scan_end"); - - free(lf->log); - lf->log = cJSON_PrintUnformatted(event); - - cJSON_Delete(event); - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - /* inside fim_process_scan_info */ - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, "agent 007 syscheck scan_info_update end_scan 123456789"); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 0); -} - -static void test_decode_fim_event_type_invalid(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *event = cJSON_Parse(lf->log); - cJSON_DeleteItemFromObject(event, "type"); - cJSON_AddStringToObject(event, "type", "invalid"); - - free(lf->log); - lf->log = cJSON_PrintUnformatted(event); - - cJSON_Delete(event); - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 0); -} - -static void test_decode_fim_event_null_item(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *event = cJSON_Parse(lf->log); - cJSON_DeleteItemFromObject(event, "data"); - cJSON *data = cJSON_CreateObject(); - cJSON_AddStringToObject(data, "test", "test"); - cJSON_AddItemToObject(event, "data", data); - - free(lf->log); - lf->log = cJSON_PrintUnformatted(event); - - cJSON_Delete(event); - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - expect_string(__wrap__mdebug1, formatted_msg, "No member 'type' in Syscheck attributes JSON payload"); - expect_string(__wrap__merror, formatted_msg, "Can't generate fim alert for event: '" - "{\"type\":\"event\"," - "\"data\":{" - "\"test\":\"test\"}}'"); - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 0); -} - -static void test_decode_fim_event_no_data(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *event = cJSON_Parse(lf->log); - cJSON_DeleteItemFromObject(event, "data"); - - free(lf->log); - lf->log = cJSON_PrintUnformatted(event); - - cJSON_Delete(event); - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - /* inside fim_process_scan_info */ - expect_string(__wrap__merror, formatted_msg, "Invalid FIM event"); - - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 0); -} - -static void test_decode_fim_event_no_type(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - int ret; - - cJSON *event = cJSON_Parse(lf->log); - cJSON_DeleteItemFromObject(event, "type"); - - free(lf->log); - lf->log = cJSON_PrintUnformatted(event); - - cJSON_Delete(event); - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - /* inside fim_process_scan_info */ - expect_string(__wrap__merror, formatted_msg, "Invalid FIM event"); - - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 0); -} - -static void test_decode_fim_event_invalid_json(void **state) { - Eventinfo *lf = *state; - _sdb sdb = {.socket = 10}; - int ret; - - free(lf->log); - lf->log = NULL; - - if(lf->agent_id = strdup("007"), lf->agent_id == NULL) - fail(); - - /* inside fim_process_scan_info */ - expect_string(__wrap__merror, formatted_msg, "Malformed FIM JSON event"); - - ret = decode_fim_event(&sdb, lf); - - assert_int_equal(ret, 0); -} - -static void test_decode_fim_event_null_sdb(void **state) { - Eventinfo *lf = *state; - - expect_assert_failure(decode_fim_event(NULL, lf)); -} - -static void test_decode_fim_event_null_eventinfo(void **state) { - _sdb sdb = {.socket = 10}; - - expect_assert_failure(decode_fim_event(&sdb, NULL)); -} - -/* perm_json_to_old_format */ -void fill_ace_array(cJSON * ace) { - int i; - const char *it; - cJSON *element; - static const char * const perm_strings[] = { - "generic_read", - "generic_write", - "generic_execute", - "generic_all", - "delete", - "read_control", - "write_dac", - "write_owner", - "synchronize", - "read_data", - "write_data", - "append_data", - "read_ea", - "write_ea", - "execute", - "read_attributes", - "write_attributes", - NULL - }; - - for (i = 0, it = perm_strings[0]; it; it = perm_strings[++i]) { - cJSON_AddItemToArray(ace, cJSON_CreateString(it)); - } -} - -static void test_perm_json_to_old_format_null_acl(void **state) { - expect_assert_failure(perm_json_to_old_format(NULL)); -} - -static void test_perm_json_to_old_format_allowed_ace_only(void **state) { - cJSON *acl = cJSON_CreateObject(); - cJSON *ace = cJSON_CreateObject(); - cJSON *allowed = cJSON_CreateArray(); - char *decoded; - - if (acl == NULL || ace == NULL || allowed == NULL) { - fail_msg("Failed to create cJSON object"); - } - - *state = acl; - - cJSON_AddItemToObject(acl, "S-1-5-32-636", ace); - cJSON_AddItemToObject(ace, "allowed", allowed); - - fill_ace_array(allowed); - - decoded = perm_json_to_old_format(acl); - - assert_non_null(decoded); - assert_string_equal(decoded, "S-1-5-32-636 (allowed): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|" - "WRITE_OWNER|SYNCHRONIZE|READ_DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|" - "READ_ATTRIBUTES|WRITE_ATTRIBUTES"); - free(decoded); -} - -static void test_perm_json_to_old_format_denied_ace_only(void **state) { - cJSON *acl = cJSON_CreateObject(); - cJSON *ace = cJSON_CreateObject(); - cJSON *denied = cJSON_CreateArray(); - char *decoded; - - if (acl == NULL || ace == NULL || denied == NULL) { - fail_msg("Failed to create cJSON object"); - } - - *state = acl; - - cJSON_AddItemToObject(acl, "S-1-5-32-636", ace); - cJSON_AddItemToObject(ace, "denied", denied); - cJSON_AddItemToObject(ace, "name", cJSON_CreateString("username")); - - fill_ace_array(denied); - - decoded = perm_json_to_old_format(acl); - - assert_non_null(decoded); - assert_string_equal(decoded, "username (denied): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|" - "WRITE_OWNER|SYNCHRONIZE|READ_DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|" - "READ_ATTRIBUTES|WRITE_ATTRIBUTES"); - free(decoded); -} - -static void test_perm_json_to_old_format_both_aces(void **state) { - cJSON *acl = cJSON_CreateObject(); - cJSON *ace = cJSON_CreateObject(); - cJSON *allowed = cJSON_CreateArray(); - cJSON *denied = cJSON_CreateArray(); - char *decoded; - - if (acl == NULL || ace == NULL || allowed == NULL || denied == NULL) { - fail_msg("Failed to create cJSON object"); - } - - *state = acl; - - cJSON_AddItemToObject(acl, "S-1-5-32-636", ace); - cJSON_AddItemToObject(ace, "name", cJSON_CreateString("username")); - cJSON_AddItemToObject(ace, "denied", denied); - cJSON_AddItemToObject(ace, "allowed", allowed); - - fill_ace_array(denied); - fill_ace_array(allowed); - - decoded = perm_json_to_old_format(acl); - - assert_non_null(decoded); - assert_string_equal(decoded, "username (allowed): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|" - "WRITE_OWNER|SYNCHRONIZE|READ_DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|" - "READ_ATTRIBUTES|WRITE_ATTRIBUTES, username (denied): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|" - "WRITE_OWNER|SYNCHRONIZE|READ_DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|" - "READ_ATTRIBUTES|WRITE_ATTRIBUTES"); - free(decoded); -} - -static void test_perm_json_to_old_format_empty_acl(void **state) { - cJSON *acl = cJSON_CreateObject(); - char *decoded; - - if (acl == NULL) { - fail_msg("Failed to create cJSON object"); - } - - *state = acl; - - decoded = perm_json_to_old_format(acl); - - assert_null(decoded); -} - -static void test_perm_json_to_old_format_empty_aces(void **state) { - cJSON *acl = cJSON_CreateObject(); - cJSON *ace = cJSON_CreateObject(); - cJSON *allowed = cJSON_CreateArray(); - cJSON *denied = cJSON_CreateArray(); - char *decoded; - - if (acl == NULL || ace == NULL || allowed == NULL || denied == NULL) { - fail_msg("Failed to create cJSON object"); - } - - *state = acl; - - cJSON_AddItemToObject(acl, "S-1-5-32-636", ace); - cJSON_AddItemToObject(ace, "name", cJSON_CreateString("username")); - cJSON_AddItemToObject(ace, "denied", denied); - cJSON_AddItemToObject(ace, "allowed", allowed); - - decoded = perm_json_to_old_format(acl); - - assert_non_null(decoded); - assert_string_equal(decoded, "username (allowed): , username (denied): "); - free(decoded); -} - -static void test_perm_json_to_old_format_multiple_aces(void **state) { - const char *const SIDS[] = { - "S-1-5-32-636", - "S-1-5-32-363", - "S-1-5-32-444", - NULL - }; - const char * const USERNAMES[] = { - "username", - "otheruser", - "anon", - NULL - }; - int i; - const char *it; - cJSON *acl = cJSON_CreateObject(); - char *decoded; - - if (acl == NULL) { - fail_msg("Failed to create cJSON object"); - } - - *state = acl; - - for (i = 0, it = SIDS[0]; it; it = SIDS[++i]) { - cJSON *ace = cJSON_CreateObject(); - cJSON *allowed = cJSON_CreateArray(); - cJSON *denied = cJSON_CreateArray(); - if (ace == NULL || allowed == NULL || denied == NULL) { - fail_msg("Failed to create cJSON object"); - } - - cJSON_AddItemToObject(acl, it, ace); - cJSON_AddItemToObject(ace, "name", cJSON_CreateString(USERNAMES[i])); - cJSON_AddItemToObject(ace, "denied", denied); - cJSON_AddItemToObject(ace, "allowed", allowed); - - fill_ace_array(denied); - fill_ace_array(allowed); - } - - decoded = perm_json_to_old_format(acl); - - assert_non_null(decoded); - assert_string_equal( - decoded, - "username (allowed): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|WRITE_OWNER|SYNCHRONIZE|READ_" - "DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|READ_ATTRIBUTES|WRITE_ATTRIBUTES, username (denied): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|WRITE_OWNER|SYNCHRONIZE|READ_" - "DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|READ_ATTRIBUTES|WRITE_ATTRIBUTES, " - "otheruser (allowed): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|WRITE_OWNER|SYNCHRONIZE|READ_" - "DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|READ_ATTRIBUTES|WRITE_ATTRIBUTES, otheruser (denied): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|WRITE_OWNER|SYNCHRONIZE|READ_" - "DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|READ_ATTRIBUTES|WRITE_ATTRIBUTES, " - "anon (allowed): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|WRITE_OWNER|SYNCHRONIZE|READ_" - "DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|READ_ATTRIBUTES|WRITE_ATTRIBUTES, anon (denied): " - "GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL|DELETE|READ_CONTROL|WRITE_DAC|WRITE_OWNER|SYNCHRONIZE|READ_" - "DATA|WRITE_DATA|APPEND_DATA|READ_EA|WRITE_EA|EXECUTE|READ_ATTRIBUTES|WRITE_ATTRIBUTES"); - free(decoded); -} - - -static void test_fim_adjust_checksum_no_attributes_no_win_perm(void **state) { - fim_adjust_checksum_data_t *data = *state; - - *data->checksum = strdup("unchanged string::"); - - fim_adjust_checksum(data->newsum, data->checksum); - - assert_string_equal(*data->checksum, "unchanged string::"); -} - -static void test_fim_adjust_checksum_no_win_perm_no_colon(void **state) { - fim_adjust_checksum_data_t *data = *state; - - *data->checksum = strdup("unchanged string"); - data->newsum->attributes = strdup("unused attributes"); - - fim_adjust_checksum(data->newsum, data->checksum); - - assert_string_equal(*data->checksum, "unchanged string"); -} - -static void test_fim_adjust_checksum_no_win_perm(void **state) { - fim_adjust_checksum_data_t *data = *state; - - *data->checksum = strdup("changed: string"); - data->newsum->attributes = strdup("to this"); - - fim_adjust_checksum(data->newsum, data->checksum); - - assert_string_equal(*data->checksum, "changed:to this"); -} - -static void test_fim_adjust_checksum_no_attributes_no_first_part(void **state) { - fim_adjust_checksum_data_t *data = *state; - - *data->checksum = strdup("unchanged string"); - data->newsum->win_perm = strdup("first part"); - - fim_adjust_checksum(data->newsum, data->checksum); - - assert_string_equal(*data->checksum, "unchanged string"); -} - -static void test_fim_adjust_checksum_no_attributes_no_second_part(void **state) { - fim_adjust_checksum_data_t *data = *state; - - *data->checksum = strdup("unchanged string: no second part"); - data->newsum->win_perm = strdup("first part"); - - fim_adjust_checksum(data->newsum, data->checksum); - - assert_string_equal(*data->checksum, "unchanged string:"); -} - -static void test_fim_adjust_checksum_no_attributes(void **state) { - fim_adjust_checksum_data_t *data = *state; - - *data->checksum = strdup("changed string: first part: second part"); - data->newsum->win_perm = strdup("replaced: this"); - - fim_adjust_checksum(data->newsum, data->checksum); - - assert_string_equal(*data->checksum, "changed string:replaced\\: this: second part"); -} - -static void test_fim_adjust_checksum_all_possible_data(void **state) { - fim_adjust_checksum_data_t *data = *state; - - *data->checksum = strdup("changed string: first part: second part:attributes"); - data->newsum->win_perm = strdup("replaced: this"); - data->newsum->attributes = strdup("new attributes"); - - fim_adjust_checksum(data->newsum, data->checksum); - - assert_string_equal(*data->checksum, "changed string:replaced\\: this: second part:new attributes"); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - /* fim_send_db_query */ - cmocka_unit_test(test_fim_send_db_query_success), - cmocka_unit_test(test_fim_send_db_query_communication_error), - cmocka_unit_test(test_fim_send_db_query_no_response), - cmocka_unit_test(test_fim_send_db_query_format_error), - - /* fim_send_db_delete */ - cmocka_unit_test(test_fim_send_db_delete_success), - cmocka_unit_test(test_fim_send_db_delete_query_too_long), - cmocka_unit_test(test_fim_send_db_delete_null_agent_id), - cmocka_unit_test(test_fim_send_db_delete_null_path), - - /* fim_send_db_save */ - cmocka_unit_test_setup_teardown(test_fim_send_db_save_success, setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_send_db_save_event_too_long, setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_send_db_save_null_agent_id, setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_send_db_save_null_data, setup_fim_event_cjson, teardown_cjson), - - /* fim_process_scan_info */ - cmocka_unit_test_setup_teardown(test_fim_process_scan_info_scan_start,setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_process_scan_info_scan_end, setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_process_scan_info_timestamp_not_a_number,setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_process_scan_info_query_too_long,setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_process_scan_info_null_agent_id,setup_fim_event_cjson, teardown_cjson), - cmocka_unit_test_setup_teardown(test_fim_process_scan_info_null_data,setup_fim_event_cjson, teardown_cjson), - - /* fim_fetch_attributes_state */ - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_state_new_attr, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_state_old_attr, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_state_item_with_no_key, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_state_invalid_element_type, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_state_null_attr, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_state_null_lf, setup_fim_data, teardown_fim_data), - - /* fim_fetch_attributes */ - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_success, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_invalid_attribute, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_null_new_attrs, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_null_old_attrs, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_null_lf, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_fetch_attributes_windows_perms, setup_fim_data_win_perms, teardown_fim_data), - - /* fim_generate_comment */ - cmocka_unit_test(test_fim_generate_comment_both_parameters), - cmocka_unit_test(test_fim_generate_comment_a1), - cmocka_unit_test(test_fim_generate_comment_a2), - cmocka_unit_test(test_fim_generate_comment_no_parameters), - cmocka_unit_test(test_fim_generate_comment_matching_parameters), - cmocka_unit_test(test_fim_generate_comment_size_not_big_enough), - cmocka_unit_test(test_fim_generate_comment_invalid_format), - - /* fim_generate_alert */ - cmocka_unit_test_setup_teardown(test_fim_generate_alert_full_alert, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_generate_alert_registry_key_alert, setup_registry_key_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_generate_alert_registry_value_alert, setup_registry_value_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_generate_alert_type_not_modified, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_generate_alert_invalid_element_in_attributes, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_generate_alert_invalid_element_in_audit, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_generate_alert_null_mode, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_generate_alert_null_audit, setup_fim_data, teardown_fim_data), - - /* fim_process_alert */ - cmocka_unit_test_setup_teardown(test_fim_process_alert_added_success, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_modified_success, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_deleted_success, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_event_type, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_invalid_entry_type, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_invalid_event_type, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_invalid_object, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_path, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_hard_links, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_mode, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_tags, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_content_changes, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_changed_attributes, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_attributes, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_old_attributes, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_audit, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_null_event, setup_fim_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_remove_registry_key, setup_registry_key_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_remove_registry_value, setup_registry_value_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_no_hash, setup_registry_key_data, teardown_fim_data), - cmocka_unit_test_setup_teardown(test_fim_process_alert_legacy_agents, setup_registry_key_data, teardown_fim_data), - - - /* decode_fim_event */ - cmocka_unit_test_setup_teardown(test_decode_fim_event_type_event, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_type_scan_start, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_type_scan_end, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_type_invalid, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_null_item, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_no_data, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_no_type, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_invalid_json, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_null_sdb, setup_decode_fim_event, teardown_decode_fim_event), - cmocka_unit_test_setup_teardown(test_decode_fim_event_null_eventinfo, setup_decode_fim_event, teardown_decode_fim_event), - - cmocka_unit_test(test_perm_json_to_old_format_null_acl), - cmocka_unit_test_teardown(test_perm_json_to_old_format_allowed_ace_only, teardown_cjson), - cmocka_unit_test_teardown(test_perm_json_to_old_format_denied_ace_only, teardown_cjson), - cmocka_unit_test_teardown(test_perm_json_to_old_format_both_aces, teardown_cjson), - cmocka_unit_test_teardown(test_perm_json_to_old_format_empty_acl, teardown_cjson), - cmocka_unit_test_teardown(test_perm_json_to_old_format_empty_aces, teardown_cjson), - cmocka_unit_test_teardown(test_perm_json_to_old_format_multiple_aces, teardown_cjson), - - /* fim_adjust_checksum */ - cmocka_unit_test_setup_teardown(test_fim_adjust_checksum_no_attributes_no_win_perm, setup_fim_adjust_checksum, teardown_fim_adjust_checksum), - cmocka_unit_test_setup_teardown(test_fim_adjust_checksum_no_win_perm_no_colon, setup_fim_adjust_checksum, teardown_fim_adjust_checksum), - cmocka_unit_test_setup_teardown(test_fim_adjust_checksum_no_win_perm, setup_fim_adjust_checksum, teardown_fim_adjust_checksum), - cmocka_unit_test_setup_teardown(test_fim_adjust_checksum_no_attributes_no_first_part, setup_fim_adjust_checksum, teardown_fim_adjust_checksum), - cmocka_unit_test_setup_teardown(test_fim_adjust_checksum_no_attributes_no_second_part, setup_fim_adjust_checksum, teardown_fim_adjust_checksum), - cmocka_unit_test_setup_teardown(test_fim_adjust_checksum_no_attributes, setup_fim_adjust_checksum, teardown_fim_adjust_checksum), - cmocka_unit_test_setup_teardown(test_fim_adjust_checksum_all_possible_data, setup_fim_adjust_checksum, teardown_fim_adjust_checksum), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_asyscom.c b/src/unit_tests/analysisd/test_asyscom.c deleted file mode 100644 index 1f5f9637268..00000000000 --- a/src/unit_tests/analysisd/test_asyscom.c +++ /dev/null @@ -1,692 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../analysisd/analysisd.h" -#include "../../analysisd/state.h" - -#include "../wrappers/posix/select_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/analysisd/state_wrappers.h" -#include "../wrappers/wazuh/analysisd/config_wrappers.h" - -char* asyscom_output_builder(int error_code, const char* message, cJSON* data_json); -size_t asyscom_dispatch(char * command, char ** output); - -/* setup/teardown */ - -static int test_teardown(void ** state) { - char* string = *state; - os_free(string); - return 0; -} - -// Wrappers - -int __wrap_accept() { - return mock(); -} - -/* Tests */ - -void test_asyscom_output_builder(void ** state) { - int error_code = 5; - const char* message = "test msg"; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "analysisd"); - - char* msg = asyscom_output_builder(error_code, message, data_json); - - *state = msg; - - assert_non_null(msg); - assert_string_equal(msg, "{\"error\":5,\"message\":\"test msg\",\"data\":{\"test1\":18,\"test2\":\"analysisd\"}}"); -} - -void test_asyscom_dispatch_getstats(void ** state) { - char* request = "{\"command\":\"getstats\"}"; - char *response = NULL; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "analysisd"); - - will_return(__wrap_asys_create_state_json, data_json); - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":18,\"test2\":\"analysisd\"}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getconfig(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{\"section\":\"global\"}}"; - char *response = NULL; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "analysisd"); - - will_return(__wrap_getGlobalConfig, data_json); - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":18,\"test2\":\"analysisd\"}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getconfig_unknown_section(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{\"section\":\"testtest\"}}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":7,\"message\":\"Unrecognized or not configured section\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getconfig_empty_section(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{}}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":6,\"message\":\"Empty section\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getconfig_empty_parameters(void ** state) { - char* request = "{\"command\":\"getconfig\"}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":5,\"message\":\"Empty parameters\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_empty_parameters(void ** state) { - char* request = "{\"command\":\"getagentsstats\"}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":5,\"message\":\"Empty parameters\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_invalid_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"agents\"}}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":8,\"message\":\"Invalid agents parameter\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_empty_last_id(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\"}}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":10,\"message\":\"Empty last id\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_too_many_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": [1,2,3,4,5,6,7,8,9,10,11, \ - 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \ - 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76]}}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":11,\"message\":\"Too many agents\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_all_empty_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\", \"last_id\": 0}}"; - char *response = NULL; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, ASYS_MAX_NUM_AGENTS_STATS); - will_return(__wrap_wdb_get_agents_ids_of_current_node, NULL); - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":9,\"message\":\"Error getting agents from DB\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_all_due(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\", \"last_id\": 0}}"; - char *response = NULL; - cJSON* data_json = cJSON_CreateObject(); - - int *connected_agents; - os_calloc(76, sizeof(int), connected_agents); - for (size_t i = 0; i < 75; i++) { - connected_agents[i] = i+1; - } - connected_agents[75] = OS_INVALID; - - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, ASYS_MAX_NUM_AGENTS_STATS); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_asys_create_agents_state_json, agents_ids, connected_agents); - will_return(__wrap_asys_create_agents_state_json, data_json); - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":1,\"message\":\"due\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_all_ok(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\", \"last_id\": 0}}"; - char *response = NULL; - cJSON* data_json = cJSON_CreateObject(); - - int *connected_agents; - os_calloc(2, sizeof(int), connected_agents); - connected_agents[0] = 1; - connected_agents[1] = OS_INVALID; - - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, ASYS_MAX_NUM_AGENTS_STATS); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_asys_create_agents_state_json, agents_ids, connected_agents); - will_return(__wrap_asys_create_agents_state_json, data_json); - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_array_empty_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": []}}"; - char *response = NULL; - - will_return(__wrap_json_parse_agents, NULL); - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":9,\"message\":\"Error getting agents from DB\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_getagentsstats_array_ok(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": [1]}}"; - char *response = NULL; - cJSON* data_json = cJSON_CreateObject(); - - int *connected_agents; - os_calloc(2, sizeof(int), connected_agents); - connected_agents[0] = 1; - connected_agents[1] = OS_INVALID; - - will_return(__wrap_json_parse_agents, connected_agents); - - expect_value(__wrap_asys_create_agents_state_json, agents_ids, connected_agents); - will_return(__wrap_asys_create_agents_state_json, data_json); - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_unknown_command(void ** state) { - char* request = "{\"command\":\"unknown\"}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":4,\"message\":\"Unrecognized command\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_empty_command(void ** state) { - char* request = "{}"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":3,\"message\":\"Empty command\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_dispatch_invalid_json(void ** state) { - char* request = "unknown"; - char *response = NULL; - - size_t size = asyscom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":2,\"message\":\"Invalid JSON input\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_asyscom_main(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - size_t input_size = strlen(input) + 1; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "analysisd"); - - char *response = "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":18,\"test2\":\"analysisd\"}}"; - size_t response_size = strlen(response); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - will_return(__wrap_asys_create_state_json, data_json); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, response_size); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_max_size(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_MAXLEN); - - expect_string(__wrap__merror, formatted_msg, "Received message > '4194304'"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_empty(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Empty message from local client"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_error(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, -1); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): 'Success'"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_sockerror(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_accept_error(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, -1); - - expect_string(__wrap__merror, formatted_msg, "At accept(): 'Success'"); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_select_zero(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 0); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_select_error_eintr(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = EINTR; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, -1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - asyscom_main(NULL); -} - -void test_asyscom_main_select_error(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, -1); - - expect_string(__wrap__merror_exit, formatted_msg, "At select(): 'Success'"); - - expect_assert_failure(asyscom_main(NULL)); -} - -void test_asyscom_main_bind_error(void **state) -{ - int socket = 0; - int peer = 1111; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, ANLSYS_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, -1); - - expect_string(__wrap__merror, formatted_msg, "Unable to bind to socket 'queue/sockets/analysis': (0) 'Success'"); - - asyscom_main(NULL); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test asyscom_output_builder - cmocka_unit_test_teardown(test_asyscom_output_builder, test_teardown), - // Test asyscom_dispatch - cmocka_unit_test_teardown(test_asyscom_dispatch_getstats, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getconfig, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getconfig_unknown_section, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getconfig_empty_section, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getconfig_empty_parameters, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_empty_parameters, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_invalid_agents, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_empty_last_id, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_too_many_agents, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_all_empty_agents, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_all_due, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_all_ok, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_array_empty_agents, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_getagentsstats_array_ok, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_unknown_command, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_empty_command, test_teardown), - cmocka_unit_test_teardown(test_asyscom_dispatch_invalid_json, test_teardown), - // Test asyscom_main - cmocka_unit_test(test_asyscom_main), - cmocka_unit_test(test_asyscom_main_max_size), - cmocka_unit_test(test_asyscom_main_empty), - cmocka_unit_test(test_asyscom_main_error), - cmocka_unit_test(test_asyscom_main_sockerror), - cmocka_unit_test(test_asyscom_main_accept_error), - cmocka_unit_test(test_asyscom_main_select_zero), - cmocka_unit_test(test_asyscom_main_select_error_eintr), - cmocka_unit_test(test_asyscom_main_select_error), - cmocka_unit_test(test_asyscom_main_bind_error), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_cleanevent.c b/src/unit_tests/analysisd/test_cleanevent.c deleted file mode 100644 index 22c3ef7511a..00000000000 --- a/src/unit_tests/analysisd/test_cleanevent.c +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../analysisd/cleanevent.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -static int test_setup(void **state) { - Eventinfo *lf = NULL; - os_calloc(1, sizeof(Eventinfo), lf); - *state = lf; - - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - Eventinfo *lf = (Eventinfo *)*state; - os_free(lf->full_log); - os_free(lf->location); - os_free(lf->location); - os_free(lf->agent_id); - os_free(lf->hostname); - os_free(lf); - - return OS_SUCCESS; -} - -/* Tests */ - -static void test_OS_CleanMSG_fail(void **state) { - - Eventinfo lf; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%s", "fail message"); - expect_string(__wrap__merror, formatted_msg, "(1106): String not correctly formatted."); - - int value = OS_CleanMSG(msg, &lf); - - assert_int_equal(value, -1); - - os_free(msg); -} - -static void test_OS_CleanMSG_fail_short_msg(void **state) { - - Eventinfo lf; - - char *msg = NULL; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%s", "1:a"); - expect_string(__wrap__merror, formatted_msg, "(1106): String not correctly formatted."); - - int value = OS_CleanMSG(msg, &lf); - - assert_int_equal(value, -1); - - os_free(msg); -} - -static void test_OS_CleanMSG_ossec_min_msg(void **state) { - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "a", "b"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->full_log, "b"); - assert_string_equal(lf->location, "a"); - - os_free(msg); -} - -static void test_OS_CleanMSG_ossec_arrow_msg(void **state) { - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s->%s", '5', "[015] (DESKTOP) any", "fim_registry:payload"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->full_log, "payload"); - assert_string_equal(lf->location, "(DESKTOP) any->fim_registry"); - - os_free(msg); -} - -static void test_OS_CleanMSG_ossec_test_msg(void **state) { - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "location test", "payload test"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->full_log, "payload test"); - assert_string_equal(lf->location, "location test"); - - os_free(msg); -} - -static void test_OS_CleanMSG_ossec_syslog_msg(void **state) { - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "payload test"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->full_log, "payload test"); - assert_string_equal(lf->location, "/var/log/syslog"); - - os_free(msg); -} - -static void test_OS_CleanMSG_syslog_ipv4_msg(void **state) { - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '2', "127.0.0.1", "payload test"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->full_log, "payload test"); - assert_string_equal(lf->location, "127.0.0.1"); - - os_free(msg); -} - -static void test_OS_CleanMSG_syslog_ipv6_msg(void **state) { - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '2', "0000|:0000|:0000|:0000|:0000|:0000|:0000|:0001", "payload test"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->full_log, "payload test"); - assert_string_equal(lf->location, "0000:0000:0000:0000:0000:0000:0000:0001"); - - os_free(msg); -} - -static void test_OS_CleanMSG_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "2015 Dec 29 10:00:01 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->program_name, "AUTH"); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "2015 Dec 29 10:00:01 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - assert_string_equal(lf->dec_timestamp, "2015 Dec 29 10:00:01"); - - os_free(msg); -} - -static void test_OS_CleanMSG_macos_ULS_syslog_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "2021-04-21 10:16:09.404756-0700 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->program_name, "AUTH"); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "2021-04-21 10:16:09.404756-0700 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - assert_string_equal(lf->dec_timestamp, "2021-04-21 10:16:09.404756-0700"); - - os_free(msg); -} - -static void test_OS_CleanMSG_proftpd_1_3_5_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "2015-04-16 21:51:02,805 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->program_name, "AUTH"); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "2015-04-16 21:51:02,805 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - assert_string_equal(lf->dec_timestamp, "2015-04-16 21:51:02,805"); - - os_free(msg); -} - -static void test_OS_CleanMSG_syslog_ng_isodate_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "2007-06-14T15:48:55-04:00 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->program_name, "AUTH"); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "2007-06-14T15:48:55-04:00 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - assert_string_equal(lf->dec_timestamp, "2007-06-14T15:48:55-04:00"); - - os_free(msg); -} - -static void test_OS_CleanMSG_rsyslog_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "2009-05-22T09:36:46.214994-07:00 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->program_name, "AUTH"); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "2009-05-22T09:36:46.214994-07:00 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - assert_string_equal(lf->dec_timestamp, "2009-05-22T09:36:46.214994-07:00"); - - os_free(msg); -} - -static void test_OS_CleanMSG_syslog_isodate_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "2022-12-19T15:02:53.288+00:00 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->program_name, "AUTH"); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "2022-12-19T15:02:53.288+00:00 wazuh-agent01 AUTH:INFO sshd[223468]: LOG BODY"); - assert_string_equal(lf->dec_timestamp, "2022-12-19T15:02:53.288+00:00"); - - os_free(msg); -} - -static void test_OS_CleanMSG_apache_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/apache", "[Fri Feb 11 18:06:35 2004] [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/apache"); - assert_string_equal(lf->full_log, "[Fri Feb 11 18:06:35 2004] [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - assert_string_equal(lf->dec_timestamp, "Fri Feb 11 18:06:35 2004"); - - os_free(msg); -} - -static void test_OS_CleanMSG_suricata_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "01/28/1979-09:13:16.240702 [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "01/28/1979-09:13:16.240702 [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - assert_string_equal(lf->dec_timestamp, "01/28/1979-09:13:16.240702"); - - os_free(msg); -} - -static void test_OS_CleanMSG_osx_asl_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "[Time 2006.12.28 15:53:55 UTC] [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->program_name, "sshd"); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "[Time 2006.12.28 15:53:55 UTC] [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - assert_null(lf->dec_timestamp); - - os_free(msg); -} - -static void test_OS_CleanMSG_snort_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "01/28-09:13:16.240702 [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "01/28-09:13:16.240702 [Facility auth] [Sender sshd] [PID 483] [Message error: PAM: Authentication failure for username from 192.168.0.2] [Level 3] [UID -2] [GID -2] [Host Hostname]"); - assert_string_equal(lf->dec_timestamp, "01/28-09:13:16.240702"); - - os_free(msg); -} - -static void test_OS_CleanMSG_xferlog_timestamp(void **state){ - - Eventinfo *lf = (Eventinfo *)*state; - - char *msg; - os_calloc(OS_BUFFER_SIZE, sizeof(char), msg); - snprintf(msg, OS_BUFFER_SIZE, "%c:%s:%s", '1', "/var/log/syslog", "Mon Apr 17 18:27:14 2006 1 64.160.42.130"); - - int value = OS_CleanMSG(msg, lf); - - assert_int_equal(value, 0); - assert_string_equal(lf->agent_id, "000"); - assert_string_equal(lf->location, "/var/log/syslog"); - assert_string_equal(lf->full_log, "Mon Apr 17 18:27:14 2006 1 64.160.42.130"); - assert_string_equal(lf->dec_timestamp, "Mon Apr 17 18:27:14 2006"); - - os_free(msg); -} - -void test_extract_module_from_message(void ** state) { - char message[32] = "1:/var/log/demo.log:Hello world"; - - char *module = extract_module_from_message(message); - - assert_string_equal(module, "/var/log/demo.log"); -} - -void test_extract_module_from_message_arrow(void ** state) { - char message[61] = "1:[001] (testing) 192.168.1.1->/var/log/demo.log:Hello world"; - - char *module = extract_module_from_message(message); - - assert_string_equal(module, "/var/log/demo.log"); -} - -void test_extract_module_from_message_end_error(void ** state) { - char message[32] = "1:/var/log/demo.log;Hello world"; - - expect_string(__wrap__merror, formatted_msg, "(1106): String not correctly formatted."); - - char *module = extract_module_from_message(message); - - assert_null(module); -} - -void test_extract_module_from_message_arrow_error(void ** state) { - char message[61] = "1:[001] (testing) 192.168.1.1- -#include -#include -#include - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/read-agents_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - -#include "../analysisd/eventinfo.h" -#include "../analysisd/decoders/decoder.h" -#include "../headers/wazuhdb_op.h" - -/* setup/teardown redefinitions */ -#define setup_dispatch_check setup_dispatch_answer -#define teardown_dispatch_check teardown_dispatch_answer -#define setup_dispatch_state setup_dispatch_answer -#define teardown_dispatch_state teardown_dispatch_answer -#define setup_dispatch_clear setup_dispatch_answer -#define teardown_dispatch_clear teardown_dispatch_answer - -void dispatch_send_local(dbsync_context_t * ctx, const char * query); -void dispatch_send_remote(dbsync_context_t * ctx, const char * query, unsigned attempts); -void dispatch_answer(dbsync_context_t * ctx, const char * result); -void dispatch_check(dbsync_context_t * ctx, const char * command); -void dispatch_state(dbsync_context_t * ctx); -void dispatch_clear(dbsync_context_t * ctx); -void DispatchDBSync(dbsync_context_t * ctx, Eventinfo * lf); - -/* auxiliary structs */ -typedef struct __test_dbsync_s{ - dbsync_context_t *ctx; - Eventinfo *lf; -}test_dbsync_t; - -/* setup/teardowns */ -static int setup_dbsync_context(void **state) { - test_dbsync_t *data; - - if(data = calloc(1, sizeof(test_dbsync_t)), !data) - return -1; - - if(data->ctx = calloc(1, sizeof(dbsync_context_t)), !data->ctx) - return -1; - - *state = data; - - return 0; -} - -static int teardown_dbsync_context(void **state) { - test_dbsync_t *data = *state; - - if(data->ctx){ - free(data->ctx); - data->ctx = NULL; - } - - if(data) { - free(data); - data = NULL; - } - - return 0; -} - -static int setup_send_local(void **state) { - test_dbsync_t *data = *state; - - data->ctx->component = calloc(OS_SIZE_32, sizeof(char)); - - if(data->ctx->component == NULL) return -1; - - return 0; -} - -static int teardown_dispatch_send_local(void **state) { - test_dbsync_t *data = *state; - - if(data->ctx->component) { - free(data->ctx->component); - data->ctx->component = NULL; - } - - errno = 0; - - return 0; -} - -static int setup_dispatch_send_remote(void **state) { - test_dbsync_t *data = *state; - - data->ctx->agent_id = calloc(OS_SIZE_16, sizeof(char)); - data->ctx->component = calloc(OS_SIZE_16, sizeof(char)); - - if(data->ctx->agent_id == NULL || - data->ctx->component == NULL) - return -1; - - return 0; -} - -static int teardown_dispatch_send_remote(void **state) { - test_dbsync_t *data = *state; - - if(data->ctx->agent_id) { - free(data->ctx->agent_id); - data->ctx->agent_id = NULL; - } - - if(data->ctx->component) { - free(data->ctx->component); - data->ctx->component = NULL; - } - - return 0; -} - -static int setup_dispatch_answer(void **state) { - test_dbsync_t *data = *state; - - data->ctx->data = cJSON_Parse( - "{\"tail\": \"tail\", \"checksum\": \"checksum\", \"begin\": \"/a/path\", \"end\": \"/z/path\"}"); - data->ctx->agent_id = calloc(OS_SIZE_16, sizeof(char)); - data->ctx->component = calloc(OS_SIZE_16, sizeof(char)); - - if(data->ctx->data == NULL || - data->ctx->agent_id == NULL || - data->ctx->component == NULL) - return -1; - - return 0; -} - -static int teardown_dispatch_answer(void **state) { - test_dbsync_t *data = *state; - - cJSON_Delete(data->ctx->data); - data->ctx->data = NULL; - - if(data->ctx->agent_id) { - free(data->ctx->agent_id); - data->ctx->agent_id = NULL; - } - - if(data->ctx->component) { - free(data->ctx->component); - data->ctx->component = NULL; - } - - return 0; -} - -static int setup_DispatchDBSync(void **state) { - test_dbsync_t *data = *state; - - if(data->lf = calloc(1, sizeof(Eventinfo)), !data->lf) - return -1; - - data->lf->log = strdup( - "{" - "\"component\": \"syscheck\"," - "\"type\": \"integrity_check_test\"," - "\"data\": {" - "\"tail\": \"tail\"," - "\"checksum\": \"checksum\"," - "\"begin\": \"/a/path\"," - "\"end\": \"/z/path\"" - "}" - "}"); - - if(data->lf->log == NULL) return -1; - - data->lf->agent_id = calloc(OS_SIZE_16, sizeof(char)); - - if(data->lf->agent_id == NULL) return -1; - - return 0; -} - -static int teardown_DispatchDBSync(void **state) { - test_dbsync_t *data = *state; - - if(data->lf->log) { - free(data->lf->log); - data->lf->log = NULL; - } - - Free_Eventinfo(data->lf); - - return 0; -} - -/* tests */ -/* dispatch_send_local */ -static void test_dispatch_send_local_success(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SYS_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, 65555); - - expect_value(__wrap_OS_SendSecureTCP, sock, 65555); - expect_value(__wrap_OS_SendSecureTCP, size, 0x36); - expect_string(__wrap_OS_SendSecureTCP, msg, "syscheck This is a mock query, it won't go anywhere..."); - will_return(__wrap_OS_SendSecureTCP, 0); - - // Assertions to this function are done through wrappers. - dispatch_send_local(data->ctx, query); -} - -static void test_dispatch_send_local_success_syscollector(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - snprintf(data->ctx->component, OS_SIZE_32, "syscollector-process"); - - expect_string(__wrap_OS_ConnectUnixDomain, path, WM_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, 65555); - - expect_value(__wrap_OS_SendSecureTCP, sock, 65555); - expect_value(__wrap_OS_SendSecureTCP, size, 66); - expect_string(__wrap_OS_SendSecureTCP, msg, "syscollector-process This is a mock query, it won't go anywhere..."); - will_return(__wrap_OS_SendSecureTCP, 0); - - // Assertions to this function are done through wrappers. - dispatch_send_local(data->ctx, query); -} - -static void test_dispatch_send_local_socket_connect_error(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SYS_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "dbsync: cannot connect to syscheck: Too many open files in system (23)"); - - errno = ENFILE; - - // Assertions to this function are done through wrappers. - dispatch_send_local(data->ctx, query); -} - -static void test_dispatch_send_local_wrong_component(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - snprintf(data->ctx->component, OS_SIZE_16, "invalid"); - - expect_string(__wrap__merror, formatted_msg, "dbsync: unknown location 'invalid'"); - - // Assertions to this function are done through wrappers. - dispatch_send_local(data->ctx, query); -} - -static void test_dispatch_send_local_null_component(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - expect_string(__wrap__merror, formatted_msg, "dbsync: unknown location ''"); - - // Assertions to this function are done through wrappers. - dispatch_send_local(data->ctx, query); -} - -/* dispatch_send_remote */ -static void test_dispatch_send_remote_success(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - data->ctx->ar_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_send_msg_to_agent, msocket, 65555); - expect_string(__wrap_send_msg_to_agent, msg, - "syscheck This is a mock query, it won't go anywhere..."); - expect_string(__wrap_send_msg_to_agent, agt_id, "007"); - expect_value(__wrap_send_msg_to_agent, exec, NULL); - will_return(__wrap_send_msg_to_agent, 0); - - // Assertions to this function are done through wrappers. - dispatch_send_remote(data->ctx, query, 3); -} - -static void test_dispatch_send_remote_not_connected_success(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - data->ctx->ar_sock = -1; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - will_return(__wrap_connect_to_remoted, 65555); - - expect_value(__wrap_send_msg_to_agent, msocket, 65555); - expect_string(__wrap_send_msg_to_agent, msg, - "syscheck This is a mock query, it won't go anywhere..."); - expect_string(__wrap_send_msg_to_agent, agt_id, "007"); - expect_value(__wrap_send_msg_to_agent, exec, NULL); - will_return(__wrap_send_msg_to_agent, 0); - - // Assertions to this function are done through wrappers. - dispatch_send_remote(data->ctx, query, 3); -} - -static void test_dispatch_send_remote_not_connected_error(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - data->ctx->ar_sock = -1; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - will_return(__wrap_connect_to_remoted, -1); - - // Assertions to this function are done through wrappers. - dispatch_send_remote(data->ctx, query, 3); -} - -static void test_dispatch_send_remote_retry(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - data->ctx->ar_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value_count(__wrap_send_msg_to_agent, msocket, 65555, 2); - expect_string_count(__wrap_send_msg_to_agent, msg, - "syscheck This is a mock query, it won't go anywhere...", 2); - expect_string_count(__wrap_send_msg_to_agent, agt_id, "007", 2); - expect_value_count(__wrap_send_msg_to_agent, exec, NULL, 2); - - will_return(__wrap_send_msg_to_agent, -1); // Fail the first time - - will_return(__wrap_connect_to_remoted, 65555); // Reconnect and send successfully - will_return(__wrap_send_msg_to_agent, 0); - - // Assertions to this function are done through wrappers. - dispatch_send_remote(data->ctx, query, 3); -} - -static void test_dispatch_send_remote_retry_3_times(void **state) { - test_dbsync_t *data = *state; - const char *query = "This is a mock query, it won't go anywhere..."; - - data->ctx->ar_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - will_return_always(__wrap_connect_to_remoted, 65555); // Always reconnect - - expect_value_count(__wrap_send_msg_to_agent, msocket, 65555, 4); - expect_string_count(__wrap_send_msg_to_agent, msg, - "syscheck This is a mock query, it won't go anywhere...", 4); - expect_string_count(__wrap_send_msg_to_agent, agt_id, "007", 4); - expect_value_count(__wrap_send_msg_to_agent, exec, NULL, 4); - - will_return_always(__wrap_send_msg_to_agent, -1); // Always fail to send - - // Assertions to this function are done through wrappers. - dispatch_send_remote(data->ctx, query, 3); -} - -/* dispatch_answer */ -static void test_dispatch_answer_local_success(void **state) { - test_dbsync_t *data = *state; - const char *result = "result_text"; - - data->ctx->ar_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "000"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SYS_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, 65555); - - expect_value(__wrap_OS_SendSecureTCP, sock, 65555); - expect_value(__wrap_OS_SendSecureTCP, size, 0x3f); - expect_string(__wrap_OS_SendSecureTCP, msg, "syscheck dbsync result_text {\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - will_return(__wrap_OS_SendSecureTCP, 0); - - dispatch_answer(data->ctx, result); -} - -static void test_dispatch_answer_remote_success(void **state) { - test_dbsync_t *data = *state; - const char *result = "result_text"; - - data->ctx->ar_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_send_msg_to_agent, msocket, 65555); - expect_string(__wrap_send_msg_to_agent, msg, - "syscheck dbsync result_text {\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_string(__wrap_send_msg_to_agent, agt_id, "007"); - expect_value(__wrap_send_msg_to_agent, exec, NULL); - will_return(__wrap_send_msg_to_agent, 0); - - dispatch_answer(data->ctx, result); -} - -static void test_dispatch_answer_query_too_long(void **state) { - test_dbsync_t *data = *state; - char result[OS_MAXSTR]; - - data->ctx->ar_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - memset(result, 'a', OS_MAXSTR); - result[OS_MAXSTR - 1] = '\0'; - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot build query for agent: query is too long."); - - dispatch_answer(data->ctx, result); -} - -/* dispatch_check */ -static void test_dispatch_check_success(void **state) { - test_dbsync_t *data = *state; - const char *command = "command"; - char *response = "This is a mock response, payload points -> here <-"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck command {\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_send_msg_to_agent, msocket, 65555); - expect_string(__wrap_send_msg_to_agent, msg, - "syscheck dbsync is a mock response, payload points -> here <- {\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_string(__wrap_send_msg_to_agent, agt_id, "007"); - expect_value(__wrap_send_msg_to_agent, exec, NULL); - will_return(__wrap_send_msg_to_agent, 0); - - dispatch_check(data->ctx, command); -} - -static void test_dispatch_check_corrupt_message(void **state) { - dbsync_context_t ctx; - const char *command = "command"; - - ctx.data = NULL; - - expect_string(__wrap__merror, formatted_msg, "dbsync: Corrupt message: cannot get data member."); - - dispatch_check(&ctx, command); -} - -static void test_dispatch_check_query_too_long(void **state) { - test_dbsync_t *data = *state; - char command[OS_MAXSTR]; - - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - memset(command, 'a', OS_MAXSTR); - command[OS_MAXSTR - 1] = '\0'; - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot build check query: input is too long."); - - dispatch_check(data->ctx, command); -} - -static void test_dispatch_check_unable_to_communicate_with_db(void **state) { - test_dbsync_t *data = *state; - const char *command = "command"; - char *response = "This is a mock response, payload points -> here <-"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck command {\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -2); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot communicate with database."); - - dispatch_check(data->ctx, command); -} - -static void test_dispatch_check_no_response_from_db(void **state) { - test_dbsync_t *data = *state; - const char *command = "command"; - char *response = "This is a mock response, payload points -> here <-"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck command {\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -1); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot get response from database."); - - dispatch_check(data->ctx, command); -} - -static void test_dispatch_check_error_parsing_response(void **state) { - test_dbsync_t *data = *state; - const char *command = "command"; - char *response = "This is a mock response"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck command {\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Bad response from database: is a mock response"); - - dispatch_check(data->ctx, command); -} - -/* dispatch_state */ -static void test_dispatch_state_success(void **state) { - test_dbsync_t *data = *state; - char *response = "This is a mock response, payload points -> here <-"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck save2 " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - // Assertions for this test are done through wrappers - dispatch_state(data->ctx); -} - -static void test_dispatch_state_corrupted_message(void **state) { - test_dbsync_t *data = *state; - - cJSON_Delete(data->ctx->data); - data->ctx->data = NULL; - - expect_string(__wrap__merror, formatted_msg, "dbsync: Corrupt message: cannot get data member."); - - // Assertions for this test are done through wrappers - dispatch_state(data->ctx); -} - -static void test_dispatch_state_query_too_long(void **state) { - test_dbsync_t *data = *state; - char *p; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - - p = realloc(data->ctx->component, OS_MAXSTR * sizeof(char)); - - if(p == NULL) - fail(); - - data->ctx->component = p; - - memset(data->ctx->component, 'a', OS_MAXSTR); - data->ctx->component[OS_MAXSTR - 1] = '\0'; - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot build save query: input is too long."); - - // Assertions for this test are done through wrappers - dispatch_state(data->ctx); -} - -static void test_dispatch_state_unable_to_communicate_with_db(void **state) { - test_dbsync_t *data = *state; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck save2 " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, -2); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot communicate with database."); - - // Assertions for this test are done through wrappers - dispatch_state(data->ctx); -} - -static void test_dispatch_state_no_response_from_db(void **state) { - test_dbsync_t *data = *state; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck save2 " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, -1); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot get response from database."); - - // Assertions for this test are done through wrappers - dispatch_state(data->ctx); -} - -static void test_dispatch_state_error_parsing_response(void **state) { - test_dbsync_t *data = *state; - char *response = "This is a mock response, payload points -> here <-"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck save2 " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - expect_string(__wrap__merror, formatted_msg, - "dbsync: Bad response from database: is a mock response, payload points -> here <-"); - - // Assertions for this test are done through wrappers - dispatch_state(data->ctx); -} - -/* dispatch_clear */ -static void test_dispatch_clear_success(void **state) { - test_dbsync_t *data = *state; - char *response = "This is a mock response, payload points -> here <-"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck integrity_clear " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - // Assertions for this test are done through wrappers - dispatch_clear(data->ctx); -} - -static void test_dispatch_clear_corrupted_message(void **state) { - test_dbsync_t *data = *state; - - cJSON_Delete(data->ctx->data); - data->ctx->data = NULL; - - expect_string(__wrap__merror, formatted_msg, "dbsync: Corrupt message: cannot get data member."); - - // Assertions for this test are done through wrappers - dispatch_clear(data->ctx); -} - -static void test_dispatch_clear_query_too_long(void **state) { - test_dbsync_t *data = *state; - char *p; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - - p = realloc(data->ctx->component, OS_MAXSTR * sizeof(char)); - - if(p == NULL) - fail(); - - data->ctx->component = p; - memset(data->ctx->component, 'a', OS_MAXSTR); - data->ctx->component[OS_MAXSTR - 1] = '\0'; - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot build clear query: input is too long."); - - // Assertions for this test are done through wrappers - dispatch_clear(data->ctx); -} - -static void test_dispatch_clear_unable_to_communicate_with_db(void **state) { - test_dbsync_t *data = *state; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck integrity_clear " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, -2); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot communicate with database."); - - // Assertions for this test are done through wrappers - dispatch_clear(data->ctx); -} - -static void test_dispatch_clear_no_response_from_db(void **state) { - test_dbsync_t *data = *state; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck integrity_clear " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, -1); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot get response from database."); - - // Assertions for this test are done through wrappers - dispatch_clear(data->ctx); -} - -static void test_dispatch_clear_error_parsing_response(void **state) { - test_dbsync_t *data = *state; - char *response = "This is a mock response, payload points -> here <-"; - - data->ctx->db_sock = 65555; - snprintf(data->ctx->agent_id, OS_SIZE_16, "007"); - snprintf(data->ctx->component, OS_SIZE_16, "syscheck"); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck integrity_clear " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - expect_string(__wrap__merror, formatted_msg, - "dbsync: Bad response from database: is a mock response, payload points -> here <-"); - - // Assertions for this test are done through wrappers - dispatch_clear(data->ctx); -} - -/* DispatchDBSync */ -static void test_DispatchDBSync_integrity_check_success(void **state) { - test_dbsync_t *data = *state; - char *response = "This is a mock response, payload points -> here <-"; - - snprintf(data->lf->agent_id, OS_SIZE_16, "007"); - - data->ctx->db_sock = 65555; - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck integrity_check_test {\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_send_msg_to_agent, msocket, 65555); - expect_string(__wrap_send_msg_to_agent, msg, - "syscheck dbsync is a mock response, payload points -> here <- {\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_string(__wrap_send_msg_to_agent, agt_id, "007"); - expect_value(__wrap_send_msg_to_agent, exec, NULL); - will_return(__wrap_send_msg_to_agent, 0); - - DispatchDBSync(data->ctx, data->lf); -} - -static void test_DispatchDBSync_state_success(void **state) { - test_dbsync_t *data = *state; - char *response = "This is a mock response, payload points -> here <-"; - cJSON *root = cJSON_Parse(data->lf->log); - - snprintf(data->lf->agent_id, OS_SIZE_16, "007"); - - data->ctx->db_sock = 65555; - - cJSON_DeleteItemFromObject(root, "type"); - cJSON_AddStringToObject(root, "type", "state"); - - free(data->lf->log); - data->lf->log = cJSON_PrintUnformatted(root); - - cJSON_Delete(root); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck save2 " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - DispatchDBSync(data->ctx, data->lf); -} - -static void test_DispatchDBSync_integrity_clear_success(void **state) { - test_dbsync_t *data = *state; - char *response = "This is a mock response, payload points -> here <-"; - cJSON *root = cJSON_Parse(data->lf->log); - - snprintf(data->lf->agent_id, OS_SIZE_16, "007"); - - data->ctx->db_sock = 65555; - - cJSON_DeleteItemFromObject(root, "type"); - cJSON_AddStringToObject(root, "type", "integrity_clear"); - - free(data->lf->log); - data->lf->log = cJSON_PrintUnformatted(root); - - cJSON_Delete(root); - - expect_value(__wrap_wdbc_query_ex, *sock, data->ctx->db_sock); - expect_string(__wrap_wdbc_query_ex, query, - "agent 007 syscheck integrity_clear " - "{\"tail\":\"tail\",\"checksum\":\"checksum\",\"begin\":\"/a/path\",\"end\":\"/z/path\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - DispatchDBSync(data->ctx, data->lf); -} - -static void test_DispatchDBSync_invalid_log(void **state) { - test_dbsync_t *data = *state; - - snprintf(data->lf->agent_id, OS_SIZE_16, "007"); - - data->ctx->db_sock = 65555; - - free(data->lf->log); - if(data->lf->log = strdup("This is no JSON"), data->lf->log == NULL) - fail(); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Cannot parse JSON: This is no JSON"); - - DispatchDBSync(data->ctx, data->lf); -} - -static void test_DispatchDBSync_no_component(void **state) { - test_dbsync_t *data = *state; - cJSON *root = cJSON_Parse(data->lf->log); - - snprintf(data->lf->agent_id, OS_SIZE_16, "007"); - - data->ctx->db_sock = 65555; - - cJSON_DeleteItemFromObject(root, "component"); - - free(data->lf->log); - data->lf->log = cJSON_PrintUnformatted(root); - - cJSON_Delete(root); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Corrupt message: cannot get component member."); - - DispatchDBSync(data->ctx, data->lf); -} - -static void test_DispatchDBSync_no_type(void **state) { - test_dbsync_t *data = *state; - cJSON *root = cJSON_Parse(data->lf->log); - - snprintf(data->lf->agent_id, OS_SIZE_16, "007"); - - data->ctx->db_sock = 65555; - - cJSON_DeleteItemFromObject(root, "type"); - - free(data->lf->log); - data->lf->log = cJSON_PrintUnformatted(root); - - cJSON_Delete(root); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Corrupt message: cannot get type member."); - - DispatchDBSync(data->ctx, data->lf); -} - -static void test_DispatchDBSync_invalid_message_type(void **state) { - test_dbsync_t *data = *state; - cJSON *root = cJSON_Parse(data->lf->log); - - snprintf(data->lf->agent_id, OS_SIZE_16, "007"); - - data->ctx->db_sock = 65555; - - cJSON_DeleteItemFromObject(root, "type"); - cJSON_AddStringToObject(root, "type", "invalid"); - - free(data->lf->log); - data->lf->log = cJSON_PrintUnformatted(root); - - cJSON_Delete(root); - - expect_string(__wrap__merror, formatted_msg, "dbsync: Wrong message type 'invalid' received from agent 007."); - - DispatchDBSync(data->ctx, data->lf); -} - -static void test_DispatchDBSync_null_ctx(void **state) { - test_dbsync_t *data = *state; - - expect_assert_failure(DispatchDBSync(NULL, data->lf)); -} - -static void test_DispatchDBSync_null_lf(void **state) { - test_dbsync_t *data = *state; - - expect_assert_failure(DispatchDBSync(data->ctx, NULL)); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - /* dispatch_send_local */ - cmocka_unit_test_setup_teardown(test_dispatch_send_local_success, setup_send_local, teardown_dispatch_send_local), - cmocka_unit_test_setup_teardown(test_dispatch_send_local_success_syscollector, setup_send_local, teardown_dispatch_send_local), - cmocka_unit_test_setup_teardown(test_dispatch_send_local_socket_connect_error, setup_send_local, teardown_dispatch_send_local), - cmocka_unit_test_setup_teardown(test_dispatch_send_local_wrong_component, setup_send_local, teardown_dispatch_send_local), - cmocka_unit_test_setup_teardown(test_dispatch_send_local_null_component, setup_send_local, teardown_dispatch_send_local), - - /* dispatch_send_remote */ - cmocka_unit_test_setup_teardown(test_dispatch_send_remote_success, setup_dispatch_send_remote, teardown_dispatch_send_remote), - cmocka_unit_test_setup_teardown(test_dispatch_send_remote_not_connected_success, setup_dispatch_send_remote, teardown_dispatch_send_remote), - cmocka_unit_test_setup_teardown(test_dispatch_send_remote_not_connected_error, setup_dispatch_send_remote, teardown_dispatch_send_remote), - cmocka_unit_test_setup_teardown(test_dispatch_send_remote_retry, setup_dispatch_send_remote, teardown_dispatch_send_remote), - cmocka_unit_test_setup_teardown(test_dispatch_send_remote_retry_3_times, setup_dispatch_send_remote, teardown_dispatch_send_remote), - - /* dispatch_answer */ - cmocka_unit_test_setup_teardown(test_dispatch_answer_local_success, setup_dispatch_answer, teardown_dispatch_answer), - cmocka_unit_test_setup_teardown(test_dispatch_answer_remote_success, setup_dispatch_answer, teardown_dispatch_answer), - cmocka_unit_test_setup_teardown(test_dispatch_answer_query_too_long, setup_dispatch_answer, teardown_dispatch_answer), - - /* dispatch_check */ - cmocka_unit_test_setup_teardown(test_dispatch_check_success, setup_dispatch_check, teardown_dispatch_check), - cmocka_unit_test_setup_teardown(test_dispatch_check_corrupt_message, setup_dispatch_check, teardown_dispatch_check), - cmocka_unit_test_setup_teardown(test_dispatch_check_query_too_long, setup_dispatch_check, teardown_dispatch_check), - cmocka_unit_test_setup_teardown(test_dispatch_check_unable_to_communicate_with_db, setup_dispatch_check, teardown_dispatch_check), - cmocka_unit_test_setup_teardown(test_dispatch_check_no_response_from_db, setup_dispatch_check, teardown_dispatch_check), - cmocka_unit_test_setup_teardown(test_dispatch_check_error_parsing_response, setup_dispatch_check, teardown_dispatch_check), - - /* dispatch_state */ - cmocka_unit_test_setup_teardown(test_dispatch_state_success, setup_dispatch_state, teardown_dispatch_state), - cmocka_unit_test_setup_teardown(test_dispatch_state_corrupted_message, setup_dispatch_state, teardown_dispatch_state), - cmocka_unit_test_setup_teardown(test_dispatch_state_query_too_long, setup_dispatch_state, teardown_dispatch_state), - cmocka_unit_test_setup_teardown(test_dispatch_state_unable_to_communicate_with_db, setup_dispatch_state, teardown_dispatch_state), - cmocka_unit_test_setup_teardown(test_dispatch_state_no_response_from_db, setup_dispatch_state, teardown_dispatch_state), - cmocka_unit_test_setup_teardown(test_dispatch_state_error_parsing_response, setup_dispatch_state, teardown_dispatch_state), - - /* dispatch_clear */ - cmocka_unit_test_setup_teardown(test_dispatch_clear_success, setup_dispatch_clear, teardown_dispatch_clear), - cmocka_unit_test_setup_teardown(test_dispatch_clear_corrupted_message, setup_dispatch_clear, teardown_dispatch_clear), - cmocka_unit_test_setup_teardown(test_dispatch_clear_query_too_long, setup_dispatch_clear, teardown_dispatch_clear), - cmocka_unit_test_setup_teardown(test_dispatch_clear_unable_to_communicate_with_db, setup_dispatch_clear, teardown_dispatch_clear), - cmocka_unit_test_setup_teardown(test_dispatch_clear_no_response_from_db, setup_dispatch_clear, teardown_dispatch_clear), - cmocka_unit_test_setup_teardown(test_dispatch_clear_error_parsing_response, setup_dispatch_clear, teardown_dispatch_clear), - - /* DispatchDBSync */ - cmocka_unit_test_setup_teardown(test_DispatchDBSync_integrity_check_success, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_state_success, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_integrity_clear_success, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_invalid_log, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_no_component, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_no_type, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_invalid_message_type, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_null_ctx, setup_DispatchDBSync, teardown_DispatchDBSync), - cmocka_unit_test_setup_teardown(test_DispatchDBSync_null_lf, setup_DispatchDBSync, teardown_DispatchDBSync), - }; - - return cmocka_run_group_tests(tests, setup_dbsync_context, teardown_dbsync_context); -} diff --git a/src/unit_tests/analysisd/test_decode-xml.c b/src/unit_tests/analysisd/test_decode-xml.c deleted file mode 100644 index d4d3adef97a..00000000000 --- a/src/unit_tests/analysisd/test_decode-xml.c +++ /dev/null @@ -1,483 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../os_regex/os_regex.h" -#include "../os_xml/os_xml.h" -#include "../../analysisd/analysisd.h" -#include "../../analysisd/eventinfo.h" -#include "../../analysisd/decoders/decoder.h" -#include "../../analysisd/decoders/plugin_decoders.h" -#include "../../analysisd/config.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -void FreeDecoderInfo(OSDecoderInfo *pi); -char *_loadmemory(char *at, char *str, OSList* log_msg); -int addDecoder2list(const char *name, OSStore **decoder_store); -bool w_get_attr_regex_type(xml_node * node, w_exp_type_t * type); -int w_get_attr_offset(xml_node * node); - -/* setup/teardown */ - -/* wraps */ -void __wrap__os_analysisd_add_logmsg(OSList * list, int level, int line, const char * func, - const char * file, char * msg, ...) { - char formatted_msg[OS_MAXSTR]; - va_list args; - - va_start(args, msg); - vsnprintf(formatted_msg, OS_MAXSTR, msg, args); - va_end(args); - - check_expected(level); - check_expected_ptr(list); - check_expected(formatted_msg); -} - -OSStore * __wrap_OSStore_Create() { - return mock_type(OSStore *); -} - -int __wrap_OSStore_Put(OSStore *list, const char *key, void *data) { - return mock_type(int); -} - - -/* tests */ - -/* FreeDecoderInfo */ -void test_FreeDecoderInfo_NULL(void **state) -{ - OSDecoderInfo *info = NULL; - - FreeDecoderInfo(info); - -} - -void test_FreeDecoderInfo_OK(void **state) -{ - OSDecoderInfo *info; - os_calloc(1, sizeof(OSDecoderInfo), info); - - os_calloc(1, sizeof(char), info->parent); - os_calloc(1, sizeof(char), info->name); - os_calloc(1, sizeof(char), info->ftscomment); - os_calloc(1, sizeof(char), info->fts_fields); - os_calloc(1, sizeof(char*), info->fields); - os_calloc(1, sizeof(char), info->fields[0]); - - w_calloc_expression_t(&info->regex, EXP_TYPE_OSREGEX); - w_calloc_expression_t(&info->prematch, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&info->program_name, EXP_TYPE_OSREGEX); - - os_calloc(1, sizeof(void*), info->order); - - Config.decoder_order_size = 1; - - FreeDecoderInfo(info); - -} - -// _loadmemory -void test__loadmemory_null_append_ok(void ** state) -{ - char * at = NULL; - char * str; - - const size_t len = 1000; - char * expect_retval; - char * retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - os_calloc(len, sizeof(char), expect_retval); - memset(expect_retval, (int) '-', len - 1); - expect_retval[len-1] = '\0'; - - retval = _loadmemory(at,str, NULL); - - assert_string_equal(retval, expect_retval); - - os_free(str); - os_free(retval); - os_free(expect_retval); - -} - -void test__loadmemory_null_append_oversize(void ** state) -{ - char * at = NULL; - char * str; - OSList list_msg = {0}; - - const size_t len = 1025; - char * retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - char expect_msg[OS_SIZE_4096]; - - snprintf(expect_msg, OS_SIZE_4096, "(1104): Maximum string size reached for: %s.", str); - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, expect_msg); - - retval = _loadmemory(at,str, &list_msg); - - assert_null(retval); - - os_free(str); - -} - -void test__loadmemory_append_oversize(void ** state) -{ - char * at = NULL; - char * str = NULL; - OSList list_msg = {0}; - - const size_t len = 513; - char * retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - os_calloc(len, sizeof(char), at); - memset(at, (int) '+', len - 1); - str[len-1] = '\0'; - - char expect_msg[OS_SIZE_4096]; - - snprintf(expect_msg, OS_SIZE_4096, "(1104): Maximum string size reached for: %s.", str); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, expect_msg); - - retval = _loadmemory(at,str, &list_msg); - - assert_null(retval); - - os_free(str); - os_free(at); - -} -void test__loadmemory_append_ok(void ** state) -{ - char * at = NULL; - char * str = NULL; - OSList list_msg = {0}; - - const size_t len = 512; - char * retval; - char * expect_retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - os_calloc(len, sizeof(char), at); - memset(at, (int) '+', len - 1); - at[len-1] = '\0'; - - os_calloc(len * 2, sizeof(char), expect_retval); - strncat(expect_retval, at, len * 2); - strncat(expect_retval, str, len * 2); - - retval = _loadmemory(at,str, &list_msg); - - assert_non_null(retval); - assert_string_equal(retval, expect_retval); - - os_free(str); - os_free(retval); - os_free(expect_retval); - -} - -// addDecoder2list -void test_addDecoder2list_empty_list_deco_error(void ** state) -{ - const char * name = "test name"; - OSStore * decoder_store = NULL; - int expect_retval = 0; - int retval; - - will_return(__wrap_OSStore_Create, NULL); - expect_string(__wrap__merror, formatted_msg, "(1290): Unable to create a new list (calloc)."); - - retval = addDecoder2list(name, &decoder_store); - - assert_int_equal(retval, expect_retval); - -} - -void test_addDecoder2list_empty_list_deco_ok(void ** state) -{ - const char * name = "test name"; - OSStore * decoder_store = NULL; - int expect_retval = 1; - int retval; - - will_return(__wrap_OSStore_Create, (OSStore *) 1); - will_return(__wrap_OSStore_Put, 1); - - retval = addDecoder2list(name, &decoder_store); - - assert_int_equal(retval, expect_retval); -} - -void test_addDecoder2list_fail_push(void ** state) -{ - const char * name = "test name"; - OSStore * decoder_store = NULL; - int expect_retval = 0; - int retval; - os_calloc(1, sizeof(OSStore), decoder_store); - - will_return(__wrap_OSStore_Put, 0); - expect_string(__wrap__merror, formatted_msg, "(1291): Error adding nodes to list."); - - retval = addDecoder2list(name, &decoder_store); - - assert_int_equal(retval, expect_retval); - os_free(decoder_store); -} - -void test_addDecoder2list_push_ok(void ** state) -{ - const char * name = "test name"; - OSStore * decoder_store = NULL; - int expect_retval = 1; - int retval; - os_calloc(1, sizeof(OSStore), decoder_store); - - will_return(__wrap_OSStore_Put, 1); - - retval = addDecoder2list(name, &decoder_store); - - assert_int_equal(retval, expect_retval); - os_free(decoder_store); -} - -void w_get_attr_regex_type_not_found(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "attr_name_2", NULL}; - char * values[] = {"attr_val_1", "attr_val_2", NULL}; - node.attributes = attributes; - node.values = values; - - w_exp_type_t type = -2; - - bool retval; - - retval = w_get_attr_regex_type(&node, &type); - - assert_false(retval); - assert_int_equal(type, -2); -} - -void w_get_attr_regex_type_osregex(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "type", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "osregex", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - w_exp_type_t type = -2; - - bool retval; - - retval = w_get_attr_regex_type(&node, &type); - - assert_true(retval); - assert_int_equal(type, EXP_TYPE_OSREGEX); -} - -void w_get_attr_regex_type_osmatch(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "type", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "osmatch", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - w_exp_type_t type = -2; - - bool retval; - - retval = w_get_attr_regex_type(&node, &type); - - assert_true(retval); - assert_int_equal(type, EXP_TYPE_OSMATCH); -} - -void w_get_attr_regex_type_pcre2(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "type", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "PCRE2", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - w_exp_type_t type = -2; - - bool retval; - - retval = w_get_attr_regex_type(&node, &type); - - assert_true(retval); - assert_int_equal(type, EXP_TYPE_PCRE2); -} - -void w_get_attr_regex_type_invalid(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "type", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "invalid type", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - w_exp_type_t type = -2; - - bool retval; - - retval = w_get_attr_regex_type(&node, &type); - - assert_true(retval); - assert_int_equal(type, EXP_TYPE_INVALID); -} - -// w_get_attr_offset - -void w_get_attr_offset_not_found(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "attr_name_2", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "attr_val_2", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - int retval; - - retval = w_get_attr_offset(&node); - - assert_int_equal(retval, 0); -} - -void w_get_attr_offset_after_parent(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "offset", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "after_parent", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - int retval; - - retval = w_get_attr_offset(&node); - - assert_int_equal(retval, AFTER_PARENT); -} - -void w_get_attr_offset_after_prematch(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "offset", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "after_prematch", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - int retval; - - retval = w_get_attr_offset(&node); - - assert_int_equal(retval, AFTER_PREMATCH); -} -void w_get_attr_offset_after_after_regex(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "offset", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "after_regex", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - int retval; - - retval = w_get_attr_offset(&node); - - assert_int_equal(retval, AFTER_PREVREGEX); -} - -void w_get_attr_offset_error(void ** state) { - - xml_node node = {0}; - char * attributes[] = {"attr_name_1", "offset", "attr_name_3", NULL}; - char * values[] = {"attr_val_1", "bad_value", "attr_val_3", NULL}; - node.attributes = attributes; - node.values = values; - - int retval; - - retval = w_get_attr_offset(&node); - - assert_int_equal(retval, AFTER_ERROR); -} - -int main(void) { - const struct CMUnitTest tests[] = { - - // Tests FreeDecoderInfo - cmocka_unit_test(test_FreeDecoderInfo_NULL), - cmocka_unit_test(test_FreeDecoderInfo_OK), - - // Tests _loadmemory - cmocka_unit_test(test__loadmemory_null_append_ok), - cmocka_unit_test(test__loadmemory_null_append_oversize), - cmocka_unit_test(test__loadmemory_append_oversize), - cmocka_unit_test(test__loadmemory_append_ok), - - // Tests addDecoder2list - cmocka_unit_test(test_addDecoder2list_empty_list_deco_error), - cmocka_unit_test(test_addDecoder2list_empty_list_deco_ok), - cmocka_unit_test(test_addDecoder2list_fail_push), - cmocka_unit_test(test_addDecoder2list_push_ok), - - // Test w_get_attr_regex_type - cmocka_unit_test(w_get_attr_regex_type_not_found), - cmocka_unit_test(w_get_attr_regex_type_osregex), - cmocka_unit_test(w_get_attr_regex_type_osmatch), - cmocka_unit_test(w_get_attr_regex_type_pcre2), - cmocka_unit_test(w_get_attr_regex_type_invalid), - - // w_get_attr_offset - cmocka_unit_test(w_get_attr_offset_not_found), - cmocka_unit_test(w_get_attr_offset_after_parent), - cmocka_unit_test(w_get_attr_offset_after_prematch), - cmocka_unit_test(w_get_attr_offset_after_after_regex), - cmocka_unit_test(w_get_attr_offset_error), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_decoder_list.c b/src/unit_tests/analysisd/test_decoder_list.c deleted file mode 100644 index 7b56298b36d..00000000000 --- a/src/unit_tests/analysisd/test_decoder_list.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../headers/debug_op.h" -#include "../../analysisd/decoders/decoder.h" -#include "../error_messages/error_messages.h" -#include "../error_messages/debug_messages.h" -#include "../../analysisd/analysisd.h" - -void os_remove_decoders_list(OSDecoderNode *decoderlist_pn, OSDecoderNode *decoderlist_npn); -void os_remove_decodernode(OSDecoderNode *node, OSDecoderInfo **decoders, int *pos, int *max_size); -void os_count_decoders(OSDecoderNode *node, int *num_decoders); - -/* setup/teardown */ - - - -/* wraps */ - -void __wrap_FreeDecoderInfo(OSDecoderInfo *pi) { - os_free(pi); - return; -} - -/* tests */ - -/* os_remove_decoders_list */ -void os_count_decoders_no_child(void **state) -{ - OSDecoderNode * node; - os_calloc(1, sizeof(OSDecoderNode), node); - - int num_decoders = 0; - - os_count_decoders(node, &num_decoders); - - os_free(node); - -} - -void os_count_decoders_child(void **state) -{ - OSDecoderNode * node; - os_calloc(1, sizeof(OSDecoderNode), node); - os_calloc(1, sizeof(OSDecoderNode), node->child); - - int num_decoders = 0; - - os_count_decoders(node, &num_decoders); - - os_free(node->child); - os_free(node); - -} - -/* os_remove_decodernode */ -void test_os_remove_decodernode_no_child(void **state) -{ - int pos = 0; - int max_size = 2; - - OSDecoderNode * node; - os_calloc(1, sizeof(OSDecoderNode), node); - os_calloc(1, sizeof(OSDecoderInfo), node->osdecoder); - node->osdecoder->internal_saving = false; - - OSDecoderInfo **decoders; - os_calloc(1, sizeof(OSDecoderInfo *), decoders); - - int num_decoders = 0; - - os_remove_decodernode(node, decoders, &pos, &max_size); - - os_free(decoders[0]); - os_free(decoders); - -} - -void test_os_remove_decodernode_child(void **state) -{ - int pos = 0; - int max_size = 2; - - OSDecoderNode * node; - os_calloc(1, sizeof(OSDecoderNode), node); - os_calloc(1, sizeof(OSDecoderNode), node->child); - os_calloc(1, sizeof(OSDecoderInfo), node->osdecoder); - os_calloc(1, sizeof(OSDecoderInfo), node->child->osdecoder); - node->osdecoder->internal_saving = false; - node->child->osdecoder->internal_saving = false; - - OSDecoderInfo **decoders; - os_calloc(2, sizeof(OSDecoderInfo *), decoders); - - int num_decoders = 0; - - os_remove_decodernode(node, decoders, &pos, &max_size); - - os_free(decoders[0]); - os_free(decoders[1]); - os_free(decoders); - -} - -/* os_remove_decoders_list */ -void test_os_remove_decoders_list_OK(void **state) -{ - OSDecoderNode * decoderlist_pn; - os_calloc(1, sizeof(OSDecoderNode), decoderlist_pn); - os_calloc(1, sizeof(OSDecoderNode), decoderlist_pn->child); - os_calloc(1, sizeof(OSDecoderInfo), decoderlist_pn->osdecoder); - os_calloc(1, sizeof(OSDecoderInfo), decoderlist_pn->child->osdecoder); - decoderlist_pn->osdecoder->internal_saving = false; - decoderlist_pn->child->osdecoder->internal_saving = false; - - - OSDecoderNode * decoderlist_npn; - os_calloc(1, sizeof(OSDecoderNode), decoderlist_npn); - os_calloc(1, sizeof(OSDecoderNode), decoderlist_npn->child); - os_calloc(1, sizeof(OSDecoderInfo), decoderlist_npn->osdecoder); - os_calloc(1, sizeof(OSDecoderInfo), decoderlist_npn->child->osdecoder); - decoderlist_npn->osdecoder->internal_saving = false; - decoderlist_npn->child->osdecoder->internal_saving = false; - - os_remove_decoders_list(decoderlist_pn, decoderlist_npn); - -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests os_count_decoders_no_child - cmocka_unit_test(os_count_decoders_no_child), - cmocka_unit_test(os_count_decoders_child), - // Tests os_remove_decodernode - cmocka_unit_test(test_os_remove_decodernode_no_child), - cmocka_unit_test(test_os_remove_decodernode_child), - // Tests os_remove_decoders_list - cmocka_unit_test(test_os_remove_decoders_list_OK) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_decoder_rootcheck.c b/src/unit_tests/analysisd/test_decoder_rootcheck.c deleted file mode 100644 index 5a66e763bd4..00000000000 --- a/src/unit_tests/analysisd/test_decoder_rootcheck.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ -#include -#include -#include -#include -#include - -#include "../../config/global-config.h" -#include "../../analysisd/eventinfo.h" -#include "../../wazuh_db/wdb.h" -#include "../wrappers/wazuh/shared/rootcheck_op_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -#define TEST_AGENT_ID "005" -#define TEST_TIME 10005 -#define TEST_LOG_STRING "Test log string File 'file_name'" - -extern int DecodeRootcheck(Eventinfo *lf); -extern void w_free_event_info(Eventinfo *lf); -extern _Config Config; -/* setup / teardown */ -int test_setup_global(void **state) { - expect_string(__wrap__mdebug1, formatted_msg, "RootcheckInit completed."); - Config.decoder_order_size = 32; - RootcheckInit(); - return 0; -} - -int test_setup(void **state) { - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - os_strdup(TEST_AGENT_ID, lf->agent_id); - os_strdup(TEST_LOG_STRING, lf->log); - lf->time.tv_sec = (time_t) TEST_TIME; - *state = lf; - return 0; -} - -int test_cleanup(void **state) { - Eventinfo *lf = *state; - os_free(lf->log); - w_free_event_info(lf); - return 0; -} - -/* tests */ - -void test_rootcheck_db_failure(void **state) { - Eventinfo *lf = *state; - expect_string(__wrap_send_rootcheck_log, agent_id, TEST_AGENT_ID); - expect_value(__wrap_send_rootcheck_log, date, TEST_TIME); - expect_string(__wrap_send_rootcheck_log, log, TEST_LOG_STRING); - will_return(__wrap_send_rootcheck_log, "ERROR String"); - will_return(__wrap_send_rootcheck_log, -2); - - expect_string(__wrap__merror, formatted_msg, "Rootcheck decoder unexpected result: 'ERROR String'"); - - int ret = DecodeRootcheck(lf); - assert_int_equal(ret, 0); -} - -void test_rootcheck_success(void **state) { - Eventinfo *lf = *state; - expect_string(__wrap_send_rootcheck_log, agent_id, TEST_AGENT_ID); - expect_value(__wrap_send_rootcheck_log, date, TEST_TIME); - expect_string(__wrap_send_rootcheck_log, log, TEST_LOG_STRING); - will_return(__wrap_send_rootcheck_log, "ok 2"); - will_return(__wrap_send_rootcheck_log, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Rootcheck decoder response: 'ok 2'"); - - int ret = DecodeRootcheck(lf); - assert_int_equal(ret, 1); - assert_string_equal(lf->fields[RK_FILE].value, "file_name"); - assert_string_equal(lf->fields[RK_TITLE].value, TEST_LOG_STRING); - assert_int_equal(lf->rootcheck_fts, FTS_DONE); -} - - -int main() { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_rootcheck_db_failure, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_rootcheck_success, test_setup, test_cleanup), - }; - return cmocka_run_group_tests(tests, test_setup_global, NULL); -} diff --git a/src/unit_tests/analysisd/test_decoder_syscollector.c b/src/unit_tests/analysisd/test_decoder_syscollector.c deleted file mode 100644 index e593f939810..00000000000 --- a/src/unit_tests/analysisd/test_decoder_syscollector.c +++ /dev/null @@ -1,3842 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ -#include -#include -#include -#include -#include - -#include "../../config/global-config.h" -#include "../../analysisd/eventinfo.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - -#include "../headers/wazuhdb_op.h" - -extern int DecodeSyscollector(Eventinfo *lf, int *socket); -extern _Config Config; - -/* setup / teardown */ -int test_setup_global(void **state) -{ - expect_string(__wrap__mdebug1, formatted_msg, "SyscollectorInit completed."); - Config.decoder_order_size = 32; - SyscollectorInit(); - return 0; -} - -int test_setup_invalid_location(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - os_strdup("{'type'='dbsync_processes'}", lf->log); - os_strdup("s>syscollector", lf->location); - *state = lf; - return 0; -} - -int test_setup_invalid_json(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - os_strdup("_INVALIDJSON_", lf->log); - os_strdup("(>syscollector", lf->location); - *state = lf; - return 0; -} - -int test_setup_invalid_msgtype(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - const char *plain_event = "{\"type\":\"_dbsync_processes\"}"; - - if (lf->log = strdup(plain_event), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - *state = lf; - return 0; -} - -int test_setup_valid_msg_unknown_operation(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("{\"type\":\"dbsync_processes\"}"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_valid_msg_null_agentid(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("{\"type\":\"dbsync_processes\"}"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - - *state = lf; - return 0; -} - -int test_setup_valid_msg_invalid_field_list(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_nothing\",\ - \"operation\":\"invalid\",\ - \"data\":{}\ - }"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_valid_msg_with_no_type(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_\",\ - \"operation\":\"invalid\",\ - \"data\":{}\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hotfixes_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_hotfixes\",\ - \"operation\":\"MODIFIED\",\ - \"data\":\ - {\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"hotfix\":\"KB123456\",\ - \"checksum\":\"abcdef0123456789\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} -int test_setup_packages_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_packages\", \ - \"operation\":\"MODIFIED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"format\" : \"1\",\ - \"name\" : \"2\",\ - \"priority\" : \"3\",\ - \"groups\" : \"4\",\ - \"size\" : \"5\",\ - \"vendor\" : \"6\",\ - \"install_time\" : \"7\",\ - \"version\" : \"8\",\ - \"architecture\" : \"9\",\ - \"multiarch\" : \"10\",\ - \"source\" : \"11\",\ - \"description\" : \"12\",\ - \"location\" : \"13\",\ - \"checksum\" : \"17\",\ - \"item_id\" : \"18\"\ - }\ - }"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - - -int test_setup_processes_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_processes\",\ - \"operation\":\"MODIFIED\",\ - \"data\":{ \ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"pid\" : \"18\",\ - \"name\" : \"19\",\ - \"state\" : \"20\",\ - \"ppid\" : \"21\",\ - \"utime\" : \"22\",\ - \"stime\" : \"23\",\ - \"cmd\" : \"24\",\ - \"argvs\" : \"25\",\ - \"euser\" : \"26\",\ - \"ruser\" : \"27\",\ - \"suser\" : \"28\",\ - \"egroup\" : \"29\",\ - \"rgroup\" : \"30\",\ - \"sgroup\" : \"31\",\ - \"fgroup\" : \"32\",\ - \"priority\" : \"33\",\ - \"nice\" : \"34\",\ - \"size\" : \"35\",\ - \"vm_size\" : \"36\",\ - \"resident\" : \"37\",\ - \"share\" : \"38\",\ - \"start_time\" : \"39\",\ - \"pgrp\" : \"40\",\ - \"session\" : \"41\",\ - \"nlwp\" : \"42\",\ - \"tgid\" : \"43\",\ - \"tty\" : \"44\",\ - \"processor\" : \"45\",\ - \"checksum\" : \"46\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_ports_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_ports\",\ - \"operation\":\"MODIFIED\",\ - \"data\":\ - {\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"protocol\" : \"47\",\ - \"local_ip\" : \"48\",\ - \"local_port\" : \"49\",\ - \"remote_ip\" : \"50\",\ - \"remote_port\" : \"51\",\ - \"tx_queue\" : \"52\",\ - \"rx_queue\" : \"53\",\ - \"inode\" : \"54\",\ - \"state\" : \"55\",\ - \"pid\" : \"56\",\ - \"process\" : \"57\",\ - \"checksum\" : \"58\",\ - \"item_id\" : \"59\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_iface_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_network_iface\",\ - \"operation\":\"MODIFIED\",\ - \"data\":\ - {\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"name\" : \"59\",\ - \"adapter\" : \"60\",\ - \"type\" : \"61\",\ - \"state\" : \"62\",\ - \"mtu\" : \"63\",\ - \"mac\" : \"64\",\ - \"tx_packets\" : \"65\",\ - \"rx_packets\" : \"66\",\ - \"tx_bytes\" : \"67\",\ - \"rx_bytes\" : \"68\",\ - \"tx_errors\" : \"69\",\ - \"rx_errors\" : \"70\",\ - \"tx_dropped\" : \"71\",\ - \"rx_dropped\" : \"72\",\ - \"checksum\" : \"73\",\ - \"item_id\" : \"74\"\ - }\ - }"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_protocol_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_network_protocol\", \ - \"operation\":\"MODIFIED\",\ - \"data\":{ \ - \"iface\" : \"74\",\ - \"type\" : \"75\",\ - \"gateway\" : \"76\",\ - \"dhcp\" : \"77\",\ - \"metric\" : \"78\",\ - \"checksum\" : \"79\",\ - \"item_id\" : \"80\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_address_invalid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_network_address\",\ - \"operation\":\"MODIFIED\",\ - \"data\":{\ - \"iface\" : \"80\",\ - \"proto\" : \"81\",\ - \"address\" : \"82\",\ - \"netmask\" : \"83\",\ - \"broadcast\" : \"84\",\ - \"checksum\" : \"85\",\ - \"item_id\" : \"86\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_address_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_network_address\",\ - \"operation\":\"MODIFIED\",\ - \"data\":{\ - \"iface\" : \"80\",\ - \"proto\" : 0,\ - \"address\" : \"82\",\ - \"netmask\" : \"83\",\ - \"broadcast\" : \"84\",\ - \"checksum\" : \"85\",\ - \"item_id\" : \"86\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hardware_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_hwinfo\",\ - \"operation\":\"MODIFIED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"board_serial\" : \"86\",\ - \"cpu_name\" : \"87\",\ - \"cpu_cores\" : 88,\ - \"cpu_MHz\" : 89.9,\ - \"ram_total\" : 90,\ - \"ram_free\" : 91,\ - \"ram_usage\" : 92,\ - \"checksum\" : \"93\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_os_valid_msg_modified(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_osinfo\",\ - \"operation\":\"MODIFIED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"hostname\" : \"93\",\ - \"architecture\" : \"94\",\ - \"os_name\" : \"95\",\ - \"os_version\" : \"96\",\ - \"os_codename\" : \"97\",\ - \"os_major\" : \"98\",\ - \"os_minor\" : \"99\",\ - \"os_patch\" : \"100\",\ - \"os_build\" : \"101\",\ - \"os_platform\" : \"102\",\ - \"sysname\" : \"103\",\ - \"release\" : \"104\",\ - \"version\" : \"105\",\ - \"os_release\" : \"106\",\ - \"checksum\" : \"107\",\ - \"os_display_version\" : \"108\",\ - \"reference\" : \"110\"\ - }\ - }"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hotfixes_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_hotfixes\",\ - \"operation\":\"INSERTED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"hotfix\":\"KB123456\",\ - \"checksum\":\"abcdef0123456789\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_packages_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_packages\", \ - \"operation\":\"INSERTED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"format\" : \"1\",\ - \"name\" : \"2\",\ - \"priority\" : \"3\",\ - \"groups\" : \"4\",\ - \"size\" : \"5\",\ - \"vendor\" : \"6\",\ - \"install_time\" : \"7\",\ - \"version\" : \"8\",\ - \"architecture\" : \"9\",\ - \"multiarch\" : \"10\",\ - \"source\" : \"11\",\ - \"description\" : \"12\",\ - \"location\" : \"13\",\ - \"checksum\" : \"17\",\ - \"item_id\" : \"18\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - - -int test_setup_processes_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_processes\",\ - \"operation\":\"INSERTED\",\ - \"data\":{ \ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"pid\" : \"18\",\ - \"name\" : \"19\",\ - \"state\" : \"20\",\ - \"ppid\" : \"21\",\ - \"utime\" : \"22\",\ - \"stime\" : \"23\",\ - \"cmd\" : \"24\",\ - \"argvs\" : \"25\",\ - \"euser\" : \"26\",\ - \"ruser\" : \"27\",\ - \"suser\" : \"28\",\ - \"egroup\" : \"29\",\ - \"rgroup\" : \"30\",\ - \"sgroup\" : \"31\",\ - \"fgroup\" : \"32\",\ - \"priority\" : \"33\",\ - \"nice\" : \"34\",\ - \"size\" : \"35\",\ - \"vm_size\" : \"36\",\ - \"resident\" : \"37\",\ - \"share\" : \"38\",\ - \"start_time\" : \"39\",\ - \"pgrp\" : \"40\",\ - \"session\" : \"41\",\ - \"nlwp\" : \"42\",\ - \"tgid\" : \"43\",\ - \"tty\" : \"44\",\ - \"processor\" : \"45\",\ - \"checksum\" : \"46\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_ports_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_ports\",\ - \"operation\":\"INSERTED\",\ - \"data\":{ \ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"protocol\" : \"47\",\ - \"local_ip\" : \"48\",\ - \"local_port\" : \"49\",\ - \"remote_ip\" : \"50\",\ - \"remote_port\" : \"51\",\ - \"tx_queue\" : \"52\",\ - \"rx_queue\" : \"53\",\ - \"inode\" : \"54\",\ - \"state\" : \"55\",\ - \"pid\" : \"56\",\ - \"process\" : \"57\",\ - \"checksum\" : \"58\",\ - \"item_id\" : \"59\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_iface_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_network_iface\",\ - \"operation\":\"INSERTED\",\ - \"data\":{ \ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"name\" : \"59\",\ - \"adapter\" : \"60\",\ - \"type\" : \"61\",\ - \"state\" : \"62\",\ - \"mtu\" : \"63\",\ - \"mac\" : \"64\",\ - \"tx_packets\" : \"65\",\ - \"rx_packets\" : \"66\",\ - \"tx_bytes\" : \"67\",\ - \"rx_bytes\" : \"68\",\ - \"tx_errors\" : \"69\",\ - \"rx_errors\" : \"70\",\ - \"tx_dropped\" : \"71\",\ - \"rx_dropped\" : \"72\",\ - \"checksum\" : \"73\",\ - \"item_id\" : \"74\"\ - }\ - }"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_protocol_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_network_protocol\", \ - \"operation\":\"INSERTED\",\ - \"data\":{ \ - \"iface\" : \"74\",\ - \"type\" : \"75\",\ - \"gateway\" : \"76\",\ - \"dhcp\" : \"77\",\ - \"metric\" : \"78\",\ - \"checksum\" : \"79\",\ - \"item_id\" : \"80\"\ - }\ - }"), lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_address_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_network_address\",\ - \"operation\":\"INSERTED\",\ - \"data\":{\ - \"iface\" : \"80\",\ - \"proto\" : 1,\ - \"address\" : \"82\",\ - \"netmask\" : \"83\",\ - \"broadcast\" : \"84\",\ - \"checksum\" : \"85\",\ - \"item_id\" : \"86\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_network_address_invalid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_network_address\",\ - \"operation\":\"INSERTED\",\ - \"data\":{\ - \"iface\" : \"80\",\ - \"proto\" : \"81\",\ - \"address\" : \"82\",\ - \"netmask\" : \"83\",\ - \"broadcast\" : \"84\",\ - \"checksum\" : \"85\",\ - \"item_id\" : \"86\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hardware_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_hwinfo\",\ - \"operation\":\"INSERTED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"board_serial\" : \"86\",\ - \"cpu_name\" : \"87\",\ - \"cpu_cores\" : 88,\ - \"cpu_MHz\" : 89.9,\ - \"ram_total\" : 90,\ - \"ram_free\" : 91,\ - \"ram_usage\" : 92,\ - \"checksum\" : 93\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_os_valid_msg_inserted(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - { \ - \"type\":\"dbsync_osinfo\",\ - \"operation\":\"INSERTED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"hostname\" : \"93\",\ - \"architecture\" : \"94\",\ - \"os_name\" : \"95\",\ - \"os_version\" : \"96\",\ - \"os_codename\" : \"97\",\ - \"os_major\" : \"98\",\ - \"os_minor\" : \"99\",\ - \"os_patch\" : \"100\",\ - \"os_build\" : \"101\",\ - \"os_platform\" : \"102\",\ - \"sysname\" : \"103\",\ - \"release\" : \"104\",\ - \"version\" : \"105\",\ - \"os_release\" : \"106\",\ - \"checksum\" : \"107\",\ - \"os_display_version\" : \"108\",\ - \"reference\" : \"110\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_os_valid_msg_with_number_pk(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - // architecture will be a number PK - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_osinfo\",\ - \"operation\":\"MODIFIED\",\ - \"data\":{\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"hostname\" : \"93\",\ - \"architecture\" : 94,\ - \"os_name\" : \"95\",\ - \"os_version\" : \"96\",\ - \"os_codename\" : \"97\",\ - \"os_major\" : \"98\",\ - \"os_minor\" : \"99\",\ - \"os_patch\" : \"100\",\ - \"os_build\" : \"101\",\ - \"os_platform\" : \"102\",\ - \"sysname\" : \"103\",\ - \"release\" : \"104\",\ - \"version\" : \"105\",\ - \"os_release\" : \"106\",\ - \"checksum\" : \"107\",\ - \"os_display_version\" : \"108\",\ - \"reference\" : \"110\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_valid_msg_query_error(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_hotfixes\",\ - \"operation\":\"MODIFIED\",\ - \"data\":\ - {\ - \"hotfix\":\"KB123456\",\ - \"checksum\":\"abcdef0123456789\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_valid_msg_no_operation(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_hotfixes\",\ - \"data\":\ - {\ - \"hotfix\":\"KB123456\",\ - \"checksum\":\"abcdef0123456789\"\ - }}"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_valid_msg_empty_string(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_hwinfo\",\ - \"operation\":\"INSERTED\",\ - \"data\":\ - {\ - \"scan_time\":\"2021/10/29 14:26:24\",\ - \"board_serial\" : \"86\",\ - \"cpu_name\" : \"\",\ - \"cpu_cores\" : \"88\",\ - \"cpu_MHz\" : \"89\",\ - \"ram_total\" : \"90\",\ - \"ram_free\" : \"91\",\ - \"ram_usage\" : \"92\",\ - \"checksum\" : \"93\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_valid_msg_data_as_value(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"dbsync_hotfixes\",\ - \"operation\":\"INSERTED\",\ - \"data\":\"data\"\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_insert_multiple_null_field_valid_msg(void ** state) { - Eventinfo * lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"data\":\ - {\ - \"checksum\":\"944fb6182222660aeca5b27bcd14a579db60b58c\",\ - \"inode\":30905,\ - \"item_id\":\"31ec8d41b06cc6dea02d9f088067d379d761732d\",\ - \"local_ip\":\"192.168.100.90\",\ - \"local_port\":53462,\ - \"pid\":null,\ - \"process\":null,\ - \"protocol\":\"tcp\",\ - \"remote_ip\":null,\ - \"remote_port\":10000,\ - \"rx_queue\":null,\ - \"scan_time\":\"2021/11/01 17:38:40\",\ - \"state\":null,\ - \"tx_queue\":null\ - },\ - \"operation\":\"INSERTED\",\ - \"type\":\"dbsync_ports\"\ - }"), - lf->log == NULL) { - return -1; - } - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_deleted_multiple_null_field_valid_msg(void ** state) { - Eventinfo * lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"data\":\ - {\ - \"inode\":30905,\ - \"local_ip\":\"192.168.100.90\",\ - \"local_port\":53462,\ - \"protocol\":\"tcp\",\ - \"scan_time\":\"2021/11/01 17:40:48\"\ - },\ - \"operation\":\"DELETED\",\ - \"type\":\"dbsync_ports\"\ - }"), - lf->log == NULL) { - return -1; - } - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_cleanup(void **state) -{ - Eventinfo *lf = *state; - os_free(lf->log); - w_free_event_info(lf); - return 0; -} - -int test_setup_hardware_valid_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"hardware\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\",\ - \"inventory\":{\ - \"board_serial\" : \"86\",\ - \"cpu_name\" : \"87\",\ - \"cpu_cores\" : 88,\ - \"cpu_mhz\" : 89.9,\ - \"ram_total\" : 90,\ - \"ram_free\" : 91,\ - \"ram_usage\" : 92\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hardware_valid_msg_inventory_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"hardware\",\ - \"inventory\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hardware_valid_msg_without_inventory(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"hardware\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\"\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hotfix_valid_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"hotfix\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\",\ - \"hotfix\":\"hotfix-version-test\"\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hotfix_valid_hotfix_end_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"hotfix_end\",\ - \"ID\":100\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_hotfix_valid_msg_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"hotfix\"\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_netinfo_valid_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"network\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\",\ - \"iface\":{\ - \"name\" : \"86\",\ - \"adapter\" : \"87\",\ - \"type\" : \"88\",\ - \"state\" : \"89\",\ - \"MAC\" : \"90\",\ - \"tx_packets\" : 91,\ - \"rx_packets\" : 92,\ - \"tx_bytes\" : 93,\ - \"rx_bytes\" : 94,\ - \"tx_errors\" : 95,\ - \"rx_errors\" : 96,\ - \"tx_dropped\" : 97,\ - \"rx_dropped\" : 98,\ - \"MTU\" : 99,\ - \"IPv4\":{\ - \"address\" : [ \"0.0.0.0\", \"0.0.1.0\" ],\ - \"netmask\" : [ \"255.255.255.255\", \"255.255.255.254\" ],\ - \"broadcast\" : [ \"0.0.0.1\", \"0.0.1.1\" ],\ - \"gateway\" : \"0.0.0.2\",\ - \"dhcp\" : \"0.0.0.3\",\ - \"metric\" : 10\ - },\ - \"IPv6\":{\ - \"address\" : [ \"0000:0000:0000:0:0000:0000:0000:0000\",\ - \"0000:0000:0000:0:0000:0000:0001:0000\" ],\ - \"netmask\" : [ \"0000::\", \"0001::\" ],\ - \"broadcast\" : [ \"0000:0000:0000:0:0000:0000:0000:0001\",\ - \"0000:0000:0000:0:0000:0000:0001:0001\" ],\ - \"gateway\" : \"0000:0000:0000:0:0000:0000:0000:0002\",\ - \"dhcp\" : \"0000:0000:0000:0:0000:0000:0000:0003\",\ - \"metric\" : 10\ - }\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_netinfo_valid_msg_groups_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"network\",\ - \"iface\":{\ - \"IPv4\":{\ - },\ - \"IPv6\":{\ - }\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_netinfo_valid_msg_address_array_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"network\",\ - \"iface\":{\ - \"IPv4\":{\ - \"address\" : [ \"0.0.0.0\" ]\ - },\ - \"IPv6\":{\ - \"address\" : [ \"0000:0000:0000:0:0000:0000:0000:0000\" ]\ - }\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_netinfo_valid_msg_net_data_free(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"network\",\ - \"iface\":{\ - \"IPv4\":{\ - \"address\" : [ \"0.0.0.0\" ],\ - \"netmask\" : [ \"255.255.255.255\" ],\ - \"broadcast\" : [ \"0.0.0.1\" ]\ - },\ - \"IPv6\":{\ - \"address\" : [ \"0000:0000:0000:0:0000:0000:0000:0000\" ],\ - \"netmask\" : [ \"0000::\" ],\ - \"broadcast\" : [ \"0000:0000:0000:0:0000:0000:0000:0001\" ]\ - }\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_netinfo_valid_network_end_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"network_end\",\ - \"ID\":100\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_osinfo_valid_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"OS\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\",\ - \"inventory\":{\ - \"os_name\":\"name\",\ - \"os_version\":\"0.0.1\",\ - \"os_codename\":\"test\",\ - \"hostname\":\"host\",\ - \"architecture\":\"x86\",\ - \"os_major\":\"0\",\ - \"os_minor\":\"0\",\ - \"os_build\":\"1\",\ - \"os_platform\":\"platform\",\ - \"sysname\":\"sysname\",\ - \"release\":\"R1\",\ - \"version\":\"0.0.2\",\ - \"os_release\":\"R2\",\ - \"os_patch\":\"P1\",\ - \"os_display_version\":\"0.0.1-R2-P1\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_osinfo_valid_msg_inventory_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"OS\",\ - \"inventory\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_package_valid_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"program\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\",\ - \"program\":{\ - \"format\":\"format\",\ - \"name\":\"name\",\ - \"priority\":\"priority\",\ - \"group\":\"group\",\ - \"size\": 0,\ - \"vendor\":\"vendor\",\ - \"version\":\"version\",\ - \"architecture\":\"architecture\",\ - \"multi-arch\":\"multi-arch\",\ - \"source\":\"source\",\ - \"description\":\"description\",\ - \"install_time\":\"install_time\",\ - \"location\":\"location\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_package_valid_msg_program_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"program\",\ - \"ID\":100,\ - \"program\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_package_valid_msg_without_ID(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"program\",\ - \"program\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_package_valid_msg_program_end(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"program_end\",\ - \"ID\":100\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_port_valid_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"port\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\",\ - \"port\":{\ - \"protocol\":\"protocol\",\ - \"local_ip\":\"0.0.0.0\",\ - \"local_port\":10,\ - \"remote_ip\":\"0.0.0.1\",\ - \"remote_port\":11,\ - \"tx_queue\":12,\ - \"rx_queue\":13,\ - \"inode\":14,\ - \"state\":\"ok\",\ - \"PID\":15,\ - \"process\":\"process\"\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_port_valid_msg_port_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"port\",\ - \"ID\":100,\ - \"port\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_port_valid_msg_without_ID(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"port\",\ - \"port\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_port_valid_msg_port_end(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"port_end\",\ - \"ID\":100\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_process_valid_msg(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"process\",\ - \"ID\":100,\ - \"timestamp\":\"2021/10/29 14:26:24\",\ - \"process\":{\ - \"pid\":10,\ - \"name\":\"name\",\ - \"state\":\"state\",\ - \"ppid\":11,\ - \"utime\":12,\ - \"stime\":13,\ - \"cmd\":\"cmd\",\ - \"argvs\": [ \"arg\" ],\ - \"euser\":\"euser\",\ - \"ruser\":\"ruser\",\ - \"suser\":\"suser\",\ - \"egroup\":\"egroup\",\ - \"rgroup\":\"rgroup\",\ - \"sgroup\":\"sgroup\",\ - \"fgroup\":\"fgroup\",\ - \"priority\":14,\ - \"nice\":15,\ - \"size\":16,\ - \"vm_size\":17,\ - \"resident\":18,\ - \"share\":19,\ - \"start_time\":20,\ - \"pgrp\":21,\ - \"session\":22,\ - \"nlwp\":23,\ - \"tgid\":24,\ - \"tty\":25,\ - \"processor\":26\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_process_valid_msg_process_empty(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"process\",\ - \"ID\":100,\ - \"process\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_process_valid_msg_without_ID(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"process\",\ - \"process\":{\ - }\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -int test_setup_process_valid_msg_process_end(void **state) -{ - Eventinfo *lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - if (lf->log = strdup("\ - {\ - \"type\":\"process_end\",\ - \"ID\":100\ - }"), - lf->log == NULL) - return -1; - os_strdup("(>syscollector", lf->location); - os_strdup("001", lf->agent_id); - - *state = lf; - return 0; -} - -/* tests */ -void test_syscollector_dbsync_invalid_location(void **state) -{ - Eventinfo *lf = *state; - expect_string(__wrap__mdebug1, formatted_msg, "Invalid received event. (Location)"); - int ret = DecodeSyscollector(lf, 0); - - assert_int_equal(ret, 0); -} - -void test_syscollector_dbsync_invalid_json(void **state) -{ - Eventinfo *lf = *state; - expect_string(__wrap__mdebug1, formatted_msg, "Error parsing JSON event."); - expect_any(__wrap__mdebug2, formatted_msg); - - int ret = DecodeSyscollector(lf, 0); - - assert_int_equal(ret, 0); -} - -void test_syscollector_dbsync_invalid_msgtype(void **state) -{ - Eventinfo *lf = *state; - expect_string(__wrap__mdebug1, formatted_msg, "Invalid message type: _dbsync_processes."); - int ret = DecodeSyscollector(lf, 0); - - assert_int_equal(ret, 0); -} - -void test_syscollector_dbsync_valid_msg_unknown_operation(void **state) -{ - Eventinfo *lf = *state; - const char type[] = {"processes"}; - char error_log[128]; - sprintf(error_log, INVALID_OPERATION, type); - - expect_string(__wrap__merror, formatted_msg, error_log); - expect_string(__wrap__mdebug1, formatted_msg, UNABLE_TO_SEND_INFORMATION_TO_WDB); - int ret = DecodeSyscollector(lf, 0); - - assert_int_equal(ret, 0); -} - -void test_syscollector_dbsync_valid_msg_invalid_field_list(void **state) -{ - Eventinfo *lf = *state; - const char type[] = {"nothing"}; - char error_log[128]; - sprintf(error_log, INVALID_TYPE, type); - - expect_string(__wrap__merror, formatted_msg, error_log); - expect_string(__wrap__mdebug1, formatted_msg, UNABLE_TO_SEND_INFORMATION_TO_WDB); - int ret = DecodeSyscollector(lf, 0); - - assert_int_equal(ret, 0); -} - -void test_syscollector_dbsync_hotfixes_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync hotfixes MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"hotfix\":\"KB123456\"," - "\"checksum\":\"abcdef0123456789\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_packages_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync packages MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"format\":\"1\"," - "\"name\":\"2\"," - "\"priority\":\"3\"," - "\"groups\":\"4\"," - "\"size\":\"5\"," - "\"vendor\":\"6\"," - "\"install_time\":\"7\"," - "\"version\":\"8\"," - "\"architecture\":\"9\"," - "\"multiarch\":\"10\"," - "\"source\":\"11\"," - "\"description\":\"12\"," - "\"location\":\"13\"," - "\"checksum\":\"17\"," - "\"item_id\":\"18\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_processes_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync processes MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"pid\":\"18\"," - "\"name\":\"19\"," - "\"state\":\"20\"," - "\"ppid\":\"21\"," - "\"utime\":\"22\"," - "\"stime\":\"23\"," - "\"cmd\":\"24\"," - "\"argvs\":\"25\"," - "\"euser\":\"26\"," - "\"ruser\":\"27\"," - "\"suser\":\"28\"," - "\"egroup\":\"29\"," - "\"rgroup\":\"30\"," - "\"sgroup\":\"31\"," - "\"fgroup\":\"32\"," - "\"priority\":\"33\"," - "\"nice\":\"34\"," - "\"size\":\"35\"," - "\"vm_size\":\"36\"," - "\"resident\":\"37\"," - "\"share\":\"38\"," - "\"start_time\":\"39\"," - "\"pgrp\":\"40\"," - "\"session\":\"41\"," - "\"nlwp\":\"42\"," - "\"tgid\":\"43\"," - "\"tty\":\"44\"," - "\"processor\":\"45\"," - "\"checksum\":\"46\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_ports_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync ports MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"protocol\":\"47\"," - "\"local_ip\":\"48\"," - "\"local_port\":\"49\"," - "\"remote_ip\":\"50\"," - "\"remote_port\":\"51\"," - "\"tx_queue\":\"52\"," - "\"rx_queue\":\"53\"," - "\"inode\":\"54\"," - "\"state\":\"55\"," - "\"pid\":\"56\"," - "\"process\":\"57\"," - "\"checksum\":\"58\"," - "\"item_id\":\"59\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_iface_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_iface MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"name\":\"59\"," - "\"adapter\":\"60\"," - "\"type\":\"61\"," - "\"state\":\"62\"," - "\"mtu\":\"63\"," - "\"mac\":\"64\"," - "\"tx_packets\":\"65\"," - "\"rx_packets\":\"66\"," - "\"tx_bytes\":\"67\"," - "\"rx_bytes\":\"68\"," - "\"tx_errors\":\"69\"," - "\"rx_errors\":\"70\"," - "\"tx_dropped\":\"71\"," - "\"rx_dropped\":\"72\"," - "\"checksum\":\"73\"," - "\"item_id\":\"74\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_protocol_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_protocol MODIFIED " - "{" - "\"iface\":\"74\"," - "\"type\":\"75\"," - "\"gateway\":\"76\"," - "\"dhcp\":\"77\"," - "\"metric\":\"78\"," - "\"checksum\":\"79\"," - "\"item_id\":\"80\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_address_invalid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_address MODIFIED " - "{" - "\"iface\":\"80\"," - "\"proto\":\"81\"," - "\"address\":\"82\"," - "\"netmask\":\"83\"," - "\"broadcast\":\"84\"," - "\"checksum\":\"85\"," - "\"item_id\":\"86\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Field 'proto' cannot be obtained."); - expect_string(__wrap__mdebug2, formatted_msg, "Error while mapping 'proto' field value."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_address_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_address MODIFIED " - "{" - "\"iface\":\"80\"," - "\"proto\":\"ipv4\"," - "\"address\":\"82\"," - "\"netmask\":\"83\"," - "\"broadcast\":\"84\"," - "\"checksum\":\"85\"," - "\"item_id\":\"86\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_hardware_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync hwinfo MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"board_serial\":\"86\"," - "\"cpu_name\":\"87\"," - "\"cpu_cores\":88," - "\"cpu_MHz\":89.9," - "\"ram_total\":90," - "\"ram_free\":91," - "\"ram_usage\":92," - "\"checksum\":\"93\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_os_valid_msg_modified(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync osinfo MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"hostname\":\"93\"," - "\"architecture\":\"94\"," - "\"os_name\":\"95\"," - "\"os_version\":\"96\"," - "\"os_codename\":\"97\"," - "\"os_major\":\"98\"," - "\"os_minor\":\"99\"," - "\"os_patch\":\"100\"," - "\"os_build\":\"101\"," - "\"os_platform\":\"102\"," - "\"sysname\":\"103\"," - "\"release\":\"104\"," - "\"version\":\"105\"," - "\"os_release\":\"106\"," - "\"checksum\":\"107\"," - "\"os_display_version\":\"108\"," - "\"reference\":\"110\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_hotfixes_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync hotfixes INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"hotfix\":\"KB123456\"," - "\"checksum\":\"abcdef0123456789\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_packages_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync packages INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"format\":\"1\"," - "\"name\":\"2\"," - "\"priority\":\"3\"," - "\"groups\":\"4\"," - "\"size\":\"5\"," - "\"vendor\":\"6\"," - "\"install_time\":\"7\"," - "\"version\":\"8\"," - "\"architecture\":\"9\"," - "\"multiarch\":\"10\"," - "\"source\":\"11\"," - "\"description\":\"12\"," - "\"location\":\"13\"," - "\"checksum\":\"17\"," - "\"item_id\":\"18\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_processes_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync processes INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"pid\":\"18\"," - "\"name\":\"19\"," - "\"state\":\"20\"," - "\"ppid\":\"21\"," - "\"utime\":\"22\"," - "\"stime\":\"23\"," - "\"cmd\":\"24\"," - "\"argvs\":\"25\"," - "\"euser\":\"26\"," - "\"ruser\":\"27\"," - "\"suser\":\"28\"," - "\"egroup\":\"29\"," - "\"rgroup\":\"30\"," - "\"sgroup\":\"31\"," - "\"fgroup\":\"32\"," - "\"priority\":\"33\"," - "\"nice\":\"34\"," - "\"size\":\"35\"," - "\"vm_size\":\"36\"," - "\"resident\":\"37\"," - "\"share\":\"38\"," - "\"start_time\":\"39\"," - "\"pgrp\":\"40\"," - "\"session\":\"41\"," - "\"nlwp\":\"42\"," - "\"tgid\":\"43\"," - "\"tty\":\"44\"," - "\"processor\":\"45\"," - "\"checksum\":\"46\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_ports_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync ports INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"protocol\":\"47\"," - "\"local_ip\":\"48\"," - "\"local_port\":\"49\"," - "\"remote_ip\":\"50\"," - "\"remote_port\":\"51\"," - "\"tx_queue\":\"52\"," - "\"rx_queue\":\"53\"," - "\"inode\":\"54\"," - "\"state\":\"55\"," - "\"pid\":\"56\"," - "\"process\":\"57\"," - "\"checksum\":\"58\"," - "\"item_id\":\"59\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_iface_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_iface INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"name\":\"59\"," - "\"adapter\":\"60\"," - "\"type\":\"61\"," - "\"state\":\"62\"," - "\"mtu\":\"63\"," - "\"mac\":\"64\"," - "\"tx_packets\":\"65\"," - "\"rx_packets\":\"66\"," - "\"tx_bytes\":\"67\"," - "\"rx_bytes\":\"68\"," - "\"tx_errors\":\"69\"," - "\"rx_errors\":\"70\"," - "\"tx_dropped\":\"71\"," - "\"rx_dropped\":\"72\"," - "\"checksum\":\"73\"," - "\"item_id\":\"74\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_protocol_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_protocol INSERTED " - "{" - "\"iface\":\"74\"," - "\"type\":\"75\"," - "\"gateway\":\"76\"," - "\"dhcp\":\"77\"," - "\"metric\":\"78\"," - "\"checksum\":\"79\"," - "\"item_id\":\"80\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_address_invalid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_address INSERTED " - "{" - "\"iface\":\"80\"," - "\"proto\":\"81\"," - "\"address\":\"82\"," - "\"netmask\":\"83\"," - "\"broadcast\":\"84\"," - "\"checksum\":\"85\"," - "\"item_id\":\"86\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Field 'proto' cannot be obtained."); - expect_string(__wrap__mdebug2, formatted_msg, "Error while mapping 'proto' field value."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_network_address_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync network_address INSERTED " - "{" - "\"iface\":\"80\"," - "\"proto\":\"ipv6\"," - "\"address\":\"82\"," - "\"netmask\":\"83\"," - "\"broadcast\":\"84\"," - "\"checksum\":\"85\"," - "\"item_id\":\"86\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_hardware_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync hwinfo INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"board_serial\":\"86\"," - "\"cpu_name\":\"87\"," - "\"cpu_cores\":88," - "\"cpu_MHz\":89.9," - "\"ram_total\":90," - "\"ram_free\":91," - "\"ram_usage\":92," - "\"checksum\":93" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} -void test_syscollector_dbsync_os_valid_msg_inserted(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync osinfo INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"hostname\":\"93\"," - "\"architecture\":\"94\"," - "\"os_name\":\"95\"," - "\"os_version\":\"96\"," - "\"os_codename\":\"97\"," - "\"os_major\":\"98\"," - "\"os_minor\":\"99\"," - "\"os_patch\":\"100\"," - "\"os_build\":\"101\"," - "\"os_platform\":\"102\"," - "\"sysname\":\"103\"," - "\"release\":\"104\"," - "\"version\":\"105\"," - "\"os_release\":\"106\"," - "\"checksum\":\"107\"," - "\"os_display_version\":\"108\"," - "\"reference\":\"110\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_dbsync_os_valid_msg_with_number_pk(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync osinfo MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"hostname\":\"93\"," - "\"architecture\":94," - "\"os_name\":\"95\"," - "\"os_version\":\"96\"," - "\"os_codename\":\"97\"," - "\"os_major\":\"98\"," - "\"os_minor\":\"99\"," - "\"os_patch\":\"100\"," - "\"os_build\":\"101\"," - "\"os_platform\":\"102\"," - "\"sysname\":\"103\"," - "\"release\":\"104\"," - "\"version\":\"105\"," - "\"os_release\":\"106\"," - "\"checksum\":\"107\"," - "\"os_display_version\":\"108\"," - "\"reference\":\"110\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_dbsync_with_no_type(void **state) -{ - Eventinfo *lf = *state; - int sock = 1; - const char type[] = {"dbsync"}; - char error_log[128]; - sprintf(error_log, INVALID_PREFIX, type); - - expect_string(__wrap__merror, formatted_msg, error_log); - expect_string(__wrap__mdebug1, formatted_msg, UNABLE_TO_SEND_INFORMATION_TO_WDB); - int ret = DecodeSyscollector(lf, &sock); - assert_int_equal(ret, 0); -} - -void test_syscollector_dbsync_valid_msg_query_error(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync hotfixes MODIFIED " - "{" - "\"hotfix\":\"KB123456\"," - "\"checksum\":\"abcdef0123456789\"" - "}"; - const char *result = "fail"; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - - expect_string(__wrap__mdebug1, formatted_msg, UNABLE_TO_SEND_INFORMATION_TO_WDB); - expect_string(__wrap__mdebug2, formatted_msg, WDBC_QUERY_EX_ERROR); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 1); -} - -void test_syscollector_dbsync_os_valid_msg_no_result_payload(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync osinfo MODIFIED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"hostname\":\"93\"," - "\"architecture\":\"94\"," - "\"os_name\":\"95\"," - "\"os_version\":\"96\"," - "\"os_codename\":\"97\"," - "\"os_major\":\"98\"," - "\"os_minor\":\"99\"," - "\"os_patch\":\"100\"," - "\"os_build\":\"101\"," - "\"os_platform\":\"102\"," - "\"sysname\":\"103\"," - "\"release\":\"104\"," - "\"version\":\"105\"," - "\"os_release\":\"106\"," - "\"checksum\":\"107\"," - "\"os_display_version\":\"108\"," - "\"reference\":\"110\"" - "}"; - const char *result = ""; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap__merror, formatted_msg, INVALID_RESPONSE); - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_dbsync_valid_msg_no_operation_or_data_no_object(void **state) -{ - Eventinfo *lf = *state; - int sock = 1; - const char type[] = {"hotfixes"}; - char error_log[128]; - sprintf(error_log, INVALID_OPERATION, type); - - expect_string(__wrap__merror, formatted_msg, error_log); - expect_string(__wrap__mdebug1, formatted_msg, UNABLE_TO_SEND_INFORMATION_TO_WDB); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 1); -} - -void test_syscollector_dbsync_empty_string(void **state) -{ - Eventinfo *lf = *state; - - const char *query = "agent 001 dbsync hwinfo INSERTED " - "{" - "\"scan_time\":\"2021/10/29 14:26:24\"," - "\"board_serial\":\"86\"," - "\"cpu_name\":\"\"," - "\"cpu_cores\":\"88\"," - "\"cpu_MHz\":\"89\"," - "\"ram_total\":\"90\"," - "\"ram_free\":\"91\"," - "\"ram_usage\":\"92\"," - "\"checksum\":\"93\"" - "}"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_dbsync_valid_msg_null_agentid(void **state) -{ - Eventinfo *lf = *state; - int sock = 1; - - expect_string(__wrap__mdebug1, formatted_msg, UNABLE_TO_SEND_INFORMATION_TO_WDB); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 1); -} - -void test_syscollector_dbsync_insert_multiple_null_valid_msg(void ** state) { - Eventinfo * lf = *state; - - const char * query = "agent 001 dbsync ports INSERTED " - "{" - "\"checksum\":\"944fb6182222660aeca5b27bcd14a579db60b58c\"," - "\"inode\":30905," - "\"item_id\":\"31ec8d41b06cc6dea02d9f088067d379d761732d\"," - "\"local_ip\":\"192.168.100.90\"," - "\"local_port\":53462," - "\"pid\":null," - "\"process\":null," - "\"protocol\":\"tcp\"," - "\"remote_ip\":null," - "\"remote_port\":10000," - "\"rx_queue\":null," - "\"scan_time\":\"2021/11/01 17:38:40\"," - "\"state\":null," - "\"tx_queue\":null" - "}"; - const char * result = "ok "; - - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); - - int index = 0; - - assert_string_equal(lf->fields[index].key, "type"); - assert_string_equal(lf->fields[index++].value, "dbsync_ports"); - - assert_string_equal(lf->fields[index].key, "port.protocol"); - assert_string_equal(lf->fields[index++].value, "tcp"); - - assert_string_equal(lf->fields[index].key, "port.local_ip"); - assert_string_equal(lf->fields[index++].value, "192.168.100.90"); - - assert_string_equal(lf->fields[index].key, "port.local_port"); - assert_string_equal(lf->fields[index++].value, "53462"); - - assert_string_equal(lf->fields[index].key, "port.remote_ip"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.remote_port"); - assert_string_equal(lf->fields[index++].value, "10000"); - - assert_string_equal(lf->fields[index].key, "port.tx_queue"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.rx_queue"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.inode"); - assert_string_equal(lf->fields[index++].value, "30905"); - - assert_string_equal(lf->fields[index].key, "port.state"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.pid"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.process"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "operation_type"); - assert_string_equal(lf->fields[index++].value, "INSERTED"); -} - -void test_syscollector_dbsync_deleted_multiple_null_valid_msg(void ** state) { - Eventinfo * lf = *state; - - const char *query = "agent 001 dbsync ports DELETED " - "{" - "\"inode\":30905," - "\"local_ip\":\"192.168.100.90\"," - "\"local_port\":53462," - "\"protocol\":\"tcp\"," - "\"scan_time\":\"2021/11/01 17:40:48\"" - "}"; - - const char * result = "ok "; - - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); - - int index = 0; - - assert_string_equal(lf->fields[index].key, "type"); - assert_string_equal(lf->fields[index++].value, "dbsync_ports"); - - assert_string_equal(lf->fields[index].key, "port.protocol"); - assert_string_equal(lf->fields[index++].value, "tcp"); - - assert_string_equal(lf->fields[index].key, "port.local_ip"); - assert_string_equal(lf->fields[index++].value, "192.168.100.90"); - - assert_string_equal(lf->fields[index].key, "port.local_port"); - assert_string_equal(lf->fields[index++].value, "53462"); - - assert_string_equal(lf->fields[index].key, "port.remote_ip"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.remote_port"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.tx_queue"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.rx_queue"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.inode"); - assert_string_equal(lf->fields[index++].value, "30905"); - - assert_string_equal(lf->fields[index].key, "port.state"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.pid"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "port.process"); - assert_string_equal(lf->fields[index++].value, ""); - - assert_string_equal(lf->fields[index].key, "operation_type"); - assert_string_equal(lf->fields[index++].value, "DELETED"); -} - -void test_syscollector_hardware_valid (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 hardware save 100|" - "2021/10/29 14:26:24|86|87|88|89.900000|" - "90.000000|91.000000|92"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_hardware_valid_inventory_empty (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 hardware save NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_hardware_valid_without_inventory (void **state) -{ - Eventinfo *lf = *state; - - int ret = DecodeSyscollector(lf, 0); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_hardware_invalid_query (void **state) -{ - Eventinfo *lf = *state; - int sock = 1; - const char *result = ""; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_any(__wrap_wdbc_query_ex, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send hardware information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_hardware_parse_result_not_ok (void **state) -{ - Eventinfo *lf = *state; - const char *result = "not_ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_any(__wrap_wdbc_query_ex, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send hardware information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_hotfix_valid (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 hotfix save 100|" - "2021/10/29 14:26:24|hotfix-version-test|"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_hotfix_valid_hotfix_end (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 hotfix del 100"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_hotfix_invalid_query (void **state) -{ - Eventinfo *lf = *state; - int sock = 1; - const char *result = ""; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_any(__wrap_wdbc_query_ex, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send hotfixes information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_hotfix_invalid_hotfix_end_query (void **state) -{ - test_syscollector_hotfix_invalid_query(state); -} - -void test_syscollector_hotfix_without_ID (void **state) -{ - Eventinfo *lf = *state; - - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send hotfixes information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, 0); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_hotfix_parse_result_not_ok (void **state) -{ - Eventinfo *lf = *state; - const char *result = "not_ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_any(__wrap_wdbc_query_ex, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send hotfixes information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_netinfo_valid (void **state) -{ - Eventinfo *lf = *state; - const char *queries[] = { "agent 001 netinfo save 100|2021/10/29 14:26:24|" - "86|87|88|89|99|90|91|92|93|94|95|96|97|98", - "agent 001 netproto save 100|86|0|0.0.0.2|0.0.0.3|10", - "agent 001 netaddr save 100|86|0|0.0.0.0|255.255.255.255|0.0.0.1", - "agent 001 netaddr save 100|86|0|0.0.1.0|255.255.255.254|0.0.1.1", - "agent 001 netproto save 100|86|1|0000:0000:0000:0:0000:0000:0000:0002|" - "0000:0000:0000:0:0000:0000:0000:0003|10", - "agent 001 netaddr save 100|86|1|0000:0000:0000:0:0000:0000:0000:0000|" - "0000::|0000:0000:0000:0:0000:0000:0000:0001", - "agent 001 netaddr save 100|86|1|0000:0000:0000:0:0000:0000:0001:0000|" - "0001::|0000:0000:0000:0:0000:0000:0001:0001" }; - - const char *result = "ok "; - int sock = 1; - size_t count = sizeof(queries) / sizeof(*queries); - - for (int i = 0; i < count; i++) - { - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, queries[i]); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - } - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -static const char *valid_empty_queries[] = { "agent 001 netinfo save NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL", - "agent 001 netproto save NULL|NULL|0|NULL|NULL|NULL", - "agent 001 netproto save NULL|NULL|1|NULL|" - "NULL|NULL" }; - -void test_syscollector_netinfo_valid_groups_empty (void **state) -{ - Eventinfo *lf = *state; - const char *result = "ok "; - int sock = 1; - size_t count = sizeof(valid_empty_queries) / sizeof(*valid_empty_queries); - - for (int i = 0; i < count; i++) - { - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_queries[i]); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - } - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -static const char *valid_empty_address_array_queries[] = { "agent 001 netinfo save NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL", - "agent 001 netproto save NULL|NULL|0|NULL|NULL|NULL", - "agent 001 netaddr save NULL|NULL|0|0.0.0.0|NULL|NULL", - "agent 001 netproto save NULL|NULL|1|NULL|" - "NULL|NULL", - "agent 001 netaddr save NULL|NULL|1|0000:0000:0000:0:0000:0000:0000:0000|" - "NULL|NULL" }; - -void test_syscollector_netinfo_valid_address_array_empty (void **state) -{ - Eventinfo *lf = *state; - const char *result = "ok "; - int sock = 1; - size_t count = sizeof(valid_empty_address_array_queries) / sizeof(*valid_empty_address_array_queries); - - for (int i = 0; i < count; i++) - { - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_address_array_queries[i]); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - } - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_netinfo_valid_network_end (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 netinfo del 100"; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Invalid query - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__merror, formatted_msg, "Unable to send netinfo message to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Invalid parse - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__merror, formatted_msg, "Unable to send netinfo message to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -void test_syscollector_netinfo_invalid_query (void **state, const int edge, const bool parse) -{ - Eventinfo *lf = *state; - - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - int i = 0; - - for (; i < edge; i++) - { - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_queries[i]); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - } - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_queries[i]); - expect_any(__wrap_wdbc_query_ex, len); - if (parse) - { - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - } - else - { - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - } - expect_string(__wrap__merror, formatted_msg, "Unable to send netinfo message to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_netinfo_invalid_queries (void **state) -{ - size_t count = sizeof(valid_empty_queries) / sizeof(*valid_empty_queries); - - for (int i = 0; i < count; i++) - { - test_syscollector_netinfo_invalid_query (state, i, false); - test_syscollector_netinfo_invalid_query (state, i, true); - } -} - -void test_syscollector_netinfo_invalid_address_array_empty_query (void **state, const int edge, const bool parse) -{ - Eventinfo *lf = *state; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - int i = 0; - - for (; i < edge; i++) - { - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_address_array_queries[i]); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - } - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_address_array_queries[i]); - expect_any(__wrap_wdbc_query_ex, len); - if (parse) - { - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - } - else - { - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - } - expect_string(__wrap__merror, formatted_msg, "Unable to send netinfo message to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_netinfo_invalid_address_array_empty_queries (void **state) -{ - size_t count = sizeof(valid_empty_address_array_queries) / sizeof(*valid_empty_address_array_queries); - - for (int i = 0; i < count; i++) - { - test_syscollector_netinfo_invalid_address_array_empty_query (state, i, false); - test_syscollector_netinfo_invalid_address_array_empty_query (state, i, true); - } -} - -static const char *valid_empty_address_array_free[] = { "agent 001 netinfo save NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL", - "agent 001 netproto save NULL|NULL|0|NULL|NULL|NULL", - "agent 001 netaddr save NULL|NULL|0|0.0.0.0|255.255.255.255|0.0.0.1", - "agent 001 netproto save NULL|NULL|1|NULL|" - "NULL|NULL", - "agent 001 netaddr save NULL|NULL|1|0000:0000:0000:0:0000:0000:0000:0000|" - "0000::|0000:0000:0000:0:0000:0000:0000:0001" }; - -void test_syscollector_netinfo_net_array_data_free (void **state, const int edge, const bool parse) -{ - Eventinfo *lf = *state; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - int i = 0; - - for (; i < edge; i++) - { - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_address_array_free[i]); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - } - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, valid_empty_address_array_free[i]); - expect_any(__wrap_wdbc_query_ex, len); - if (parse) - { - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - } - else - { - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - } - expect_string(__wrap__merror, formatted_msg, "Unable to send netinfo message to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_netinfo_net_data_free (void **state) -{ - size_t count = sizeof(valid_empty_address_array_free) / sizeof(*valid_empty_address_array_free); - - for (int i = 0; i < count; i++) - { - test_syscollector_netinfo_net_array_data_free (state, i, false); - test_syscollector_netinfo_net_array_data_free (state, i, true); - } -} - -void test_syscollector_osinfo_valid (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 osinfo set 100|2021/10/29 14:26:24|host|x86|" - "name|0.0.1|test|0|0|1|platform|sysname|R1|0.0.2|R2|P1|0.0.1-R2-P1"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -static const char *osinfo_empty_query = "agent 001 osinfo set NULL|NULL|NULL|NULL|NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL"; - -void test_syscollector_osinfo_valid_inventory_empty (void **state) -{ - Eventinfo *lf = *state; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, osinfo_empty_query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -void test_syscollector_osinfo_invalid_inventory_empty (void **state) -{ - Eventinfo *lf = *state; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - // Invalid query out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, osinfo_empty_query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send osinfo message to Wazuh DB."); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Invalid parse out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, osinfo_empty_query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send osinfo message to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -void test_syscollector_package_valid (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 package save 100|2021/10/29 14:26:24|" - "format|name|priority|group|0|vendor|install_time|version|" - "architecture|multi-arch|source|description|location|" - "0b50c065ffd996675a6b8e95e716091165796053"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -extern int error_package; -extern int prev_package_id; - -void test_syscollector_package_program_empty (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 package save 100|NULL|NULL|NULL|NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|" - "da39a3ee5e6b4b0d3255bfef95601890afd80709"; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Clean previous package error, and exit - error_package = 1; - prev_package_id = 100; - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Clean previous package error, and continue - error_package = 1; - prev_package_id++; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Query error out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send packages information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Parse error out - error_package = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send packages information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -void test_syscollector_package_valid_without_ID (void **state) -{ - Eventinfo *lf = *state; - - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send packages information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, NULL); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_package_program_end (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 package del 100"; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - error_package = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Invalid query out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send packages information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Return ok after query error - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Return ok after query error, changing package_id - prev_package_id++; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send packages information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Invalid parse out - error_package = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send packages information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -void test_syscollector_port_valid (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 port save 100|2021/10/29 14:26:24|protocol|" - "0.0.0.0|10|0.0.0.1|11|12|13|14|ok|15|process"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -extern int error_port; -extern int prev_port_id; - -void test_syscollector_port_empty (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 port save 100|NULL|NULL|NULL|NULL|NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL"; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Clean previous port error, and exit - error_port = 1; - prev_port_id = 100; - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Clean previous port error, and continue - error_port = 1; - prev_port_id++; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Query error out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send ports information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Parse error out - error_port = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send ports information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -void test_syscollector_port_valid_without_ID (void **state) -{ - Eventinfo *lf = *state; - - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send ports information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, NULL); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_port_end (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 port del 100"; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - error_port = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Invalid query out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send ports information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Return ok after query error - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Return ok after query error, changing port_id - prev_port_id++; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send ports information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Invalid parse out - error_port = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send ports information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -void test_syscollector_process_valid (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 process save 100|2021/10/29 14:26:24|10|name|" - "state|11|12|13|cmd|arg|euser|ruser|suser|egroup|rgroup|sgroup|fgroup|" - "14|15|16|17|18|19|20|21|22|23|24|25|26"; - const char *result = "ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - - assert_int_not_equal(ret, 0); -} - -extern int error_process; -extern int prev_process_id; - -void test_syscollector_process_empty (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 process save 100|NULL|NULL|NULL|NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|" - "NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL|NULL"; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Clean previous process error, and exit - error_process = 1; - prev_process_id = 100; - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Clean previous process error, and continue - error_process = 1; - prev_process_id++; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Query error out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send processes information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Parse error out - error_process = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send processes information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -void test_syscollector_process_valid_without_ID (void **state) -{ - Eventinfo *lf = *state; - - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send processes information to Wazuh DB."); - - int ret = DecodeSyscollector(lf, NULL); - - assert_int_not_equal(ret, -1); -} - -void test_syscollector_process_end (void **state) -{ - Eventinfo *lf = *state; - const char *query = "agent 001 process del 100"; - const char *result = "ok "; - const char *result_not_ok = "not ok "; - int sock = 1; - - error_process = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, 0); - - int ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Invalid query out - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result); - will_return(__wrap_wdbc_query_ex, -1); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send processes information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Return ok after query error - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, 0); - - // Return ok after query error, changing package_id - prev_process_id++; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send processes information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); - - // Invalid parse out - error_process = 0; - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query); - expect_any(__wrap_wdbc_query_ex, len); - will_return(__wrap_wdbc_query_ex, result_not_ok); - will_return(__wrap_wdbc_query_ex, 0); - expect_string(__wrap__mdebug1, formatted_msg, - "Unable to send processes information to Wazuh DB."); - - ret = DecodeSyscollector(lf, &sock); - assert_int_not_equal(ret, -1); -} - -int main() -{ - const struct CMUnitTest tests[] = { - /* Misc invalid tests*/ - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_invalid_location, test_setup_invalid_location, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_invalid_json, test_setup_invalid_json, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_invalid_msgtype, test_setup_invalid_msgtype, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_valid_msg_unknown_operation, test_setup_valid_msg_unknown_operation, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_valid_msg_invalid_field_list, test_setup_valid_msg_invalid_field_list, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_valid_msg_query_error, test_setup_valid_msg_query_error, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_with_no_type, test_setup_valid_msg_with_no_type, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_valid_msg_no_operation_or_data_no_object, test_setup_valid_msg_data_as_value, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_valid_msg_no_operation_or_data_no_object, test_setup_valid_msg_no_operation, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_empty_string, test_setup_valid_msg_empty_string, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_valid_msg_null_agentid, test_setup_valid_msg_null_agentid, test_cleanup), - /* MODIFIED delta tests*/ - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_hotfixes_valid_msg_modified, test_setup_hotfixes_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_packages_valid_msg_modified, test_setup_packages_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_processes_valid_msg_modified, test_setup_processes_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_ports_valid_msg_modified, test_setup_ports_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_iface_valid_msg_modified, test_setup_network_iface_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_protocol_valid_msg_modified, test_setup_network_protocol_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_address_invalid_msg_modified, test_setup_network_address_invalid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_address_valid_msg_modified, test_setup_network_address_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_hardware_valid_msg_modified, test_setup_hardware_valid_msg_modified, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_os_valid_msg_modified, test_setup_os_valid_msg_modified, test_cleanup), - /* INSERTED delta tests*/ - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_hotfixes_valid_msg_inserted, test_setup_hotfixes_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_packages_valid_msg_inserted, test_setup_packages_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_processes_valid_msg_inserted, test_setup_processes_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_ports_valid_msg_inserted, test_setup_ports_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_iface_valid_msg_inserted, test_setup_network_iface_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_protocol_valid_msg_inserted, test_setup_network_protocol_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_address_valid_msg_inserted, test_setup_network_address_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_network_address_invalid_msg_inserted, test_setup_network_address_invalid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_hardware_valid_msg_inserted, test_setup_hardware_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_os_valid_msg_inserted, test_setup_os_valid_msg_inserted, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_os_valid_msg_with_number_pk, test_setup_os_valid_msg_with_number_pk, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_insert_multiple_null_valid_msg, test_setup_insert_multiple_null_field_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_deleted_multiple_null_valid_msg, test_setup_deleted_multiple_null_field_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_dbsync_os_valid_msg_no_result_payload, test_setup_os_valid_msg_modified, test_cleanup), - // Hardware tests - cmocka_unit_test_setup_teardown(test_syscollector_hardware_valid, test_setup_hardware_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hardware_valid_inventory_empty, test_setup_hardware_valid_msg_inventory_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hardware_valid_without_inventory, test_setup_hardware_valid_msg_without_inventory, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hardware_invalid_query, test_setup_hardware_valid_msg_inventory_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hardware_parse_result_not_ok, test_setup_hardware_valid_msg_inventory_empty, test_cleanup), - // Hotfix tests - cmocka_unit_test_setup_teardown(test_syscollector_hotfix_valid, test_setup_hotfix_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hotfix_valid_hotfix_end, test_setup_hotfix_valid_hotfix_end_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hotfix_invalid_query, test_setup_hotfix_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hotfix_invalid_hotfix_end_query, test_setup_hotfix_valid_hotfix_end_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hotfix_without_ID, test_setup_hotfix_valid_msg_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_hotfix_parse_result_not_ok, test_setup_hotfix_valid_msg, test_cleanup), - // Netinfo tests - cmocka_unit_test_setup_teardown(test_syscollector_netinfo_valid, test_setup_netinfo_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_netinfo_valid_groups_empty, test_setup_netinfo_valid_msg_groups_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_netinfo_valid_address_array_empty, test_setup_netinfo_valid_msg_address_array_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_netinfo_valid_network_end, test_setup_netinfo_valid_network_end_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_netinfo_invalid_queries, test_setup_netinfo_valid_msg_groups_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_netinfo_invalid_address_array_empty_queries, test_setup_netinfo_valid_msg_address_array_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_netinfo_net_data_free, test_setup_netinfo_valid_msg_net_data_free, test_cleanup), - // OSinfo tests - cmocka_unit_test_setup_teardown(test_syscollector_osinfo_valid, test_setup_osinfo_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_osinfo_valid_inventory_empty, test_setup_osinfo_valid_msg_inventory_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_osinfo_invalid_inventory_empty, test_setup_osinfo_valid_msg_inventory_empty, test_cleanup), - // Package tests - cmocka_unit_test_setup_teardown(test_syscollector_package_valid, test_setup_package_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_package_program_empty, test_setup_package_valid_msg_program_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_package_valid_without_ID, test_setup_package_valid_msg_without_ID, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_package_program_end, test_setup_package_valid_msg_program_end, test_cleanup), - // Port tests - cmocka_unit_test_setup_teardown(test_syscollector_port_valid, test_setup_port_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_port_empty, test_setup_port_valid_msg_port_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_port_valid_without_ID, test_setup_port_valid_msg_without_ID, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_port_end, test_setup_port_valid_msg_port_end, test_cleanup), - // Process tests - cmocka_unit_test_setup_teardown(test_syscollector_process_valid, test_setup_process_valid_msg, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_process_empty, test_setup_process_valid_msg_process_empty, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_process_valid_without_ID, test_setup_process_valid_msg_without_ID, test_cleanup), - cmocka_unit_test_setup_teardown(test_syscollector_process_end, test_setup_process_valid_msg_process_end, test_cleanup) - }; - return cmocka_run_group_tests(tests, test_setup_global, NULL); -} diff --git a/src/unit_tests/analysisd/test_decoder_winevtchannel.c b/src/unit_tests/analysisd/test_decoder_winevtchannel.c deleted file mode 100644 index 58d9f5e9bcd..00000000000 --- a/src/unit_tests/analysisd/test_decoder_winevtchannel.c +++ /dev/null @@ -1,591 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ -#include -#include -#include -#include -#include -#include - -#include "../../config/global-config.h" -#include "../../analysisd/eventinfo.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_xml/os_xml_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" - -#define TEST_AGENT_ID "005" -#define TEST_TIME 10005 -#define TEST_LOG_STRING "Test log string File 'file_name'" - -#define FAIL_DECODE 1 -#define SUCCESS_DECODE 0 - -extern int DecodeWinevt(Eventinfo * lf); -extern void w_free_event_info(Eventinfo * lf); -extern _Config Config; - -int test_setup_global(void ** state) { - expect_string(__wrap__mdebug1, formatted_msg, "WinevtInit completed."); - Config.decoder_order_size = 32; - WinevtInit(); - return 0; -} - -int test_setup(void ** state) { - Eventinfo * lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - os_strdup(TEST_AGENT_ID, lf->agent_id); - os_strdup(TEST_LOG_STRING, lf->full_log); - lf->log = lf->full_log; - lf->time.tv_sec = (time_t) TEST_TIME; - - *state = lf; - - return 0; -} - -int test_cleanup(void ** state) { - Eventinfo * lf = *state; - - w_free_event_info(lf); - return 0; -} - -// TODO move -void * __wrap_JSON_Decoder_Exec(Eventinfo * lf, __attribute__((unused)) regex_matching * decoder_match) { - function_called(); - return (void *) NULL; -} - -void initDec() { - will_return(__wrap_cJSON_CreateObject, (void *) 0x1); // final_event - will_return(__wrap_cJSON_CreateObject, (void *) 0x1); // json_event - will_return(__wrap_cJSON_CreateObject, (void *) 0x1); // json_system_in - will_return(__wrap_cJSON_CreateObject, (void *) 0x0); // json_eventdata_in TODO Change this to 0x1 - will_return(__wrap_cJSON_CreateObject, (void *) 0x1); // json_extra_in -} - -void cleanDec(bool deleteXML) { - if (deleteXML) { - expect_function_call(__wrap_OS_ClearXML); - } - expect_function_call(__wrap_cJSON_Delete); - expect_function_call(__wrap_cJSON_Delete); -} - -void test_winevt_json_parseFail(void ** state) { - Eventinfo * lf = *state; - initDec(); - - // Fail in parsing the JSON - will_return(__wrap_cJSON_ParseWithOpts, "a json error"); - will_return(__wrap_cJSON_ParseWithOpts, NULL); - expect_string(__wrap__merror, formatted_msg, "Malformed EventChannel JSON event."); - - expect_function_call(__wrap_cJSON_Delete); - expect_function_call(__wrap_cJSON_Delete); - expect_function_call(__wrap_cJSON_Delete); - expect_function_call(__wrap_cJSON_Delete); - - cleanDec(false); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, FAIL_DECODE); -} - -void test_winevt_json_notEvent(void ** state) { - Eventinfo * lf = *state; - initDec(); - - // parse ok - will_return(__wrap_cJSON_ParseWithOpts, (char *) 0x1); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 0x1); - - // Event not found in JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Malformed JSON received. No 'Event' field found."); - - expect_function_call(__wrap_cJSON_Delete); // Delete json_event - expect_function_call(__wrap_cJSON_Delete); // Delete json_system_in - expect_function_call(__wrap_cJSON_Delete); // Delete json_eventdata_in - expect_function_call(__wrap_cJSON_Delete); // Delete json_extra_in - - cleanDec(false); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, FAIL_DECODE); -} - -void test_winevt_failXML_parse(void ** state) { - Eventinfo * lf = *state; - initDec(); - - // parse ok - will_return(__wrap_cJSON_ParseWithOpts, (char *) 0x1); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 0x1); - - /********************** EVENT ***********************/ - // Get event - - cJSON event = {0}; - event.valuestring = strdup("test"); - will_return(__wrap_cJSON_GetObjectItem, &event); - - // Fail read xml - will_return(__wrap_OS_ReadXMLString, -1); - will_return(__wrap_OS_ReadXMLString, "unknown"); - will_return(__wrap_OS_ReadXMLString, 5); - expect_string(__wrap__mwarn, formatted_msg, "Could not read XML string: 'test'"); - - /********************** Message ***********************/ - // Fail get message - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_PrintUnformatted, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); // json_system_in - will_return(__wrap_cJSON_AddItemToObject, true); - - // json_eventdata_in - - // json_extra_in - expect_function_call(__wrap_cJSON_Delete); // Delete - - /********************** Final event *********************/ - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - will_return(__wrap_cJSON_PrintUnformatted, (char *) strdup("test")); - - expect_function_call(__wrap_JSON_Decoder_Exec); - - cleanDec(false); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); - os_free(event.valuestring); -} - -void test_winevt_dec_systemNode_ok(void ** state) { - Eventinfo * lf = *state; - initDec(); - - // parse ok - will_return(__wrap_cJSON_ParseWithOpts, (char *) 0x1); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 0x1); - - /********************** EVENT ***********************/ - // Get event - - cJSON event = {0}; - event.valuestring = strdup("test"); - will_return(__wrap_cJSON_GetObjectItem, &event); - - // Read xml ok - will_return(__wrap_OS_ReadXMLString, 0); - - XML_NODE root_node; // - os_calloc(2, sizeof(xml_node *), root_node); - os_calloc(1, sizeof(xml_node), root_node[0]); - os_strdup("event", root_node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, root_node); - - XML_NODE system_root; // - os_calloc(2, sizeof(xml_node *), system_root); - os_calloc(1, sizeof(xml_node), system_root[0]); - os_strdup("System", system_root[0]->element); - will_return(__wrap_OS_GetElementsbyNode, system_root); - - // Chill of system - XML_NODE system_chill; - os_calloc(9, sizeof(xml_node *), system_chill); - os_calloc(1, sizeof(xml_node), system_chill[0]); // provider - os_calloc(1, sizeof(xml_node), system_chill[1]); // TimeCreated - os_calloc(1, sizeof(xml_node), system_chill[2]); // Execution - os_calloc(1, sizeof(xml_node), system_chill[3]); // Channel - os_calloc(1, sizeof(xml_node), system_chill[4]); // Security - os_calloc(1, sizeof(xml_node), system_chill[5]); // Level - os_calloc(1, sizeof(xml_node), system_chill[6]); // Keywords - os_calloc(1, sizeof(xml_node), system_chill[7]); // Other fields - - will_return(__wrap_OS_GetElementsbyNode, system_chill); - - // Provider node - xml_node * providerNode = system_chill[0]; - os_strdup("Provider", providerNode->element); - - os_calloc(4, sizeof(char *), providerNode->attributes); - os_calloc(4, sizeof(char *), providerNode->values); - - os_strdup("Name", providerNode->attributes[0]); - os_strdup("Guid", providerNode->attributes[1]); - os_strdup("EventSourceName", providerNode->attributes[2]); - - os_strdup("value name", providerNode->values[0]); - os_strdup("value guid", providerNode->values[1]); - os_strdup("value event source name", providerNode->values[2]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "providerName"); - expect_string(__wrap_cJSON_AddStringToObject, string, "value name"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "providerGuid"); - expect_string(__wrap_cJSON_AddStringToObject, string, "value guid"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "eventSourceName"); - expect_string(__wrap_cJSON_AddStringToObject, string, "value event source name"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // TimeCreated node - xml_node * timeCreatedNode = system_chill[1]; - os_strdup("TimeCreated", timeCreatedNode->element); - - os_calloc(2, sizeof(char *), timeCreatedNode->attributes); - os_calloc(2, sizeof(char *), timeCreatedNode->values); - - os_strdup("SystemTime", timeCreatedNode->attributes[0]); - os_strdup("time value", timeCreatedNode->values[0]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "systemTime"); - expect_string(__wrap_cJSON_AddStringToObject, string, "time value"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Execution node - xml_node * executionNode = system_chill[2]; - os_strdup("Execution", executionNode->element); - - os_calloc(3, sizeof(char *), executionNode->attributes); - os_calloc(3, sizeof(char *), executionNode->values); - - os_strdup("ProcessID", executionNode->attributes[0]); - os_strdup("ThreadID", executionNode->attributes[1]); - - os_strdup("process id value", executionNode->values[0]); - os_strdup("thread id value", executionNode->values[1]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "processID"); - expect_string(__wrap_cJSON_AddStringToObject, string, "process id value"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "threadID"); - expect_string(__wrap_cJSON_AddStringToObject, string, "thread id value"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Channel node - xml_node * channelNode = system_chill[3]; - os_strdup("Channel", channelNode->element); - os_strdup("Channel/name", channelNode->content); - - expect_string(__wrap_cJSON_AddStringToObject, name, "channel"); - expect_string(__wrap_cJSON_AddStringToObject, string, "Channel/name"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - os_calloc(2, sizeof(char *), channelNode->attributes); - os_calloc(2, sizeof(char *), channelNode->values); - - os_strdup("useridAttr", channelNode->attributes[0]); - os_strdup("UserID", channelNode->values[0]); - // TODO Fix this should be the attribute value - expect_string(__wrap_cJSON_AddStringToObject, name, "userID"); - expect_string(__wrap_cJSON_AddStringToObject, string, "UserID"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Security node - xml_node * securityNode = system_chill[4]; - os_strdup("Security", securityNode->element); - - os_calloc(2, sizeof(char *), securityNode->attributes); - os_calloc(2, sizeof(char *), securityNode->values); - - os_strdup("useridAttr", securityNode->attributes[0]); - os_strdup("UserID", securityNode->values[0]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "securityUserID"); - expect_string(__wrap_cJSON_AddStringToObject, string, "UserID"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Level - xml_node * levelNode = system_chill[5]; - - os_strdup("Level", levelNode->element); - os_strdup("info/warn/error", levelNode->content); - - expect_string(__wrap_cJSON_AddStringToObject, name, "level"); - expect_string(__wrap_cJSON_AddStringToObject, string, "info/warn/error"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Keywords - xml_node * keywordsNode = system_chill[6]; - - os_strdup("Keywords", keywordsNode->element); - os_strdup("keyword1/keyword2", keywordsNode->content); - - expect_string(__wrap_cJSON_AddStringToObject, name, "keywords"); - expect_string(__wrap_cJSON_AddStringToObject, string, "keyword1/keyword2"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Other fields - xml_node * otherFieldsNode = system_chill[7]; - - os_strdup("OtherFields", otherFieldsNode->element); - os_strdup("other field value", otherFieldsNode->content); - - expect_string(__wrap_cJSON_AddStringToObject, name, "otherFields"); - expect_string(__wrap_cJSON_AddStringToObject, string, "other field value"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - /*********** Message [level && keywords] **************/ - expect_string(__wrap_cJSON_AddStringToObject, name, "severityValue"); - expect_string(__wrap_cJSON_AddStringToObject, string, "UNKNOWN"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - /********************** Message ***********************/ - // Fail get message - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_PrintUnformatted, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); // json_system_in - will_return(__wrap_cJSON_AddItemToObject, true); - - // json_eventdata_in - - // json_extra_in - expect_function_call(__wrap_cJSON_Delete); // Delete - - /********************** Final event *********************/ - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - will_return(__wrap_cJSON_PrintUnformatted, (char *) strdup("test")); - - expect_function_call(__wrap_JSON_Decoder_Exec); - - cleanDec(false); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); - os_free(event.valuestring); -} - -void test_winevt_dec_eventDataNode_ok(void ** state) { - Eventinfo * lf = *state; - initDec(); - - // parse ok - will_return(__wrap_cJSON_ParseWithOpts, (char *) 0x1); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 0x1); - - /********************** EVENT ***********************/ - // Get event - - cJSON event = {0}; - event.valuestring = strdup("test"); - will_return(__wrap_cJSON_GetObjectItem, &event); - - // Read xml ok - will_return(__wrap_OS_ReadXMLString, 0); - - XML_NODE root_node; // - os_calloc(2, sizeof(xml_node *), root_node); - os_calloc(1, sizeof(xml_node), root_node[0]); - os_strdup("event", root_node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, root_node); - - XML_NODE eventdata_root; // - os_calloc(2, sizeof(xml_node *), eventdata_root); - os_calloc(1, sizeof(xml_node), eventdata_root[0]); - os_strdup("EventData", eventdata_root[0]->element); - will_return(__wrap_OS_GetElementsbyNode, eventdata_root); - - // Chill of eventData - XML_NODE eventdata_chill; - os_calloc(4, sizeof(xml_node *), eventdata_chill); - os_calloc(1, sizeof(xml_node), eventdata_chill[0]); // Data 1 - os_calloc(1, sizeof(xml_node), eventdata_chill[1]); // Data 2 - os_calloc(1, sizeof(xml_node), eventdata_chill[2]); // Data 3 - // os_calloc(1, sizeof(xml_node), eventdata_chill[3]); // Data 4 - - will_return(__wrap_OS_GetElementsbyNode, eventdata_chill); - - // Data 1 node - xml_node * data_1_node = eventdata_chill[0]; - os_strdup("Data", data_1_node->element); - os_strdup("content", data_1_node->content); - - os_calloc(2, sizeof(char *), data_1_node->attributes); - os_calloc(2, sizeof(char *), data_1_node->values); - - os_strdup("Name", data_1_node->attributes[0]); - os_strdup("categoryId", data_1_node->values[0]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "categoryId"); - expect_string(__wrap_cJSON_AddStringToObject, string, "content"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Data 2 node - xml_node * data_2_node = eventdata_chill[1]; - os_strdup("Data", data_2_node->element); - os_strdup("content", data_2_node->content); - - os_calloc(2, sizeof(char *), data_2_node->attributes); - os_calloc(2, sizeof(char *), data_2_node->values); - - os_strdup("Name", data_2_node->attributes[0]); - os_strdup("subcategoryId", data_2_node->values[0]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "subcategoryId"); - expect_string(__wrap_cJSON_AddStringToObject, string, "content"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - // Data 3 node - xml_node * data_3_node = eventdata_chill[2]; - os_strdup("Data", data_3_node->element); - os_strdup("%%8451", data_3_node->content); - - os_calloc(2, sizeof(char *), data_3_node->attributes); - os_calloc(2, sizeof(char *), data_3_node->values); - - os_strdup("Name", data_3_node->attributes[0]); - os_strdup("auditPolicyChanges", data_3_node->values[0]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "auditPolicyChangesId"); - expect_string(__wrap_cJSON_AddStringToObject, string, "%%8451"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - /******** Message [auditPolicyChangesId] **************/ - - expect_string(__wrap_cJSON_AddStringToObject, name, "auditPolicyChanges"); - expect_string(__wrap_cJSON_AddStringToObject, string, "Failure added"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - /********************** Message ***********************/ - // Fail get message - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_PrintUnformatted, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); // json_system_in - will_return(__wrap_cJSON_AddItemToObject, true); - - // json_eventdata_in - - // json_extra_in - expect_function_call(__wrap_cJSON_Delete); // Delete - - /********************** Final event *********************/ - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - will_return(__wrap_cJSON_PrintUnformatted, (char *) strdup("test")); - - expect_function_call(__wrap_JSON_Decoder_Exec); - - cleanDec(false); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); - os_free(event.valuestring); -} - -void test_winevt_dec_long_log_ok(void ** state) { - Eventinfo * lf = *state; - initDec(); - - // parse ok - will_return(__wrap_cJSON_ParseWithOpts, (char *) 0x1); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 0x1); - - /********************** EVENT ***********************/ - // Get event - cJSON event = {0}; - event.valuestring = strdup("test"); - will_return(__wrap_cJSON_GetObjectItem, &event); - - // Read xml ok - will_return(__wrap_OS_ReadXMLString, 0); - - XML_NODE root_node; // - os_calloc(2, sizeof(xml_node *), root_node); - os_calloc(1, sizeof(xml_node), root_node[0]); - os_strdup("event", root_node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, root_node); - - XML_NODE eventdata_root; // - os_calloc(2, sizeof(xml_node *), eventdata_root); - os_calloc(1, sizeof(xml_node), eventdata_root[0]); - os_strdup("EventData", eventdata_root[0]->element); - will_return(__wrap_OS_GetElementsbyNode, eventdata_root); - - // Chill of eventData - XML_NODE eventdata_chill; - os_calloc(2, sizeof(xml_node *), eventdata_chill); - os_calloc(1, sizeof(xml_node), eventdata_chill[0]); // Data 1 - - will_return(__wrap_OS_GetElementsbyNode, eventdata_chill); - - // Data 1 node - xml_node * data_1_node = eventdata_chill[0]; - os_strdup("Data", data_1_node->element); - os_strdup("content", data_1_node->content); - - os_calloc(2, sizeof(char *), data_1_node->attributes); - os_calloc(2, sizeof(char *), data_1_node->values); - - os_strdup("Name", data_1_node->attributes[0]); - os_strdup("categoryId", data_1_node->values[0]); - - expect_string(__wrap_cJSON_AddStringToObject, name, "categoryId"); - expect_string(__wrap_cJSON_AddStringToObject, string, "content"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - /********************** Message ***********************/ - // Fail get message - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_PrintUnformatted, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); // json_system_in - will_return(__wrap_cJSON_AddItemToObject, true); - - // json_extra_in - expect_function_call(__wrap_cJSON_Delete); // Delete - - /********************** Final event *********************/ - - size_t long_log_size = strlen(lf->full_log) + 1; - // Create a long log string (5 times the size of the original) - char * long_log = (char *) calloc(long_log_size * 5, sizeof(char)); - for (int i = 0; i < 5; i++) { - strcat(long_log, lf->full_log); - } - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - will_return(__wrap_cJSON_PrintUnformatted, (char *) long_log); - - expect_function_call(__wrap_JSON_Decoder_Exec); - - cleanDec(false); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); - os_free(event.valuestring); -} - -int main() { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_winevt_json_parseFail, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_json_notEvent, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_failXML_parse, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_dec_systemNode_ok, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_dec_eventDataNode_ok, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_dec_long_log_ok, test_setup, test_cleanup), - // - }; - return cmocka_run_group_tests(tests, test_setup_global, NULL); -} diff --git a/src/unit_tests/analysisd/test_decoder_winevtchannel_input.c b/src/unit_tests/analysisd/test_decoder_winevtchannel_input.c deleted file mode 100644 index 68a6614499d..00000000000 --- a/src/unit_tests/analysisd/test_decoder_winevtchannel_input.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../config/global-config.h" -#include "../../analysisd/eventinfo.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -#define TEST_AGENT_ID "005" -#define TEST_TIME 10005 - -#define FAIL_DECODE 1 -#define SUCCESS_DECODE 0 - -extern int DecodeWinevt(Eventinfo * lf); -extern void w_free_event_info(Eventinfo * lf); -extern _Config Config; - -int test_setup_global(void ** state) { - expect_string(__wrap__mdebug1, formatted_msg, "WinevtInit completed."); - Config.decoder_order_size = 32; - WinevtInit(); - return 0; -} - -int test_setup(void ** state) { - Eventinfo * lf; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(Config.decoder_order_size, sizeof(DynamicField), lf->fields); - Zero_Eventinfo(lf); - os_strdup(TEST_AGENT_ID, lf->agent_id); - lf->time.tv_sec = (time_t) TEST_TIME; - - *state = lf; - - // lf->log and lf->full_log are null - - return 0; -} - -int test_cleanup(void ** state) { - Eventinfo * lf = *state; - - w_free_event_info(lf); - return 0; -} - -void test_winevt_dec_time_created_no_attributes(void ** state) { - const char * TEST_LOG_STRING = "{\"Event\":\"\"}"; - - Eventinfo * lf = *state; - lf->log = lf->full_log = strdup(TEST_LOG_STRING); - - expect_string(__wrap__mdebug2, formatted_msg, "Decoding JSON: '{\"win\":{\"system\":{}}}'"); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); -} - -void test_winevt_dec_execution_no_attributes(void ** state) { - const char * TEST_LOG_STRING = "{\"Event\":\"\"}"; - - Eventinfo * lf = *state; - lf->log = lf->full_log = strdup(TEST_LOG_STRING); - - expect_string(__wrap__mdebug2, formatted_msg, "Decoding JSON: '{\"win\":{\"system\":{}}}'"); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); -} - -void test_winevt_dec_execution_one_attribute(void ** state) { - const char * TEST_LOG_STRING = "{\"Event\":\"\"}"; - - Eventinfo * lf = *state; - lf->log = lf->full_log = strdup(TEST_LOG_STRING); - - expect_string(__wrap__mdebug2, formatted_msg, "Decoding JSON: '{\"win\":{\"system\":{\"processID\":\"1'"); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); -} - -void test_winevt_dec_provider_no_attributes(void ** state) { - const char * TEST_LOG_STRING = "{\"Event\":\"\"}"; - - Eventinfo * lf = *state; - lf->log = lf->full_log = strdup(TEST_LOG_STRING); - - expect_string(__wrap__mdebug2, formatted_msg, "Decoding JSON: '{\"win\":{\"system\":{}}}'"); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); -} - -void test_winevt_dec_provider(void ** state) { - const char * TEST_LOG_STRING = "{\"Event\":\"\"}"; - - Eventinfo * lf = *state; - lf->log = lf->full_log = strdup(TEST_LOG_STRING); - - expect_string(__wrap__mdebug2, formatted_msg, "Decoding JSON: '{\"win\":{\"system\":{}}}'"); - - int ret = DecodeWinevt(lf); - assert_int_equal(ret, SUCCESS_DECODE); -} - -int main() { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_winevt_dec_time_created_no_attributes, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_dec_execution_no_attributes, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_dec_execution_one_attribute, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_dec_provider_no_attributes, test_setup, test_cleanup), - cmocka_unit_test_setup_teardown(test_winevt_dec_provider, test_setup, test_cleanup), - }; - return cmocka_run_group_tests(tests, test_setup_global, NULL); -} diff --git a/src/unit_tests/analysisd/test_eventinfo_list.c b/src/unit_tests/analysisd/test_eventinfo_list.c deleted file mode 100644 index 98db36e376f..00000000000 --- a/src/unit_tests/analysisd/test_eventinfo_list.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../analysisd/eventinfo.h" -#include "../../analysisd/rules.h" - -void os_remove_eventlist(EventList *list); - -/* setup/teardown */ - - - -/* wraps */ - -void __wrap_Free_Eventinfo(Eventinfo *lf) { - return; -} - -/* tests */ - -/* os_remove_eventlist */ -void test_os_remove_eventlist_OK(void **state) -{ - EventList *list; - os_calloc(1,sizeof(EventList), list); - - os_calloc(1,sizeof(EventNode), list->first_node); - - os_remove_eventlist(list); - -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests os_remove_eventlist - cmocka_unit_test(test_os_remove_eventlist_OK) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} - diff --git a/src/unit_tests/analysisd/test_exec.c b/src/unit_tests/analysisd/test_exec.c deleted file mode 100644 index 3b9869f0e03..00000000000 --- a/src/unit_tests/analysisd/test_exec.c +++ /dev/null @@ -1,932 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/os_regex/os_regex_wrappers.h" -#include "../wrappers/wazuh/shared/labels_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" -#include "../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../../analysisd/eventinfo.h" -#include "../../analysisd/config.h" -#include "../../analysisd/alerts/exec.h" -#include "../../config/active-response.h" - -typedef struct test_struct { - Eventinfo *lf; - active_response *ar; -} test_struct_t; - -const char *get_ip(const Eventinfo *lf); - -// Setup / Teardown - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1, sizeof(test_struct_t), init_data); - os_calloc(1, sizeof(Eventinfo), init_data->lf); - os_calloc(1, sizeof(DynamicField), init_data->lf->fields); - os_calloc(1, sizeof(*init_data->lf->generated_rule), init_data->lf->generated_rule); - os_calloc(1, sizeof(OSDecoderInfo), init_data->lf->decoder_info); - os_calloc(1, sizeof(active_response), init_data->ar); - os_calloc(1, sizeof(*init_data->ar->ar_cmd), init_data->ar->ar_cmd); - - init_data->lf->fields[FIM_FILE].value = "/home/vagrant/file/n44.txt"; - init_data->lf->srcip = NULL; - init_data->lf->dstuser = NULL; - init_data->lf->time.tv_sec = 160987966; - init_data->lf->generated_rule->sigid = 554; - init_data->lf->location = "(ubuntu) any->syscheck"; - init_data->lf->agent_id = "001"; - init_data->lf->decoder_info->name = "syscheck_event"; - - init_data->ar->name = "restart-wazuh0"; - init_data->ar->ar_cmd->extra_args = NULL; - init_data->ar->location = 0; - init_data->ar->agent_id = "002"; - init_data->ar->command = "restart-wazuh"; - - *state = init_data; - - test_mode = 1; - - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_free(data->lf->decoder_info); - os_free(data->lf->generated_rule); - os_free(data->ar->ar_cmd); - os_free(data->lf->fields); - os_free(data->lf); - os_free(data->ar); - os_free(data); - - test_mode = 0; - - return OS_SUCCESS; -} - -// Wrappers - - -int __wrap_OS_ReadXML(const char *file, OS_XML *_lxml) { - return mock(); -} - -char* __wrap_OS_GetOneContentforElement(OS_XML *_lxml, const char **element_name) { - return mock_type(char *); -} - -void __wrap_OS_ClearXML(OS_XML *_lxml) { - return; -} - -char * __wrap_Eventinfo_to_jsonstr(__attribute__((unused)) const Eventinfo *lf, __attribute__((unused)) bool force_full_log) { - return mock_type(char*); -} - -static int test_setup_word_between_two_words(void **state) { - char *word = NULL; - *state = word; - return OS_SUCCESS; -} - -static int test_teardown_word_between_two_words(void **state) { - char *word = (char *)*state; - os_free(word); - return OS_SUCCESS; -} - -// Tests - -void test_server_success_json(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - data->ar->location = AS_ONLY; - - char *exec_msg = "{\"version\":1,\"origin\":{\"name\":\"node01\",\"module\":\"wazuh-analysisd\"},\"command\":\"restart-wazuh0\",\"parameters\":{\"extra_args\":[],\"alert\":[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]}}"; - const char *alert_info = "[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]"; - char *node = NULL; - - os_strdup("node01", node); - - Config.ar = 2; - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - expect_value(__wrap_OS_SendUnix, socket, execq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_all_agents_success_json_string(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version_1 = "Wazuh v4.2.0"; - char *version_2 = "Wazuh v4.0.0"; - data->ar->location = ALL_AGENTS; - - char *exec_msg_1 = "(local_source) [] NNS 003 {\"version\":1,\"origin\":{\"name\":\"node01\",\"module\":\"wazuh-analysisd\"},\"command\":\"restart-wazuh0\",\"parameters\":{\"extra_args\":[],\"alert\":[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]}}"; - const char *alert_info_1 = "[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]"; - char *node_1 = NULL; - - os_strdup("node01", node_1); - - char *exec_msg = "(local_source) [] NNS 005 restart-wazuh0 - - 160987966.80794 554 (ubuntu) any->syscheck /home/vagrant/file/n44.txt -"; - - Config.ar = 1; - __crt_ftell = 80794; - - int *array = NULL; - os_malloc(sizeof(int)*3, array); - array[0] = 3; - array[1] = 5; - array[2] = OS_INVALID; - - expect_string(__wrap_wdb_get_agents_by_connection_status, status, AGENT_CS_ACTIVE); - will_return(__wrap_wdb_get_agents_by_connection_status, array); - - // Alert 1 - - wlabel_t *labels_1 = NULL; - os_calloc(2, sizeof(wlabel_t), labels_1); - - os_strdup("_wazuh_version", labels_1[0].key); - os_strdup(version_1, labels_1[0].value); - - expect_string(__wrap_labels_find, agent_id, "003"); - will_return(__wrap_labels_find, labels_1); - - expect_string(__wrap_labels_get, key, labels_1->key); - will_return(__wrap_labels_get, labels_1->value); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info_1)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node_1); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg_1); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - // Alert 2 - - wlabel_t *labels_2 = NULL; - os_calloc(2, sizeof(wlabel_t), labels_2); - - os_strdup("_wazuh_version", labels_2[0].key); - os_strdup(version_2, labels_2[0].value); - - expect_string(__wrap_labels_find, agent_id, "005"); - will_return(__wrap_labels_find, labels_2); - - expect_string(__wrap_labels_get, key, labels_2->key); - will_return(__wrap_labels_get, labels_2->value); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_all_agents_success_json_string_wdb(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version_1 = "Wazuh v4.2.0"; - char *version_2 = "Wazuh v4.0.0"; - data->ar->location = ALL_AGENTS; - - cJSON *agent_info_array_1 = cJSON_CreateArray(); - cJSON *agent_info_1 = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info_1, "version", version_1); - cJSON_AddItemToArray(agent_info_array_1, agent_info_1); - - char *exec_msg_1 = "(local_source) [] NNS 003 {\"version\":1,\"origin\":{\"name\":\"node01\",\"module\":\"wazuh-analysisd\"},\"command\":\"restart-wazuh0\",\"parameters\":{\"extra_args\":[],\"alert\":[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]}}"; - const char *alert_info_1 = "[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]"; - char *node_1 = NULL; - - os_strdup("node01", node_1); - - cJSON *agent_info_array_2 = cJSON_CreateArray(); - cJSON *agent_info_2 = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info_2, "version", version_2); - cJSON_AddItemToArray(agent_info_array_2, agent_info_2); - - char *exec_msg = "(local_source) [] NNS 005 restart-wazuh0 - - 160987966.80794 554 (ubuntu) any->syscheck /home/vagrant/file/n44.txt -"; - - Config.ar = 1; - __crt_ftell = 80794; - - int *array = NULL; - os_malloc(sizeof(int)*3, array); - array[0] = 3; - array[1] = 5; - array[2] = OS_INVALID; - - expect_string(__wrap_wdb_get_agents_by_connection_status, status, AGENT_CS_ACTIVE); - will_return(__wrap_wdb_get_agents_by_connection_status, array); - - // Alert 1 - - wlabel_t *labels_1 = NULL; - os_calloc(1, sizeof(wlabel_t), labels_1); - - expect_string(__wrap_labels_find, agent_id, "003"); - will_return(__wrap_labels_find, labels_1); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, array[0]); - will_return(__wrap_wdb_get_agent_info, agent_info_array_1); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info_1)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node_1); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg_1); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - // Alert 2 - - wlabel_t *labels_2 = NULL; - os_calloc(1, sizeof(wlabel_t), labels_2); - - expect_string(__wrap_labels_find, agent_id, "005"); - will_return(__wrap_labels_find, labels_2); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, array[1]); - will_return(__wrap_wdb_get_agent_info, agent_info_array_2); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_all_agents_success_fail_agt_info1(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - data->ar->location = ALL_AGENTS; - - Config.ar = 1; - - int *array = NULL; - os_malloc(sizeof(int)*3, array); - array[0] = 3; - array[1] = 5; - array[2] = OS_INVALID; - - expect_string(__wrap_wdb_get_agents_by_connection_status, status, AGENT_CS_ACTIVE); - will_return(__wrap_wdb_get_agents_by_connection_status, array); - - // Alert 1 - - wlabel_t *labels_1 = NULL; - os_calloc(1, sizeof(wlabel_t), labels_1); - - expect_string(__wrap_labels_find, agent_id, "003"); - will_return(__wrap_labels_find, labels_1); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, array[0]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_string(__wrap__merror, formatted_msg, "Failed to get agent '3' information from Wazuh DB."); - - // Alert 2 - - wlabel_t *labels_2 = NULL; - os_calloc(1, sizeof(wlabel_t), labels_2); - - expect_string(__wrap_labels_find, agent_id, "005"); - will_return(__wrap_labels_find, labels_2); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, array[1]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_string(__wrap__merror, formatted_msg, "Failed to get agent '5' information from Wazuh DB."); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_specific_agent_success_json(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.2.0"; - data->ar->location = SPECIFIC_AGENT; - - char *exec_msg = "(local_source) [] NNS 002 {\"version\":1,\"origin\":{\"name\":\"node01\",\"module\":\"wazuh-analysisd\"},\"command\":\"restart-wazuh0\",\"parameters\":{\"extra_args\":[],\"alert\":[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]}}"; - const char *alert_info = "[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]"; - char *node = NULL; - - os_strdup("node01", node); - - Config.ar = 1; - - wlabel_t *labels = NULL; - os_calloc(2, sizeof(wlabel_t), labels); - - os_strdup("_wazuh_version", labels[0].key); - os_strdup(version, labels[0].value); - - expect_string(__wrap_labels_find, agent_id, "002"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, labels->key); - will_return(__wrap_labels_get, labels->value); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_specific_agent_success_json_wdb(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.2.0"; - data->ar->location = SPECIFIC_AGENT; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddItemToArray(agent_info_array, agent_info); - - char *exec_msg = "(local_source) [] NNS 002 {\"version\":1,\"origin\":{\"name\":\"node01\",\"module\":\"wazuh-analysisd\"},\"command\":\"restart-wazuh0\",\"parameters\":{\"extra_args\":[],\"alert\":[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]}}"; - const char *alert_info = "[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]"; - char *node = NULL; - - os_strdup("node01", node); - - Config.ar = 1; - - wlabel_t *labels = NULL; - os_calloc(1, sizeof(wlabel_t), labels); - - expect_string(__wrap_labels_find, agent_id, "002"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, atoi(data->ar->agent_id)); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_specific_agent_success_string(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.0.0"; - data->ar->location = SPECIFIC_AGENT; - - char *exec_msg = "(local_source) [] NNS 002 restart-wazuh0 - - 160987966.80794 554 (ubuntu) any->syscheck /home/vagrant/file/n44.txt -"; - - Config.ar = 1; - __crt_ftell = 80794; - - wlabel_t *labels = NULL; - os_calloc(2, sizeof(wlabel_t), labels); - - os_strdup("_wazuh_version", labels[0].key); - os_strdup(version, labels[0].value); - - expect_string(__wrap_labels_find, agent_id, "002"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, labels->key); - will_return(__wrap_labels_get, labels->value); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_specific_agent_success_string_wdb(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.0.0"; - data->ar->location = SPECIFIC_AGENT; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddItemToArray(agent_info_array, agent_info); - - char *exec_msg = "(local_source) [] NNS 002 restart-wazuh0 - - 160987966.80794 554 (ubuntu) any->syscheck /home/vagrant/file/n44.txt -"; - - Config.ar = 1; - __crt_ftell = 80794; - - wlabel_t *labels = NULL; - os_calloc(1, sizeof(wlabel_t), labels); - - expect_string(__wrap_labels_find, agent_id, "002"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, atoi(data->ar->agent_id)); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_specific_agent_success_fail_agt_info1(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - data->ar->location = SPECIFIC_AGENT; - - Config.ar = 1; - - wlabel_t *labels = NULL; - os_calloc(1, sizeof(wlabel_t), labels); - - expect_string(__wrap_labels_find, agent_id, "002"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, atoi(data->ar->agent_id)); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_string(__wrap__merror, formatted_msg, "Failed to get agent '2' information from Wazuh DB."); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_remote_agent_success_json(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.2.0"; - data->ar->location = REMOTE_AGENT; - - char *exec_msg = "(local_source) [] NRN 001 {\"version\":1,\"origin\":{\"name\":\"node01\",\"module\":\"wazuh-analysisd\"},\"command\":\"restart-wazuh0\",\"parameters\":{\"extra_args\":[],\"alert\":[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]}}"; - const char *alert_info = "[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]"; - char *node = NULL; - - os_strdup("node01", node); - - Config.ar = 1; - - wlabel_t *labels = NULL; - os_calloc(2, sizeof(wlabel_t), labels); - - os_strdup("_wazuh_version", labels[0].key); - os_strdup(version, labels[0].value); - - expect_string(__wrap_labels_find, agent_id, "001"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, labels->key); - will_return(__wrap_labels_get, labels->value); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_remote_agent_success_json_wdb(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.2.0"; - data->ar->location = REMOTE_AGENT; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddItemToArray(agent_info_array, agent_info); - - char *exec_msg = "(local_source) [] NRN 001 {\"version\":1,\"origin\":{\"name\":\"node01\",\"module\":\"wazuh-analysisd\"},\"command\":\"restart-wazuh0\",\"parameters\":{\"extra_args\":[],\"alert\":[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]}}"; - const char *alert_info = "[{\"timestamp\":\"2021-01-05T15:23:00.547+0000\",\"rule\":{\"level\":5,\"description\":\"File added to the system.\",\"id\":\"554\"}}]"; - char *node = NULL; - - os_strdup("node01", node); - - Config.ar = 1; - - wlabel_t *labels = NULL; - os_calloc(1, sizeof(wlabel_t), labels); - - expect_string(__wrap_labels_find, agent_id, "001"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, atoi(data->lf->agent_id)); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_remote_agent_success_string(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.0.0"; - data->ar->location = REMOTE_AGENT; - - char *exec_msg = "(local_source) [] NRN 001 restart-wazuh0 - - 160987966.80794 554 (ubuntu) any->syscheck /home/vagrant/file/n44.txt -"; - - Config.ar = 1; - __crt_ftell = 80794; - - wlabel_t *labels = NULL; - os_calloc(2, sizeof(wlabel_t), labels); - - os_strdup("_wazuh_version", labels[0].key); - os_strdup(version, labels[0].value); - - expect_string(__wrap_labels_find, agent_id, "001"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, labels->key); - will_return(__wrap_labels_get, labels->value); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_remote_agent_success_string_wdb(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - char *version = "Wazuh v4.0.0"; - data->ar->location = REMOTE_AGENT; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddItemToArray(agent_info_array, agent_info); - - char *exec_msg = "(local_source) [] NRN 001 restart-wazuh0 - - 160987966.80794 554 (ubuntu) any->syscheck /home/vagrant/file/n44.txt -"; - - Config.ar = 1; - __crt_ftell = 80794; - - wlabel_t *labels = NULL; - os_calloc(1, sizeof(wlabel_t), labels); - - expect_string(__wrap_labels_find, agent_id, "001"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, atoi(data->lf->agent_id)); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - expect_value(__wrap_OS_SendUnix, socket, arq); - expect_string(__wrap_OS_SendUnix, msg, exec_msg); - expect_value(__wrap_OS_SendUnix, size, 0); - will_return(__wrap_OS_SendUnix, 1); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_remote_agent_success_fail_agt_info1(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - int execq = 10; - int arq = 11; - int sock = -1; - - data->ar->location = REMOTE_AGENT; - - Config.ar = 1; - - wlabel_t *labels = NULL; - os_calloc(1, sizeof(wlabel_t), labels); - - expect_string(__wrap_labels_find, agent_id, "001"); - will_return(__wrap_labels_find, labels); - - expect_string(__wrap_labels_get, key, "_wazuh_version"); - will_return(__wrap_labels_get, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, atoi(data->lf->agent_id)); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_string(__wrap__merror, formatted_msg, "Failed to get agent '1' information from Wazuh DB."); - - OS_Exec(&execq, &arq, &sock, data->lf, data->ar); -} - -void test_getActiveResponseInJSON_extra_args(void **state){ - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_msj = NULL; - - char * msg; - char *c_device = NULL; - const char *alert_info = "[{\"test\":\"test\"}]"; - char *extra_args = "-arg1 --arg2 arg3 ; cat /etc/passwd"; - char *result = "[\"-arg1\",\"--arg2\",\"arg3\",\";\",\"cat\",\"/etc/passwd\"]"; - char *node = NULL; - - os_malloc(OS_MAXSTR + 1, msg); - os_strdup("node01", node); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup(alert_info)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - getActiveResponseInJSON(data->lf, data->ar, extra_args, msg, false); - - cJSON * root = cJSON_Parse(msg); - cJSON * deviceData = cJSON_GetObjectItem(root,"parameters"); - if(deviceData) { - cJSON *device = deviceData->child; - if(device) { - c_device = cJSON_PrintUnformatted(device); - } - } - cJSON_Delete(root); - - assert_string_equal(c_device, result); - - os_free(c_device); - os_free(msg); -} - -void test_send_exec_msg(void **state){ - int socket = 10; - char *queue_path = "/path/to/queue"; - char *exec_msg = "Message"; - - expect_OS_SendUnix_call(socket, exec_msg, 0, 0); - - send_exec_msg(&socket, queue_path, exec_msg); -} - -void test_send_exec_msg_reconnect_socket(void **state){ - int socket = -1; - int new_socket = 1; - char *queue_path = "/path/to/queue"; - char *exec_msg = "Message"; - - expect_StartMQ_call(queue_path, WRITE, new_socket); - expect_OS_SendUnix_call(new_socket, exec_msg, 0, 0); - - send_exec_msg(&socket, queue_path, exec_msg); -} - -void test_send_exec_msg_reconnect_socket_fail(void **state){ - int socket = -1; - char *queue_path = "/path/to/queue"; - char *exec_msg = "Message"; - errno = 1; - - expect_StartMQ_call(queue_path, WRITE, -1); - expect_string(__wrap__merror, formatted_msg, "(1210): Queue '/path/to/queue' not accessible: 'Operation not permitted'"); - - send_exec_msg(&socket, queue_path, exec_msg); -} - -void test_send_exec_msg_OS_SOCKBUSY(void **state){ - int socket = 10; - char *queue_path = "/path/to/queue"; - char *exec_msg = "Message"; - - expect_OS_SendUnix_call(socket, exec_msg, 0, OS_SOCKBUSY); - expect_string(__wrap__merror, formatted_msg, "(1322): Socket busy."); - expect_string(__wrap__merror, formatted_msg, "(1321): Error communicating with queue '/path/to/queue'."); - - send_exec_msg(&socket, queue_path, exec_msg); -} - -void test_send_exec_msg_OS_TIMEOUT(void **state){ - int socket = 10; - char *queue_path = "/path/to/queue"; - char *exec_msg = "Message"; - - expect_OS_SendUnix_call(socket, exec_msg, 0, OS_TIMEOUT); - expect_string(__wrap__merror, formatted_msg, "(1321): Error communicating with queue '/path/to/queue'."); - - send_exec_msg(&socket, queue_path, exec_msg); -} - -void test_get_ip_success(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - Config.white_list = (os_ip **)1; - Config.hostname_white_list = (OSMatch **) realloc(Config.hostname_white_list, sizeof(OSMatch *)*2); - os_calloc(1, sizeof(OSMatch), Config.hostname_white_list[0]); - Config.hostname_white_list[1] = NULL; - char *expected_ip = "192.168.0.100"; - data->lf->srcip = expected_ip; - - expect_string(__wrap_OS_IPFoundList, ip_address, expected_ip); - will_return(__wrap_OS_IPFoundList, 0); - - expect_string(__wrap_OSMatch_Execute, str, expected_ip); - will_return(__wrap_OSMatch_Execute, 0); - - assert_string_equal(expected_ip, get_ip(data->lf)); - - os_free(Config.hostname_white_list[0]); - os_free(Config.hostname_white_list); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // LOCAL - cmocka_unit_test_setup_teardown(test_server_success_json, test_setup, test_teardown), - - // ALL_AGENTS - cmocka_unit_test_setup_teardown(test_all_agents_success_json_string, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_all_agents_success_json_string_wdb, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_all_agents_success_fail_agt_info1, test_setup, test_teardown), - - // SPECIFIC_AGENT - cmocka_unit_test_setup_teardown(test_specific_agent_success_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_specific_agent_success_json_wdb, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_specific_agent_success_string, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_specific_agent_success_string_wdb, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_specific_agent_success_fail_agt_info1, test_setup, test_teardown), - - // REMOTE_AGENT - cmocka_unit_test_setup_teardown(test_remote_agent_success_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_remote_agent_success_json_wdb, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_remote_agent_success_string, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_remote_agent_success_string_wdb, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_remote_agent_success_fail_agt_info1, test_setup, test_teardown), - - // getActiveResponseInJSON - cmocka_unit_test_setup_teardown(test_getActiveResponseInJSON_extra_args, test_setup, test_teardown), - - // get_ip - cmocka_unit_test_setup_teardown(test_get_ip_success, test_setup, test_teardown), - - // send_exec_msg - cmocka_unit_test(test_send_exec_msg), - cmocka_unit_test(test_send_exec_msg_reconnect_socket), - cmocka_unit_test(test_send_exec_msg_reconnect_socket_fail), - cmocka_unit_test(test_send_exec_msg_OS_SOCKBUSY), - cmocka_unit_test(test_send_exec_msg_OS_TIMEOUT), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_labels.c b/src/unit_tests/analysisd/test_labels.c deleted file mode 100644 index 85707677a6e..00000000000 --- a/src/unit_tests/analysisd/test_labels.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" - -#include "../analysisd/config.h" -#include "../analysisd/labels.h" -#include "labels_op.h" - -/* setup/teardown */ - -static int setup_labels_context(void **state) { - labels_init(); - return OS_SUCCESS; -} - -static int teardown_labels_local(void **state) { - labels_finalize(); - return OS_SUCCESS; -} - -/* tests */ - -void test_labels_find_manager_no_labels(void **state) { - int sock = -1; - char *agent_id = "000"; - - wlabel_t *labels = labels_find(agent_id, &sock); - - assert_null(labels); -} - -void test_labels_find_manager_with_labels(void **state) { - int sock = -1; - char *agent_id = "000"; - wlabel_t *manager_labels = NULL; - - // Setting the manager's labels - os_calloc(1, sizeof(wlabel_t), manager_labels); - Config.labels = manager_labels; - - wlabel_t *labels = labels_find(agent_id, &sock); - - assert_ptr_equal(manager_labels, labels); - os_free(manager_labels); -} - -void test_labels_find_agent_no_labels(void **state) { - int sock = -1; - char *agent_id = "001"; - - // Requesting labels to Wazuh DB - expect_value(__wrap_wdb_get_agent_labels, id, 1); - will_return(__wrap_wdb_get_agent_labels, NULL); - - wlabel_t *labels = labels_find(agent_id, &sock); - - assert_null(labels); -} - -void test_labels_find_agent_with_labels(void **state) { - int sock = -1; - char *agent_id = "001"; - - // Creating a dummy set of labels - cJSON* array = cJSON_CreateArray(); - cJSON* label1 = cJSON_CreateObject(); - cJSON_AddStringToObject(label1, "key", "#\"_system_label\""); - cJSON_AddStringToObject(label1, "value", "system_value"); - cJSON_AddItemToArray(array, label1); - cJSON* label2 = cJSON_CreateObject(); - cJSON_AddStringToObject(label2, "key", "!\"_hidden_label\""); - cJSON_AddStringToObject(label2, "value", "hidden_value"); - cJSON_AddItemToArray(array, label2); - cJSON* label3 = cJSON_CreateObject(); - cJSON_AddStringToObject(label3, "key", "\"label\""); - cJSON_AddStringToObject(label3, "value", "value"); - cJSON_AddItemToArray(array, label3); - - // Requesting labels to Wazuh DB - expect_value(__wrap_wdb_get_agent_labels, id, 1); - will_return(__wrap_wdb_get_agent_labels, array); - - wlabel_t *labels = labels_find(agent_id, &sock); - - assert_non_null(labels); - assert_string_equal("system_value", labels_get(labels, "_system_label")); - assert_string_equal("hidden_value", labels_get(labels, "_hidden_label")); - assert_string_equal("value", labels_get(labels, "label")); - labels_free(labels); -} - -int main(void) { - const struct CMUnitTest tests[] = { - /* dispatch_send_local */ - cmocka_unit_test_setup_teardown(test_labels_find_manager_no_labels, setup_labels_context, teardown_labels_local), - cmocka_unit_test_setup_teardown(test_labels_find_manager_with_labels, setup_labels_context, teardown_labels_local), - cmocka_unit_test_setup_teardown(test_labels_find_agent_no_labels, setup_labels_context, teardown_labels_local), - cmocka_unit_test_setup_teardown(test_labels_find_agent_with_labels, setup_labels_context, teardown_labels_local) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_limits.c b/src/unit_tests/analysisd/test_limits.c deleted file mode 100644 index 1d52a9927da..00000000000 --- a/src/unit_tests/analysisd/test_limits.c +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../analysisd/limits.h" - -extern sem_t credits_eps_semaphore; -extern limits_t limits; - -void generate_eps_credits(unsigned int credits); -void increase_event_counter(void); - -// Setup / Teardown - -static int test_setup(void **state) { - memset(&limits, 0, sizeof(limits)); - limits.enabled = true; - limits.timeframe = 10; - limits.eps = 10; - os_calloc(limits.timeframe, sizeof(unsigned int), limits.circ_buf); - - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - if (limits.circ_buf) { - os_free(limits.circ_buf); - } - memset(&limits, 0, sizeof(limits)); - return OS_SUCCESS; -} - -/* Tests */ - -// generate_eps_credits -void test_generate_eps_credits_ok(void ** state) -{ - int current_credits; - sem_init(&credits_eps_semaphore, 0, 0); - - generate_eps_credits(5); - - sem_getvalue(&credits_eps_semaphore, ¤t_credits); - assert_int_equal(5, current_credits); - sem_destroy(&credits_eps_semaphore); -} - -void test_generate_eps_credits_ok_zero(void ** state) -{ - int current_credits; - sem_init(&credits_eps_semaphore, 0, 0); - - generate_eps_credits(0); - - sem_getvalue(&credits_eps_semaphore, ¤t_credits); - assert_int_equal(0, current_credits); - sem_destroy(&credits_eps_semaphore); -} - -// increase_event_counter -void test_increase_event_counter_ok(void ** state) -{ - limits.current_cell = 0; - assert_int_equal(0, limits.circ_buf[limits.current_cell]); - increase_event_counter(); - assert_int_equal(1, limits.circ_buf[limits.current_cell]); -} - -// limit_reached -void test_limit_reached_disabled(void ** state) -{ - limits.enabled = false; - - bool result = limit_reached(NULL); - - assert_false(result); -} - -void test_limit_reached_enabled_non_zero(void ** state) -{ - limits.enabled = true; - sem_init(&credits_eps_semaphore, 0, 5); - - bool result = limit_reached(NULL); - - assert_false(result); - sem_destroy(&credits_eps_semaphore); -} - -void test_limit_reached_enabled_non_zero_value(void ** state) -{ - int credits = 0; - limits.enabled = true; - sem_init(&credits_eps_semaphore, 0, 5); - - bool result = limit_reached(&credits); - - assert_false(result); - assert_int_equal(credits, 5); - sem_destroy(&credits_eps_semaphore); -} - -void test_limit_reached_enabled_zero(void ** state) -{ - limits.enabled = true; - sem_init(&credits_eps_semaphore, 0, 0); - - bool result = limit_reached(NULL); - - assert_true(result); - sem_destroy(&credits_eps_semaphore); -} - -void test_limit_reached_enabled_zero_value(void ** state) -{ - int credits = 0; - limits.enabled = true; - sem_init(&credits_eps_semaphore, 0, 0); - - bool result = limit_reached(&credits); - - assert_true(result); - assert_int_equal(credits, 0); - sem_destroy(&credits_eps_semaphore); -} - -// get_eps_credit -void test_get_eps_credit_ok(void ** state) -{ - int current_credits; - sem_init(&credits_eps_semaphore, 0, 5); - - get_eps_credit(); - - sem_getvalue(&credits_eps_semaphore, ¤t_credits); - assert_int_equal(4, current_credits); - assert_int_equal(1, limits.circ_buf[limits.current_cell]); - sem_destroy(&credits_eps_semaphore); -} - -// load_limits -void test_load_limits_disabled(void ** state) -{ - int current_credits; - limits.enabled = false; - - expect_string(__wrap__minfo, formatted_msg, "EPS limit disabled"); - - load_limits(0, 5, true); - - assert_false(limits.enabled); -} - -// load_limits -void test_load_limits_maximun_block_not_found(void ** state) -{ - int current_credits; - limits.enabled = false; - - expect_string(__wrap__mwarn, formatted_msg, "EPS limit disabled. The maximum value is missing in the configuration block."); - - load_limits(0, 5, false); - - assert_false(limits.enabled); -} - -void test_load_limits_timeframe_zero(void ** state) -{ - int current_credits; - limits.enabled = false; - - expect_string(__wrap__minfo, formatted_msg, "EPS limit disabled"); - - load_limits(100, 0, true); - - assert_false(limits.enabled); -} - -void test_load_limits_ok(void ** state) -{ - int current_credits; - limits.enabled = false; - - expect_string(__wrap__minfo, formatted_msg, "EPS limit enabled, EPS: '100', timeframe: '5'"); - - load_limits(100, 5, true); - - assert_int_equal(limits.eps, 100); - assert_int_equal(limits.timeframe, 5); - assert_true(limits.enabled); - sem_getvalue(&credits_eps_semaphore, ¤t_credits); - assert_int_equal(500, current_credits); - sem_destroy(&credits_eps_semaphore); -} - -// update_limits -void test_update_limits_current_cell_less_than_timeframe(void ** state) -{ - limits.current_cell = 5; - limits.circ_buf[0] = 5; - limits.circ_buf[1] = 10; - limits.circ_buf[limits.current_cell] = 25; - - update_limits(); - - assert_int_equal(limits.eps, 10); - assert_int_equal(limits.timeframe, 10); - assert_int_equal(limits.current_cell, 6); - assert_int_equal(limits.circ_buf[0], 5); - assert_int_equal(limits.circ_buf[1], 10); - assert_int_equal(limits.circ_buf[limits.current_cell - 1], 25); - assert_int_equal(limits.circ_buf[limits.current_cell], 0); -} - -void test_update_limits_current_cell_timeframe_limit(void ** state) -{ - limits.current_cell = limits.timeframe - 1; - limits.circ_buf[0] = 5; - limits.circ_buf[1] = 10; - limits.circ_buf[limits.current_cell] = 25; - - update_limits(); - - assert_int_equal(limits.eps, 10); - assert_int_equal(limits.timeframe, 10); - assert_int_equal(limits.current_cell, limits.timeframe - 1); - assert_int_equal(limits.circ_buf[0], 10); - assert_int_equal(limits.circ_buf[1], 0); - assert_int_equal(limits.circ_buf[limits.current_cell - 1], 25); - assert_int_equal(limits.circ_buf[limits.current_cell], 0); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests generate_eps_credits - cmocka_unit_test(test_generate_eps_credits_ok), - cmocka_unit_test(test_generate_eps_credits_ok_zero), - // Test increase_event_counter - cmocka_unit_test_setup_teardown(test_increase_event_counter_ok, test_setup, test_teardown), - // Test limit_reached - cmocka_unit_test(test_limit_reached_disabled), - cmocka_unit_test(test_limit_reached_enabled_non_zero), - cmocka_unit_test(test_limit_reached_enabled_non_zero_value), - cmocka_unit_test(test_limit_reached_enabled_zero), - cmocka_unit_test(test_limit_reached_enabled_zero_value), - // Test get_eps_credit - cmocka_unit_test_setup_teardown(test_get_eps_credit_ok, test_setup, test_teardown), - // Test load_limits - cmocka_unit_test_teardown(test_load_limits_disabled, test_teardown), - cmocka_unit_test_teardown(test_load_limits_maximun_block_not_found, test_teardown), - cmocka_unit_test_teardown(test_load_limits_timeframe_zero, test_teardown), - cmocka_unit_test_teardown(test_load_limits_ok, test_teardown), - // // Test update_limits - cmocka_unit_test_setup_teardown(test_update_limits_current_cell_less_than_timeframe, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_update_limits_current_cell_timeframe_limit, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_lists_list.c b/src/unit_tests/analysisd/test_lists_list.c deleted file mode 100644 index 3ee0131c3f2..00000000000 --- a/src/unit_tests/analysisd/test_lists_list.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../analysisd/rules.h" -#include "../../analysisd/cdb/cdb.h" -#include "../../analysisd/analysisd.h" -#include -#include -#include -#include - -void os_remove_cdblist(ListNode **l_node); -void os_remove_cdbrules(ListRule **l_rule); -ListNode *OS_FindList(const char *listname, ListNode **l_node); -void OS_ListLoadRules(ListNode **l_node, ListRule **lrule); - -/* setup/teardown */ - - - -/* wraps */ - -void __wrap_OSMatch_FreePattern(OSMatch *reg) { - return; -} - -/* tests */ - -/* os_remove_cdblist */ -void test_os_remove_cdblist_OK(void **state) -{ - ListNode *l_node; - os_calloc(1,sizeof(ListNode), l_node); - os_calloc(1,sizeof(ListNode), l_node->cdb_filename); - os_calloc(1,sizeof(char*), l_node->txt_filename); - - os_remove_cdblist(&l_node); - -} - -/* os_remove_cdbrules */ -void test_os_remove_cdbrules_OK(void **state) -{ - ListRule *l_rule; - os_calloc(1,sizeof(ListRule), l_rule); - os_calloc(1,sizeof(ListRule), l_rule->matcher); - os_calloc(1,sizeof(char*), l_rule->dfield); - os_calloc(1,sizeof(char*), l_rule->filename); - os_remove_cdbrules(&l_rule); - -} - -/* OS_FindList */ -void test_OS_FindList_dont_match(void ** state) { - - const char list[] = "list_test.cbd"; - ListNode * node; - ListNode * retval; - - os_calloc(1, sizeof(ListNode), node); - node->next = NULL; - node->txt_filename = "not_list_test.cbd"; - node->cdb_filename = "not_2_list_test.cbd"; - - retval = OS_FindList(list, &node); - - assert_null(retval); - - os_free(node); -} - -void test_OS_FindList_empty_node(void ** state) { - - const char list[] = "list_test.cbd"; - ListNode * node = NULL; - ListNode * retval; - - retval = OS_FindList(list, &node); - - assert_null(retval); -} - -void test_OS_FindList_txt_match(void ** state) { - - const char list[] = "list_test.cbd"; - ListNode * node; - os_calloc(1, sizeof(ListNode), node); - ListNode * retval; - const ListNode * expect_retval = node; - - node->next = NULL; - node->txt_filename = "list_test.cbd"; - node->cdb_filename = "not_2_list_test.cbd"; - - retval = OS_FindList(list, &node); - - assert_non_null(retval); - assert_ptr_equal(retval, expect_retval); - - os_free(node); -} - -void test_OS_FindList_cdb_match(void ** state) { - - const char list[] = "list_test.cbd"; - ListNode * node; - os_calloc(1, sizeof(ListNode), node); - ListNode * retval; - const ListNode * expect_retval = node; - - node->next = NULL; - node->txt_filename = "_not_list_test.cbd"; - node->cdb_filename = "list_test.cbd"; - - retval = OS_FindList(list, &node); - - assert_non_null(retval); - assert_ptr_equal(retval, expect_retval); - - os_free(node); -} - -/* OS_ListLoadRules */ -void test_OS_ListLoadRules_rule_null_check(void ** state) { - ListNode * l_node = (ListNode *) 1; - ListRule * lrule = NULL; - - OS_ListLoadRules(&l_node, &lrule); -} - -void test_OS_ListLoadRules_list_checked(void ** state) { - ListRule * lrule; - ListRule * firstrule; - ListNode * l_node = NULL; - - os_calloc(1, sizeof(ListRule), lrule); - firstrule = lrule; - lrule->next = NULL; - lrule->loaded = 0; - lrule->filename = strdup("test_file"); - - OS_ListLoadRules(&l_node, &lrule); - - assert_int_equal(firstrule->loaded, 1); - os_free(firstrule->filename); - os_free(firstrule); -} - -void test_OS_ListLoadRules_list_checked_and_load (void ** state) { - ListRule * lrule; - ListRule * firstrule; - ListNode * l_node = NULL; - - os_calloc(1, sizeof(ListRule), lrule); - firstrule = lrule; - lrule->next = NULL; - lrule->loaded = 0; - lrule->filename = strdup("list_test.cbd"); - - /* OS_FindList */ - ListNode * node; - os_calloc(1, sizeof(ListNode), node); - - node->next = NULL; - node->txt_filename = "_not_list_test.cbd"; - node->cdb_filename = "list_test.cbd"; - - OS_ListLoadRules(&node, &lrule); - - assert_int_equal(firstrule->loaded, 1); - os_free(firstrule->filename); - os_free(firstrule); - os_free(node); -} - -void test_OS_ListLoadRules_already_load(void ** state) { - ListRule * lrule; - ListRule * firstrule; - ListNode * l_node = NULL; - - os_calloc(1, sizeof(ListRule), lrule); - firstrule = lrule; - lrule->next = NULL; - lrule->loaded = 1; - - OS_ListLoadRules(&l_node, &lrule); - - assert_int_equal(firstrule->loaded, 1); - os_free(firstrule); - os_free(lrule); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests os_remove_cdblist - cmocka_unit_test(test_os_remove_cdblist_OK), - // Tests os_remove_cdbrules - cmocka_unit_test(test_os_remove_cdbrules_OK), - // Tests OS_FindList - cmocka_unit_test(test_OS_FindList_dont_match), - cmocka_unit_test(test_OS_FindList_empty_node), - cmocka_unit_test(test_OS_FindList_cdb_match), - cmocka_unit_test(test_OS_FindList_txt_match), - // Tests OS_ListLoadRules - cmocka_unit_test(test_OS_ListLoadRules_rule_null_check), - cmocka_unit_test(test_OS_ListLoadRules_list_checked), - cmocka_unit_test(test_OS_ListLoadRules_list_checked_and_load), - cmocka_unit_test(test_OS_ListLoadRules_already_load), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_log.c b/src/unit_tests/analysisd/test_log.c deleted file mode 100644 index 8ca4124e728..00000000000 --- a/src/unit_tests/analysisd/test_log.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/posix/time_wrappers.h" -#include "../../analysisd/alerts/log.h" -#include "../../headers/syscheck_op.h" - -extern int test_mode; -extern FILE *_aflog; - -// Setup / Teardown -DynamicField df[] = { - [FIM_FILE] = {.key = "fim_file", .value = "/path/to/file"}, - [FIM_HARD_LINKS] = {.key = "fim_hard_links", .value = "/link/to/file"}, - [FIM_MODE] = {.key = "fim_mode", .value = "whodata"}, - [FIM_SIZE] = {.key = "fim_size", .value = "5000"}, - [FIM_SIZE_BEFORE] = {.key = "fim_size_before", .value = "4000"}, - [FIM_PERM] = {.key = "fim_perm", .value = "permission"}, - [FIM_PERM_BEFORE] = {.key = "fim_perm_before", .value = "permission_before"}, - [FIM_UID] = {.key = "fim_uid", .value = "1000"}, - [FIM_UID_BEFORE] = {.key = "fim_uid_before", .value = "999"}, - [FIM_GID] = {.key = "fim_gid", .value = "1000"}, - [FIM_GID_BEFORE] = {.key = "fim_gid_before", .value = "999"}, - [FIM_MD5] = {.key = "fim_md5", .value = "12345"}, - [FIM_MD5_BEFORE] = {.key = "fim_md5_before", .value = "54321"}, - [FIM_SHA1] = {.key = "fim_sha1", .value = "12345"}, - [FIM_SHA1_BEFORE] = {.key = "fim_sha1_before", .value = "54321"}, - [FIM_UNAME] = {.key = "fim_uname", .value = "user"}, - [FIM_UNAME_BEFORE] = {.key = "fim_uname_before", .value = "user_before"}, - [FIM_GNAME] = {.key = "fim_gname", .value = "group"}, - [FIM_GNAME_BEFORE] = {.key = "fim_gname_before", .value = "group_before"}, - [FIM_MTIME] = {.key = "fim_mtime", .value = "12345678"}, - [FIM_MTIME_BEFORE] = {.key = "fim_mtime_before", .value = "87654321"}, - [FIM_INODE] = {.key = "fim_inode", .value = "2222"}, - [FIM_INODE_BEFORE] = {.key = "fim_inode_before", .value = "1111"}, - [FIM_SHA256] = {.key = "fim_sha256", .value = "12345"}, - [FIM_SHA256_BEFORE] = {.key = "fim_sha256_before", .value = "54321"}, - [FIM_DIFF] = {.key = "fim_diff", .value = "diff"}, - [FIM_ATTRS] = {.key = "fim_attrs", .value = "attributes"}, - [FIM_ATTRS_BEFORE] = {.key = "fim_attrs_before", .value = "attributes_before"}, - [FIM_CHFIELDS] = {.key = "fim_chfields", .value = "changed_fields"}, - [FIM_USER_ID] = {.key = "fim_userid", .value = "2000"}, - [FIM_USER_NAME] = {.key = "fim_username", .value = "user_name"}, - [FIM_GROUP_ID] = {.key = "fim_groupid", .value = "2000"}, - [FIM_GROUP_NAME] = {.key = "fim_groupname", .value = "group_name"}, - [FIM_PROC_NAME] = {.key = "fim_proc_name", .value = "proc_name"}, - [FIM_PROC_PNAME] = {.key = "fim_proc_pname", .value = "proc_pname"}, - [FIM_AUDIT_CWD] = {.key = "fim_audit_cwd", .value = "/audit/cwd"}, - [FIM_AUDIT_PCWD] = {.key = "fim_audit_pcwd", .value = "/audit/pcwd"}, - [FIM_AUDIT_ID] = {.key = "fim_audit_id", .value = "6789"}, - [FIM_AUDIT_NAME] = {.key = "fim_audit_name", .value = "audit_name"}, - [FIM_EFFECTIVE_UID] = {.key = "fim_effective_uid", .value = "effective_uid"}, - [FIM_EFFECTIVE_NAME] = {.key = "fim_effective_name", .value = "effective_name"}, - [FIM_PPID] = {.key = "fim_ppid", .value = "ppid"}, - [FIM_PROC_ID] = {.key = "fim_proc_id", .value = "proc_id"}, - [FIM_TAG] = {.key = "fim_tag", .value = "tag1,tag2"}, - [FIM_SYM_PATH] = {.key = "fim_sym_path", .value = "/sym/path"}, - [FIM_REGISTRY_ARCH] = {.key = "fim_registry_arch", .value = "[x64]"}, - [FIM_REGISTRY_VALUE_NAME] = {.key = "fim_registry_value_name", .value = "value_name"}, - [FIM_REGISTRY_VALUE_TYPE] = {.key = "fim_registry_value_type", .value = "binary"}, - [FIM_REGISTRY_HASH] = {.key = "hash_full_path", .value = "ff03d79932df0148efa6a066552badf25ea9c466"}, - [FIM_ENTRY_TYPE] = {.key = "fim_entry_type", .value = "registry"}, - [FIM_EVENT_TYPE] = {.key = "fim_event_type", .value = "modified"} -}; - - -static int test_setup(void **state) { - Eventinfo *lf = NULL; - os_calloc(1, sizeof(Eventinfo), lf); - os_calloc(2, sizeof(wlabel_t), lf->labels); - os_calloc(3, sizeof(char *), lf->last_events); - os_calloc(1, sizeof(RuleInfo), lf->generated_rule); - os_calloc(1, sizeof(OSDecoderInfo), lf->decoder_info); - - lf->labels[0].key = "key_label"; - lf->labels[0].value = "value_label"; - lf->labels[1].key = NULL; - lf->labels[1].value = NULL; - lf->nfields = FIM_NFIELDS; - lf->last_events[0] = "Last"; - lf->last_events[1] = "event"; - lf->last_events[2] = NULL; - lf->year = 2000; - lf->mon[0] = 'm'; - lf->mon[1] = '\0'; - lf->day = 1; - lf->hour[0] = 'h'; - lf->hour[1] = '\0'; - lf->generated_rule->sigid = 554; - lf->generated_rule->level = 123; - lf->generated_rule->group = "rule_group"; - lf->time.tv_sec = 160987966; - lf->full_log = "full_log"; - lf->comment = "comment"; - lf->hostname = "hostname"; - lf->fields = df; - lf->decoder_info->name = "non_syscheck_event"; - lf->location = "no-syscheck"; - - test_mode = 1; - *state = lf; - - return 0; -} - -static int test_teardown(void **state) { - Eventinfo *lf = *state; - - os_free(lf->decoder_info); - os_free(lf->labels); - os_free(lf->last_events); - os_free(lf->generated_rule); - os_free(lf); - - test_mode = 0; - - return 0; -} - -// Tests - -void test_OS_Log_no_syscheck_event(void **state) { - Eventinfo *lf = *state; - char buffer[FIM_NFIELDS][60]; - FILE fp = { '\0' }; - - expect_fprintf(&fp, "** Alert 160987966.0: - rule_group\n" - "2000 m 01 h hostname->no-syscheck\n" - "key_label: value_label\n" - "Rule: 554 (level 123) -> 'comment'\n" - "full_log\n", 0); - - for (int i = 0; i < lf->nfields; i++) { - snprintf(buffer[i], sizeof(buffer[i]), "%s: %s\n", df[i].key, df[i].value); - expect_fprintf(&fp, buffer[i], 0); - } - - expect_fprintf(&fp, "Last\n", 0); - expect_fprintf(&fp, "event\n", 0); - expect_value(__wrap_fputc, character, '\n'); - expect_value(__wrap_fputc, stream, &fp); - will_return(__wrap_fputc, 0); - - OS_Log(lf, &fp); -} - -void test_OS_Log_no_label_event(void **state) { - Eventinfo *lf = *state; - char buffer[FIM_NFIELDS][60]; - lf->labels[0].key = NULL; - lf->labels[0].value = NULL; - FILE fp = { '\0' }; - - expect_fprintf(&fp, "** Alert 160987966.0: - rule_group\n" - "2000 m 01 h hostname->no-syscheck\n" - "Rule: 554 (level 123) -> 'comment'\n" - "full_log\n", 0); - - for (int i = 0; i < lf->nfields; i++) { - snprintf(buffer[i], sizeof(buffer[i]), "%s: %s\n", df[i].key, df[i].value); - expect_fprintf(&fp, buffer[i], 0); - } - - expect_fprintf(&fp, "Last\n", 0); - expect_fprintf(&fp, "event\n", 0); - expect_value(__wrap_fputc, character, '\n'); - expect_value(__wrap_fputc, stream, &fp); - will_return(__wrap_fputc, 0); - - OS_Log(lf, &fp); -} - -void test_OS_Log_syscheck_event(void **state) { - Eventinfo *lf = *state; - lf->decoder_info->name = "syscheck_event"; - lf->location = "syscheck"; - lf->labels[0].key = "key_label"; - lf->labels[0].value = "value_label"; - FILE fp = { '\0' }; - - expect_fprintf(&fp, "** Alert 160987966.0: - rule_group\n" - "2000 m 01 h hostname->syscheck\n" - "key_label: value_label\n" - "Rule: 554 (level 123) -> 'comment'\n" - "full_log\n", 0); - - will_return(__wrap_fwrite, 13); // "Attributes:\n" - expect_fprintf(&fp, " - Size: 5000\n", 0); - expect_fprintf(&fp, " - Permissions: permission\n", 0); - - expect_any(__wrap_ctime_r, timep); - will_return(__wrap_ctime_r, "Sat May 23 21:21:18 1970\n"); - - expect_fprintf(&fp, " - Date: Sat May 23 21:21:18 1970\n", 0); - expect_fprintf(&fp, " - Inode: 2222\n", 0); - expect_fprintf(&fp, " - User: user (1000)\n", 0); - expect_fprintf(&fp, " - Group: group (1000)\n", 0); - expect_fprintf(&fp, " - MD5: 12345\n", 0); - expect_fprintf(&fp, " - SHA1: 12345\n", 0); - expect_fprintf(&fp, " - SHA256: 12345\n", 0); - expect_fprintf(&fp, " - File attributes: attributes\n", 0); - expect_fprintf(&fp, " - (Audit) User name: user_name\n", 0); - expect_fprintf(&fp, " - (Audit) Audit name: audit_name\n", 0); - expect_fprintf(&fp, " - (Audit) Effective name: effective_name\n", 0); - expect_fprintf(&fp, " - (Audit) Group name: group_name\n", 0); - expect_fprintf(&fp, " - (Audit) Process id: proc_id\n", 0); - expect_fprintf(&fp, " - (Audit) Process name: proc_name\n", 0); - expect_fprintf(&fp, " - (Audit) Process cwd: /audit/cwd\n", 0); - expect_fprintf(&fp, " - (Audit) Parent process name: proc_pname\n", 0); - expect_fprintf(&fp, " - (Audit) Parent process id: ppid\n", 0); - expect_fprintf(&fp, " - (Audit) Parent process cwd: /audit/pcwd\n", 0); - expect_fprintf(&fp, "\nWhat changed:\ndiff\n", 0); - will_return(__wrap_fwrite, 8); // "\nTags:\n" - expect_fprintf(&fp, " - tag1\n", 0); - expect_fprintf(&fp, " - tag2\n", 0); - expect_fprintf(&fp, "Last\n", 0); - expect_fprintf(&fp, "event\n", 0); - expect_value(__wrap_fputc, character, '\n'); - expect_value(__wrap_fputc, stream, &fp); - will_return(__wrap_fputc, 0); - - OS_Log(lf, &fp); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // OS_Log (Legacy function testing) - cmocka_unit_test(test_OS_Log_no_syscheck_event), - cmocka_unit_test(test_OS_Log_no_label_event), - cmocka_unit_test(test_OS_Log_syscheck_event) - }; - - return cmocka_run_group_tests(tests, test_setup, test_teardown); -} diff --git a/src/unit_tests/analysisd/test_logmsg.c b/src/unit_tests/analysisd/test_logmsg.c deleted file mode 100644 index 8c450a83014..00000000000 --- a/src/unit_tests/analysisd/test_logmsg.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../analysisd/logmsg.h" - -void _os_analysisd_add_logmsg(OSList * list, int level, int line, const char * func, - const char * file, char * msg, ...) __attribute__((nonnull)); -char * os_analysisd_string_log_msg(os_analysisd_log_msg_t * log_msg); -void os_analysisd_free_log_msg(os_analysisd_log_msg_t * log_msg); - -/* setup/teardown */ - - - -/* wraps */ - -int __wrap_isDebug() { - return mock(); -} - -void __wrap__mvinfo(const char * file, int line, const char * func, const char *msg, va_list args) { - function_called(); - return; -} - -void __wrap__mvwarn(const char * file, int line, const char * func, const char *msg, va_list args) { - function_called(); - return; -} - -void __wrap__mverror(const char * file, int line, const char * func, const char *msg, va_list args) { - function_called(); - return; -} - -void * __wrap_OSList_AddData(OSList *list, void *data) { - os_free(((os_analysisd_log_msg_t*)data)->msg); - os_free(((os_analysisd_log_msg_t*)data)->file); - os_free(((os_analysisd_log_msg_t*)data)->func); - os_free(data); - return mock_type(void *); -} - -int __wrap_vsnprintf(char *__restrict __s, size_t __maxlen, - const char *__restrict __format, ...) { - - check_expected(__format); - - return mock(); -} - -/* tests */ - -/* os_analysisd_free_log_msg */ - -void test_os_analysisd_free_log_msg_NULL(void **state) -{ - - os_analysisd_log_msg_t * message = NULL; - - os_analysisd_free_log_msg(message); - -} - -void test_os_analysisd_free_log_msg_OK(void **state) -{ - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - - message->level = LOGLEVEL_ERROR; - message->line = 500; - message->msg = strdup("Test Message"); - message->file = strdup("Test_file.c"); - message->func = strdup("TestFunction"); - - - os_analysisd_free_log_msg(message); - -} - -/* os_analysisd_string_log_msg */ -void test_os_analysisd_string_log_msg_NULL(void **state) -{ - char * retval = NULL; - - os_analysisd_log_msg_t * message = NULL; - - retval = os_analysisd_string_log_msg(message); - assert_null(retval); - -} - -void test_os_analysisd_string_log_msg_isDebug_false(void **state) -{ - char * retval = NULL; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - - message->level = LOGLEVEL_ERROR; - message->line = 500; - message->msg = strdup("Test Message"); - message->file = strdup("Test_file.c"); - message->func = strdup("TestFunction"); - - will_return(__wrap_isDebug, 0); - - retval = os_analysisd_string_log_msg(message); - assert_string_equal("Test Message", retval); - - os_free(message->file); - os_free(message->func); - os_free(message->msg); - os_free(message); - os_free(retval); - -} - -void test_os_analysisd_string_log_msg_isDebug_true(void **state) -{ - char * retval = NULL; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - - message->level = LOGLEVEL_ERROR; - message->line = 500; - message->msg = strdup("Test Message"); - message->file = strdup("Test_file.c"); - message->func = strdup("TestFunction"); - - will_return(__wrap_isDebug, 1); - - retval = os_analysisd_string_log_msg(message); - assert_string_equal("Test_file.c:500 at TestFunction(): Test Message", retval); - - os_free(message->file); - os_free(message->func); - os_free(message->msg); - os_free(message); - os_free(retval); - -} - -/* _os_analysisd_add_logmsg */ - -void test__os_analysisd_add_logmsg_OK(void **state) -{ - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - - message->level = LOGLEVEL_ERROR; - message->line = 500; - message->msg = strdup("Test Message"); - message->file = strdup("Test_file.c"); - message->func = strdup("TestFunction"); - - expect_string(__wrap_vsnprintf, __format, "Test Message"); - will_return(__wrap_vsnprintf, 0); - - will_return(__wrap_OSList_AddData,"test"); - - _os_analysisd_add_logmsg(list_msg, message->level, message->line, message->func, message->file, message->msg); - - os_free(message->file); - os_free(message->func); - os_free(message->msg); - os_free(list_msg); - os_free(message); -} - -void test__os_analysisd_add_logmsg_info(void ** state) { - - expect_function_call(__wrap__mvinfo); - _os_analysisd_add_logmsg(NULL, LOGLEVEL_INFO, 500, "TestFunction", "Test_file.c", "Test Message"); -} - -void test__os_analysisd_add_logmsg_warn(void ** state) { - - expect_function_call(__wrap__mvwarn); - _os_analysisd_add_logmsg(NULL, LOGLEVEL_WARNING, 500, "TestFunction", "Test_file.c", "Test Message"); -} - -void test__os_analysisd_add_logmsg_error(void ** state) { - - expect_function_call(__wrap__mverror); - _os_analysisd_add_logmsg(NULL, LOGLEVEL_ERROR, 500, "TestFunction", "Test_file.c", "Test Message"); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - //Test os_analysisd_free_log_msg - cmocka_unit_test(test_os_analysisd_free_log_msg_NULL), - cmocka_unit_test(test_os_analysisd_free_log_msg_OK), - //Test os_analysisd_string_log_msg - cmocka_unit_test(test_os_analysisd_string_log_msg_NULL), - cmocka_unit_test(test_os_analysisd_string_log_msg_isDebug_false), - cmocka_unit_test(test_os_analysisd_string_log_msg_isDebug_true), - //Test _os_analysisd_add_logmsg - cmocka_unit_test(test__os_analysisd_add_logmsg_OK), - cmocka_unit_test(test__os_analysisd_add_logmsg_info), - cmocka_unit_test(test__os_analysisd_add_logmsg_error), - cmocka_unit_test(test__os_analysisd_add_logmsg_warn), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_logtest-config.c b/src/unit_tests/analysisd/test_logtest-config.c deleted file mode 100644 index 7b7b628b7c4..00000000000 --- a/src/unit_tests/analysisd/test_logtest-config.c +++ /dev/null @@ -1,567 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../analysisd/logtest.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -int Read_Logtest(XML_NODE node); -cJSON *getRuleTestConfig(); - -/* setup/teardown */ - - - -/* wraps */ - -int __wrap_get_nproc(void) { - return mock(); -} - -cJSON * __wrap_cJSON_CreateObject(void) { - return mock_type(cJSON *); -} - -cJSON* __wrap_cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) { - if (name) check_expected(name); - if (string) check_expected(string); - return mock_type(cJSON *); -} - -cJSON* __wrap_cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) { - if (name) check_expected(name); - if (number) check_expected(number); - return mock_type(cJSON *); -} - - -void __wrap_cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { - if (string) check_expected(string); - if (item) check_expected(item); -} - -/* tests */ - -/* Read_Logtest */ - -void test_Read_Logtest_element_NULL(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = NULL; - nodes[0]->content = strdup("yes"); - - expect_string(__wrap__merror, formatted_msg, XML_ELEMNULL); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_content_NULL(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("enabled"); - nodes[0]->content = NULL; - - expect_string(__wrap__merror, formatted_msg, "(1234): Invalid NULL content for element: enabled."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_invalid_enabled(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("enabled"); - nodes[0]->content = strdup("test"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'enabled': test."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_valid_disabled(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("enabled"); - nodes[0]->content = strdup("no"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_valid_enabled(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("enabled"); - nodes[0]->content = strdup("yes"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_invalid_threads(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("threads"); - nodes[0]->content = strdup("test"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'threads': test."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_auto_threads(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("threads"); - nodes[0]->content = strdup("auto"); - - will_return(__wrap_get_nproc, 1); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_smaller_threads(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("threads"); - nodes[0]->content = strdup("-1"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'threads': -1."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_bigger_threads(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("threads"); - nodes[0]->content = strdup("1000000"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'threads': 1000000."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_limit_threads(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("threads"); - nodes[0]->content = strdup("256"); - - expect_string(__wrap__mwarn, formatted_msg, "(7000): Number of logtest threads too high. Only creates 128 threads"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_valid_threads(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("threads"); - nodes[0]->content = strdup("64"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_invalid_max_sessions(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("max_sessions"); - nodes[0]->content = strdup("test"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'max_sessions': test."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_smaller_max_sessions(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("max_sessions"); - nodes[0]->content = strdup("-1"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'max_sessions': -1."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_bigger_max_sessions(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("max_sessions"); - nodes[0]->content = strdup("1000000"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'max_sessions': 1000000."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_limit_max_sessions(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("max_sessions"); - nodes[0]->content = strdup("700"); - - expect_string(__wrap__mwarn, formatted_msg, "(7001): Number of maximum users connected in logtest too high. Only allows 500 users"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_valid_max_sessions(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("max_sessions"); - nodes[0]->content = strdup("200"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_invalid_session_timeout(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("session_timeout"); - nodes[0]->content = strdup("test"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'session_timeout': test."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_smaller_session_timeout(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("session_timeout"); - nodes[0]->content = strdup("-1"); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'session_timeout': -1."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_limit_session_timeout(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("session_timeout"); - nodes[0]->content = strdup("32000000"); - - expect_string(__wrap__mwarn, formatted_msg, "(7002): Number of maximum user timeouts in logtest too high. Only allows 31536000s maximum timeouts"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_valid_session_timeout(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("session_timeout"); - nodes[0]->content = strdup("1000000"); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_SUCCESS); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -void test_Read_Logtest_invalid_element(void **state) -{ - xml_node **nodes; - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - - nodes[0]->element = strdup("test"); - nodes[0]->content = strdup("unit_test"); - - expect_string(__wrap__merror, formatted_msg, "(1230): Invalid element in the configuration: 'test'."); - - int ret = Read_Logtest(nodes); - assert_int_equal(ret, OS_INVALID); - - os_free(nodes[0]->element); - os_free(nodes[0]->content); - os_free(nodes[0]); - os_free(nodes); -} - -/* getRuleTestConfig */ -void test_getRuleTestConfig_disabled(void **state) -{ - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - w_logtest_conf.enabled = false; - w_logtest_conf.threads = LOGTEST_LIMIT_THREAD; - w_logtest_conf.max_sessions = LOGTEST_LIMIT_MAX_SESSIONS; - w_logtest_conf.session_timeout = LOGTEST_LIMIT_SESSION_TIMEOUT; - - expect_string(__wrap_cJSON_AddStringToObject, name, "enabled"); - expect_string(__wrap_cJSON_AddStringToObject, string, "no"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "threads"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 128); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "max_sessions"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 500); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "session_timeout"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 31536000); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddItemToObject, string, "rule_test"); - expect_value(__wrap_cJSON_AddItemToObject, item, (cJSON *)1); - - cJSON* ret = getRuleTestConfig(); - -} - -void test_getRuleTestConfig_enabled(void **state) -{ - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - w_logtest_conf.enabled = true; - w_logtest_conf.threads = LOGTEST_LIMIT_THREAD; - w_logtest_conf.max_sessions = LOGTEST_LIMIT_MAX_SESSIONS; - w_logtest_conf.session_timeout = LOGTEST_LIMIT_SESSION_TIMEOUT; - - expect_string(__wrap_cJSON_AddStringToObject, name, "enabled"); - expect_string(__wrap_cJSON_AddStringToObject, string, "yes"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "threads"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 128); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "max_sessions"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 500); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "session_timeout"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 31536000); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddItemToObject, string, "rule_test"); - expect_value(__wrap_cJSON_AddItemToObject, item, (cJSON *)1); - - cJSON* ret = getRuleTestConfig(); - -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests Read_Logtest - cmocka_unit_test(test_Read_Logtest_element_NULL), - cmocka_unit_test(test_Read_Logtest_content_NULL), - cmocka_unit_test(test_Read_Logtest_invalid_enabled), - cmocka_unit_test(test_Read_Logtest_valid_disabled), - cmocka_unit_test(test_Read_Logtest_valid_enabled), - cmocka_unit_test(test_Read_Logtest_invalid_threads), - cmocka_unit_test(test_Read_Logtest_auto_threads), - cmocka_unit_test(test_Read_Logtest_smaller_threads), - cmocka_unit_test(test_Read_Logtest_bigger_threads), - cmocka_unit_test(test_Read_Logtest_limit_threads), - cmocka_unit_test(test_Read_Logtest_valid_threads), - cmocka_unit_test(test_Read_Logtest_invalid_max_sessions), - cmocka_unit_test(test_Read_Logtest_smaller_max_sessions), - cmocka_unit_test(test_Read_Logtest_bigger_max_sessions), - cmocka_unit_test(test_Read_Logtest_limit_max_sessions), - cmocka_unit_test(test_Read_Logtest_valid_max_sessions), - cmocka_unit_test(test_Read_Logtest_invalid_session_timeout), - cmocka_unit_test(test_Read_Logtest_smaller_session_timeout), - cmocka_unit_test(test_Read_Logtest_limit_session_timeout), - cmocka_unit_test(test_Read_Logtest_valid_session_timeout), - cmocka_unit_test(test_Read_Logtest_invalid_element), - // Tests getRuleTestConfig - cmocka_unit_test(test_getRuleTestConfig_disabled), - cmocka_unit_test(test_getRuleTestConfig_enabled) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_logtest.c b/src/unit_tests/analysisd/test_logtest.c deleted file mode 100644 index c151573ff2a..00000000000 --- a/src/unit_tests/analysisd/test_logtest.c +++ /dev/null @@ -1,6717 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../analysisd/logtest.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_xml/os_xml_wrappers.h" - -int w_logtest_init_parameters(); -void * w_logtest_init(); -void w_logtest_remove_session(char * token); -void w_logtest_register_session(w_logtest_connection_t * connection, w_logtest_session_t * session); -void w_logtest_remove_old_session(w_logtest_connection_t * connection); -void * w_logtest_check_inactive_sessions(w_logtest_connection_t * connection); -int w_logtest_fts_init(OSList ** fts_list, OSHash ** fts_store); -w_logtest_session_t * w_logtest_initialize_session(OSList * list_msg); -char * w_logtest_generate_token(); -void w_logtest_add_msg_response(cJSON * response, OSList * list_msg, int * error_code); -int w_logtest_check_input(char * input_json, cJSON ** req, char ** command_value, char ** msg, OSList * list_msg); -int w_logtest_check_input_request(cJSON * root, char ** msg, OSList * list_msg); -int w_logtest_check_input_remove_session(cJSON * root, char ** msg); -char * w_logtest_process_request(char * raw_request, w_logtest_connection_t * connection); -char * w_logtest_generate_error_response(char * msg); -int w_logtest_preprocessing_phase(Eventinfo * lf, cJSON * request); -void w_logtest_decoding_phase(Eventinfo * lf, w_logtest_session_t * session); -int w_logtest_rulesmatching_phase(Eventinfo * lf, w_logtest_session_t * session, - cJSON * rules_debug_list, - OSList * list_msg); -cJSON *w_logtest_process_log(cJSON * request, w_logtest_session_t * session, - w_logtest_extra_data_t * extra_data, - OSList * list_msg); -int w_logtest_process_request_remove_session(cJSON * json_request, cJSON * json_response, OSList * list_msg, - w_logtest_connection_t * connection); -void * w_logtest_clients_handler(w_logtest_connection_t * connection); -int w_logtest_process_request_log_processing(cJSON * json_request, cJSON * json_response, OSList * list_msg, - w_logtest_connection_t * connection); -void w_logtest_ruleset_free_config (_Config * ruleset_config); -bool w_logtest_ruleset_load_config(OS_XML * xml, XML_NODE conf_section_nodes, - _Config * ruleset_config, OSList * list_msg); - -int logtest_enabled = 1; - -int w_logtest_conf_threads = 1; - -int random_bytes_result = 0; - -char * cJSON_error_ptr = NULL; - -bool session_load_acm_store = false; - -bool refill_OS_CleanMSG = false; -OSDecoderInfo * decoder_CleanMSG; - -Eventinfo * event_OS_AddEvent = NULL; - -w_logtest_session_t * stored_session = NULL; -bool store_session = false; - -extern OSHash *w_logtest_sessions; - -int session_level_alert = 7; - -/* setup/teardown */ - -static int setup_group(void **state) { - w_logtest_sessions = (OSHash *) 8; - return 0; -} - -/* wraps */ - -int __wrap_OS_BindUnixDomain(const char *path, int type, int max_msg_size) { - return mock(); -} - -int __wrap_accept(int __fd, __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len) { - return mock_type(int); -} - -void __wrap__os_analysisd_add_logmsg(OSList * list, int level, int line, const char * func, - const char * file, char * msg, ...) { - char formatted_msg[OS_MAXSTR]; - va_list args; - - va_start(args, msg); - vsnprintf(formatted_msg, OS_MAXSTR, msg, args); - va_end(args); - - check_expected(level); - check_expected_ptr(list); - check_expected(formatted_msg); -} - -int __wrap_CreateThreadJoinable(pthread_t *lthread, void * (*function_pointer)(void *), void *data) -{ - return mock_type(int); -} - -int __wrap_CreateThread(void * (*function_pointer)(void *), void *data) -{ - return mock_type(int); -} - -int __wrap_pthread_join (pthread_t __th, void **__thread_return) { - return mock_type(int); -} - -int __wrap_unlink(const char *file) { - check_expected_ptr(file); - return mock(); -} - -int __wrap_pthread_mutex_init() { - return mock(); -} - -int __wrap_pthread_mutex_lock(pthread_mutex_t * mutex) { - return mock_type(int); -} - -int __wrap_pthread_mutex_unlock(pthread_mutex_t * mutex) { - return mock_type(int); -} - -int __wrap_pthread_mutex_destroy() { - return mock(); -} - -int __wrap_pthread_mutex_trylock(pthread_mutex_t *mutex) { - return mock(); -} - -int __wrap_pthread_rwlock_init() { - return mock(); -} - -int __wrap_pthread_rwlock_wrlock(pthread_rwlock_t * mutex) { - return mock_type(int); -} - -int __wrap_pthread_rwlock_rdlock(pthread_rwlock_t * mutex) { - return mock_type(int); -} - -int __wrap_pthread_rwlock_unlock(pthread_rwlock_t * mutex) { - return mock_type(int); -} - -int __wrap_ReadConfig(int modules, const char *cfgfile, void *d1, void *d2) { - if (!logtest_enabled) { - w_logtest_conf.enabled = false; - } - w_logtest_conf.threads = w_logtest_conf_threads; - return mock(); -} - -OSHash *__wrap_OSHash_Create() { - return mock_type(OSHash *); -} - -int __wrap_OSHash_setSize(OSHash *self, unsigned int new_size) { - if (new_size) check_expected(new_size); - return mock(); -} - -void __wrap_w_analysisd_accumulate_free(OSHash **acm_store) { - return; -} - -void __wrap_OSList_CleanOnlyNodes(OSList *list) { - return; -} - -int __wrap_OSHash_SetFreeDataPointer(OSHash *self, void (free_data_function)(void *)) { - return mock_type(int); -} - -OSList *__wrap_OSList_Create() { - return mock_type(OSList *); -} - -OSListNode *__wrap_OSList_GetFirstNode(OSList * list) { - return mock_type(OSListNode *); -} - -int __wrap_OSList_SetMaxSize() { - return mock(); -} - -void __wrap_w_mutex_init() { - return; -} - -void __wrap_w_mutex_destroy() { - return; -} - -void __wrap_w_create_thread() { - return; -} - -int __wrap_close (int __fd) { - return mock(); -} - -int __wrap_getDefine_Int() { - return mock(); -} - -void * __wrap_OSHash_Delete_ex(OSHash *self, const char *key) { - if (key) check_expected(key); - return mock_type(void *); -} - -void * __wrap_OSHash_Delete(OSHash *self, const char *key) { - if (key) check_expected(key); - return mock_type(void *); -} - -int __wrap_OSHash_Add_ex(OSHash *hash, const char *key, void *data) { - - if (key) check_expected(key); - if (data) check_expected(data); - if (data && store_session) stored_session = (w_logtest_session_t *) data; - return mock_type(int); -} - -int __wrap_OSHash_Add(OSHash *hash, const char *key, void *data) { - - if (key) check_expected(key); - if (data) check_expected(data); - if (data && store_session) stored_session = (w_logtest_session_t *) data; - return mock_type(int); -} - -void * __wrap_OSHash_Get_ex(OSHash *self, const char *key) { - if (key) check_expected(key); - return mock_type(void *); -} - -void * __wrap_OSHash_Get(OSHash *self, const char *key) { - if (key) check_expected(key); - return mock_type(void *); -} - -void __wrap_os_remove_rules_list(RuleNode *node) { - return; -} - -void * __wrap_OSHash_Free(OSHash *self) { - return mock_type(void *); -} - -void __wrap_os_remove_decoders_list(OSDecoderNode *decoderlist_pn, OSDecoderNode *decoderlist_npn) { - return; -} - -void __wrap_os_remove_cdblist(ListNode **l_node) { - return; -} - -void __wrap_os_remove_cdbrules(ListRule **l_rule) { - os_free(*l_rule); - return; -} - -void __wrap_os_remove_eventlist(EventList *list) { - os_free(list); - return; -} - -int __wrap_Read_Rules(XML_NODE node, void * configp, void * list) { - - int retval = mock_type(int); - _Config * ruleset = (_Config *) configp; - - if (retval < 0) { - return retval; - } - - ruleset->decoders = calloc(2, sizeof(char *)); - os_strdup("test_decoder.xml", ruleset->decoders[0]); - - ruleset->lists = calloc(2, sizeof(char *)); - os_strdup("test_list.xml", ruleset->lists[0]); - - ruleset->includes = calloc(2, sizeof(char *)); - os_strdup("test_rule.xml", ruleset->includes[0]); - - return retval; -} - -int __wrap_Read_Alerts(XML_NODE node, void * configp, void * list) { - int retval = mock_type(int); - _Config * ruleset = (_Config *) configp; - - if (retval < 0) { - return retval; - } - - ruleset->logbylevel = session_level_alert; - return retval; -} - -unsigned int __wrap_sleep (unsigned int __seconds) { - return mock_type(unsigned int); -} - -OSHashNode *__wrap_OSHash_Begin(const OSHash *self, unsigned int *i) { - return mock_type(OSHashNode *); -} - -double __wrap_difftime (time_t __time1, time_t __time0) { - return mock(); -} - -OSHashNode *__wrap_OSHash_Next(const OSHash *self, unsigned int *i, OSHashNode *current) { - return mock_type(OSHashNode *); -} - -OSStore *__wrap_OSStore_Free(OSStore *list) { - return mock_type(OSStore *); -} - -void __wrap_OS_CreateEventList(int maxsize, EventList *list) { - return; -} - -int __wrap_ReadDecodeXML(const char *file, OSDecoderNode **decoderlist_pn, - OSDecoderNode **decoderlist_nopn, OSStore **decoder_list, - OSList* log_msg) { - int retval = mock_type(int); - - if (retval > 0) { - *decoder_list = (OSStore *) 1; - } - return retval; -} - -int __wrap_SetDecodeXML(OSList* log_msg, OSStore **decoder_list, - OSDecoderNode **decoderlist_npn, OSDecoderNode **decoderlist_pn) { - return mock_type(int); -} - -int __wrap_Lists_OP_LoadList(char * files, ListNode ** cdblistnode, OSList * msg) { - return mock_type(int); -} - -void __wrap_Lists_OP_MakeAll(int force, int show_message, ListNode **lnode) { - return; -} - -int __wrap_Rules_OP_ReadRules(char * file, RuleNode ** rule_list, ListNode ** cbd , EventList ** evet, OSList * msg) { - return mock_type(int); -} - -void __wrap_OS_ListLoadRules(ListNode **l_node, ListRule **lrule) { - return; -} - -int __wrap__setlevels(RuleNode *node, int nnode) { - return mock_type(int); -} - -int __wrap_AddHash_Rule(RuleNode *node) { - return mock_type(int); -} - -int __wrap_Accumulate_Init(OSHash **acm_store, int *acm_lookups, time_t *acm_purge_ts) { - if (session_load_acm_store) { - *acm_store = (OSHash *) 8; - } - return mock_type(int); -} - -void __wrap_randombytes(void * ptr, size_t length) { - check_expected(length); - *((int32_t *) ptr) = random_bytes_result; - return; -} - -cJSON * __wrap_cJSON_ParseWithOpts(const char *value, const char **return_parse_end, - cJSON_bool require_null_terminated) { - *return_parse_end = cJSON_error_ptr; - return mock_type(cJSON *); -} - -cJSON* __wrap_cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) { - return mock_type(cJSON *); -} - -cJSON * __wrap_cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) { - return mock_type(cJSON *); -} - -cJSON * __wrap_cJSON_GetObjectItem(const cJSON * const object, const char * const string) { - return mock_type(cJSON *); -} - -char * __wrap_cJSON_GetStringValue(cJSON *item) { - return mock_type(char *); -} - -int __wrap_OS_CleanMSG(char *msg, Eventinfo *lf) { - if (refill_OS_CleanMSG) { - lf->program_name = strdup ("test program name"); - lf->is_a_copy = 1; - lf->log = msg; - lf->decoder_info = decoder_CleanMSG; - } - - return mock_type(int); -} - -Eventinfo * __wrap_Accumulate(Eventinfo *lf, OSHash **acm_store, int *acm_lookups, time_t *acm_purge_ts) { - return lf; -} - -char* __wrap_ParseRuleComment(Eventinfo *lf) { - return mock_type(char *); -} - -cJSON* __wrap_cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) { - return mock_type(cJSON *); -} - -cJSON_bool __wrap_cJSON_IsNumber(const cJSON * const item) { - return mock_type(cJSON_bool); -} - -cJSON_bool __wrap_cJSON_IsObject(const cJSON * const item) { - return mock_type(cJSON_bool); -} - -cJSON * __wrap_cJSON_CreateArray() { - return mock_type(cJSON *); -} - -cJSON * __wrap_cJSON_CreateObject() { - return mock_type(cJSON *); -} - -cJSON * __wrap_cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) { - check_expected(number); - check_expected(name); - return mock_type(cJSON *); -} - -char * __wrap_cJSON_PrintUnformatted(const cJSON *item){ - return mock_type(char *); -} - -void __wrap_cJSON_Delete(cJSON *item){ - return; -} - -cJSON_bool __wrap_cJSON_IsString(const cJSON * const item) { - return mock_type(cJSON_bool); -} - -void __wrap_cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string){ - return; -} - -void __wrap_cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item){ - check_expected(object); - check_expected(string); - return; -} - -cJSON * __wrap_cJSON_CreateString(const char *string){ - return mock_type(cJSON *); -} - -void __wrap_cJSON_AddItemToArray(cJSON *array, cJSON *item) { - return; -} - -cJSON * __wrap_cJSON_Parse(const char *value) { - return mock_type(cJSON *); -} - -char *__wrap_Eventinfo_to_jsonstr(const Eventinfo *lf, bool force_full_log){ - return mock_type(char *); -} - -void __wrap_os_analysisd_free_log_msg(os_analysisd_log_msg_t * log_msg) { - os_free(log_msg->file); - os_free(log_msg->func); - os_free(log_msg->msg); - os_free(log_msg); - return; -} - -char * __wrap_os_analysisd_string_log_msg(os_analysisd_log_msg_t * log_msg) { - return mock_type(char *); -} - -void __wrap_OSList_DeleteCurrentlyNode(OSList *list) { - if (list) { - os_free(list->cur_node) - } - return; -} - -int __wrap_wm_strcat(char **str1, const char *str2, char sep) { - if(*str1 == NULL){ - os_calloc(4 , sizeof(char), *str1); - } - check_expected(str2); - return mock_type(int); -} - -void __wrap_DecodeEvent(struct _Eventinfo *lf, OSHash *rules_hash, regex_matching *decoder_match, OSDecoderNode *node) { - check_expected(node); -} - -RuleInfo * __wrap_OS_CheckIfRuleMatch(struct _Eventinfo *lf, EventList *last_events, - ListNode **cdblists, RuleNode *curr_node, - regex_matching *rule_match, OSList **fts_list, - OSHash **fts_store) { - return mock_type(RuleInfo *); -} - -void __wrap_OS_AddEvent(Eventinfo *lf, EventList *list) { - event_OS_AddEvent = lf; - return; -} - -int __wrap_IGnore(Eventinfo *lf, int pos) { - return mock_type(int); -} - -void * __wrap_OSList_AddData(OSList *list, void *data) { - return mock_type(void *); -} - -int __wrap_OS_RecvSecureTCP(int sock, char * ret,uint32_t size) { - return mock_type(int); -} - -int __wrap_OS_SendSecureTCP(int sock, uint32_t size, const void * msg) { - return mock_type(int); -} - -/* tests */ - -/* w_logtest_init_parameters */ -void test_w_logtest_init_parameters_invalid(void **state) -{ - will_return(__wrap_ReadConfig, OS_INVALID); - - int ret = w_logtest_init_parameters(); - assert_int_equal(ret, OS_INVALID); - -} - -void test_w_logtest_init_parameters_done(void **state) -{ - will_return(__wrap_ReadConfig, 0); - - int ret = w_logtest_init_parameters(); - assert_int_equal(ret, OS_SUCCESS); - -} - -/* w_logtest_init */ -void test_w_logtest_init_error_parameters(void **state) -{ - will_return(__wrap_ReadConfig, OS_INVALID); - - expect_string(__wrap__merror, formatted_msg, "(7304): Invalid wazuh-logtest configuration"); - - w_logtest_init(); - -} - - -void test_w_logtest_init_logtest_disabled(void **state) -{ - will_return(__wrap_ReadConfig, 0); - - logtest_enabled = 0; - - expect_string(__wrap__minfo, formatted_msg, "(7201): Logtest disabled"); - - w_logtest_init(); - - logtest_enabled = 1; - -} - -void test_w_logtest_init_conection_fail(void **state) -{ - will_return(__wrap_ReadConfig, 0); - - will_return(__wrap_OS_BindUnixDomain, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "(7300): Unable to bind to socket 'queue/sockets/logtest'. Errno: (0) Success"); - - w_logtest_init(); - -} - -void test_w_logtest_init_OSHash_create_fail(void **state) -{ - will_return(__wrap_ReadConfig, 0); - - will_return(__wrap_OS_BindUnixDomain, OS_SUCCESS); - - will_return(__wrap_OSHash_Create, NULL); - - expect_string(__wrap__merror, formatted_msg, "(7303): Failure to initialize all_sessions hash"); - - w_logtest_init(); - -} - -void test_w_logtest_init_OSHash_setSize_fail(void **state) -{ - will_return(__wrap_ReadConfig, 0); - - will_return(__wrap_OS_BindUnixDomain, OS_SUCCESS); - - will_return(__wrap_OSHash_Create, 8); - - expect_in_range(__wrap_OSHash_setSize, new_size, 1, 400); - will_return(__wrap_OSHash_setSize, NULL); - - expect_string(__wrap__merror, formatted_msg, "(7305): Failure to resize all_sessions hash"); - - w_logtest_init(); - -} - -void test_w_logtest_init_pthread_fail(void **state) -{ - w_logtest_conf_threads = 2; - will_return(__wrap_ReadConfig, 0); - - will_return(__wrap_OS_BindUnixDomain, OS_SUCCESS); - - will_return(__wrap_OSHash_Create, 8); - - expect_in_range(__wrap_OSHash_setSize, new_size, 1, 400); - will_return(__wrap_OSHash_setSize, 1); - - will_return(__wrap_pthread_mutex_init, 0); - - expect_string(__wrap__minfo, formatted_msg, "(7200): Logtest started"); - - will_return(__wrap_CreateThreadJoinable, -1); - - expect_string(__wrap__merror_exit, formatted_msg, "(1109): Unable to create new pthread."); - - expect_assert_failure(w_logtest_init()); - w_logtest_conf_threads = 1; - -} - -void test_w_logtest_init_unlink_fail(void **state) -{ - w_logtest_conf_threads = 1; - will_return(__wrap_ReadConfig, 0); - - will_return(__wrap_OS_BindUnixDomain, OS_SUCCESS); - - will_return(__wrap_OSHash_Create, 8); - - expect_in_range(__wrap_OSHash_setSize, new_size, 1, 400); - will_return(__wrap_OSHash_setSize, 1); - - will_return(__wrap_pthread_mutex_init, 0); - - expect_string(__wrap__minfo, formatted_msg, "(7200): Logtest started"); - - will_return(__wrap_CreateThread, 1); - - //w_logtest_clients_handler - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - - will_return(__wrap_accept, 5); - - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7314): Failure to receive message: empty or reception timeout"); - - will_return(__wrap_close, 0); - will_return(__wrap_FOREVER, 0); - - - will_return(__wrap_close, 0); - - expect_string(__wrap_unlink, file, LOGTEST_SOCK); - will_return(__wrap_unlink, 1); - - char msg[OS_SIZE_4096]; - errno = EBUSY; - snprintf(msg, OS_SIZE_4096, "(1129): Could not unlink file '%s' due to [(%d)-(%s)].", - LOGTEST_SOCK, errno, strerror(errno)); - - expect_string(__wrap__merror, formatted_msg, msg); - - will_return(__wrap_pthread_mutex_destroy, 0); - - w_logtest_init(); - w_logtest_conf_threads = 1; - -} - -void test_w_logtest_init_done(void **state) -{ - w_logtest_conf_threads = 1; - will_return(__wrap_ReadConfig, 0); - - will_return(__wrap_OS_BindUnixDomain, OS_SUCCESS); - - will_return(__wrap_OSHash_Create, 8); - - expect_in_range(__wrap_OSHash_setSize, new_size, 1, 400); - will_return(__wrap_OSHash_setSize, 1); - - will_return(__wrap_pthread_mutex_init, 0); - - expect_string(__wrap__minfo, formatted_msg, "(7200): Logtest started"); - - will_return(__wrap_CreateThread, 1); - - //w_logtest_clients_handler - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - - will_return(__wrap_accept, 5); - - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7314): Failure to receive message: empty or reception timeout"); - - will_return(__wrap_close, 0); - will_return(__wrap_FOREVER, 0); - - - will_return(__wrap_close, 0); - - expect_string(__wrap_unlink, file, LOGTEST_SOCK); - will_return(__wrap_unlink, 0); - - - will_return(__wrap_pthread_mutex_destroy, 0); - - w_logtest_init(); - w_logtest_conf_threads = 1; - -} - -/* w_logtest_fts_init */ -void test_w_logtest_fts_init_create_list_failure(void **state) -{ - OSList *fts_list; - OSHash *fts_store; - - will_return(__wrap_getDefine_Int, 5); - - will_return(__wrap_OSList_Create, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1290): Unable to create a new list (calloc)."); - - int ret = w_logtest_fts_init(&fts_list, &fts_store); - assert_int_equal(ret, 0); - -} - -void test_w_logtest_fts_init_SetMaxSize_failure(void **state) -{ - OSList *fts_list; - OSHash *fts_store; - OSList *list = (OSList *) 8; - - will_return(__wrap_getDefine_Int, 5); - - will_return(__wrap_OSList_Create, list); - - will_return(__wrap_OSList_SetMaxSize, 0); - - expect_string(__wrap__merror, formatted_msg, "(1292): Error setting error size."); - - int ret = w_logtest_fts_init(&fts_list, &fts_store); - assert_int_equal(ret, 0); - -} - -void test_w_logtest_fts_init_create_hash_failure(void **state) -{ - OSList *fts_list; - OSHash *fts_store; - OSList *list = (OSList *) 8; - - will_return(__wrap_getDefine_Int, 5); - - will_return(__wrap_OSList_Create, list); - - will_return(__wrap_OSList_SetMaxSize, 1); - - will_return(__wrap_OSHash_Create, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1295): Unable to create a new hash (calloc)."); - - int ret = w_logtest_fts_init(&fts_list, &fts_store); - assert_int_equal(ret, 0); - -} - -void test_w_logtest_fts_init_setSize_failure(void **state) -{ - OSList *fts_list; - OSHash *fts_store; - OSList *list = (OSList *) 8; - OSHash *hash = (OSHash *) 8; - - will_return(__wrap_getDefine_Int, 5); - - will_return(__wrap_OSList_Create, list); - - will_return(__wrap_OSList_SetMaxSize, 1); - - will_return(__wrap_OSHash_Create, hash); - - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 0); - - expect_string(__wrap__merror, formatted_msg, "(1292): Error setting error size."); - - int ret = w_logtest_fts_init(&fts_list, &fts_store); - assert_int_equal(ret, 0); - -} - -void test_w_logtest_fts_init_success(void **state) -{ - OSList *fts_list; - OSHash *fts_store; - OSList *list = (OSList *) 8; - OSHash *hash = (OSHash *) 8; - - will_return(__wrap_getDefine_Int, 5); - - will_return(__wrap_OSList_Create, list); - - will_return(__wrap_OSList_SetMaxSize, 1); - - will_return(__wrap_OSHash_Create, hash); - - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - int ret = w_logtest_fts_init(&fts_list, &fts_store); - assert_int_equal(ret, 1); - -} - -/* w_logtest_remove_session */ -void test_w_logtest_remove_session_fail(void **state) -{ - char * key = "test"; - - expect_value(__wrap_OSHash_Delete, key, "test"); - will_return(__wrap_OSHash_Delete, NULL); - - w_logtest_remove_session(key); - -} - -void test_w_logtest_remove_session_OK(void **state) -{ - char * key = "test"; - w_logtest_session_t *session; - os_calloc(1, sizeof(w_logtest_session_t), session); - - expect_value(__wrap_OSHash_Delete, key, "test"); - will_return(__wrap_OSHash_Delete, session); - - will_return(__wrap_OSStore_Free, session->decoder_store); - - will_return(__wrap_OSHash_Free, session); - - will_return(__wrap_OSHash_Free, session); - - will_return(__wrap_pthread_mutex_destroy, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7206): The session 'test' was closed successfully"); - - w_logtest_remove_session(key); - -} - -/* w_logtest_check_inactive_sessions */ -void test_w_logtest_check_inactive_sessions_no_remove(void **state) -{ - - w_logtest_connection_t connection; - const int active_session = 5; - connection.active_client = active_session; - - w_logtest_session_t *session; - os_calloc(1, sizeof(w_logtest_session_t), session); - session->last_connection = 1; - - OSHashNode *hash_node; - os_calloc(1, sizeof(OSHashNode), hash_node); - hash_node->key = "test"; - hash_node->data = session; - - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_sleep, 0); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - - will_return(__wrap_OSHash_Begin, hash_node); - - will_return(__wrap_time, NULL); - - will_return(__wrap_difftime, 1); - - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - will_return(__wrap_FOREVER, 0); - - w_logtest_check_inactive_sessions(&connection); - - assert_int_equal(connection.active_client, active_session); - - os_free(session); - os_free(hash_node); - -} - -void test_w_logtest_check_inactive_sessions_remove(void **state) -{ - - w_logtest_connection_t connection; - const int active_session = 5; - connection.active_client = active_session; - - w_logtest_session_t *session; - os_calloc(1, sizeof(w_logtest_session_t), session); - session->last_connection = 1; - - OSHashNode *hash_node; - os_calloc(1, sizeof(OSHashNode), hash_node); - hash_node->key = "test"; - hash_node->data = session; - - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_sleep, 0); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - - will_return(__wrap_OSHash_Begin, hash_node); - - will_return(__wrap_time, NULL); - - will_return(__wrap_difftime, 1000000); - - will_return(__wrap_pthread_mutex_trylock, 0); - - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_OSHash_Next, NULL); - - // test_w_logtest_remove_session_ok - char * key = "test"; - - expect_value(__wrap_OSHash_Delete, key, "test"); - will_return(__wrap_OSHash_Delete, session); - - will_return(__wrap_OSStore_Free, NULL); - - will_return(__wrap_OSHash_Free, session); - - will_return(__wrap_OSHash_Free, session); - - will_return(__wrap_pthread_mutex_destroy, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7206): The session 'test' was closed successfully"); - - will_return(__wrap_FOREVER, 0); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - - w_logtest_check_inactive_sessions(&connection); - - assert_int_equal(connection.active_client, active_session - 1); - - os_free(hash_node); - -} - -/* w_logtest_remove_old_session */ -void test_w_logtest_remove_old_session_Begin_fail(void ** state) { - - w_logtest_connection_t connection; - - connection.active_client = 2; - w_logtest_conf.max_sessions = 1; - - will_return(__wrap_OSHash_Begin, NULL); - - w_logtest_remove_old_session(&connection); - -} - -void test_w_logtest_remove_old_session_one(void ** state) { - - w_logtest_connection_t connection; - - connection.active_client = 2; - w_logtest_conf.max_sessions = 1; - - /* Oldest session */ - w_logtest_session_t * old_session; - os_calloc(1, sizeof(w_logtest_session_t), old_session); - old_session->last_connection = 100; - w_strdup("old_session", old_session->token); - OSHashNode * hash_node_old; - os_calloc(1, sizeof(OSHashNode), hash_node_old); - w_strdup("old_session", hash_node_old->key); - hash_node_old->data = old_session; - - will_return(__wrap_OSHash_Begin, hash_node_old); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - - /* Remove session */ - expect_string(__wrap_OSHash_Delete, key, "old_session"); - will_return(__wrap_OSHash_Delete, old_session); - - will_return(__wrap_OSStore_Free, old_session->decoder_store); - - will_return(__wrap_OSHash_Free, old_session); - - will_return(__wrap_OSHash_Free, old_session); - - will_return(__wrap_pthread_mutex_destroy, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7206): The session 'old_session' was closed successfully"); - - - w_logtest_remove_old_session(&connection); - - assert_int_equal(connection.active_client, w_logtest_conf.max_sessions); - - os_free(hash_node_old->key); - os_free(hash_node_old); -} - -void test_w_logtest_remove_old_session_many(void ** state) { - - w_logtest_connection_t connection; - - connection.active_client = 3; - w_logtest_conf.max_sessions = 2; - - /* Oldest session */ - w_logtest_session_t * old_session; - os_calloc(1, sizeof(w_logtest_session_t), old_session); - old_session->last_connection = 100; - w_strdup("old_session", old_session->token); - OSHashNode * hash_node_old; - os_calloc(1, sizeof(OSHashNode), hash_node_old); - w_strdup("old_session", hash_node_old->key); - hash_node_old->data = old_session; - - /* Other session */ - w_logtest_session_t other_session; - other_session.last_connection = 300; - OSHashNode * hash_node_other; - os_calloc(1, sizeof(OSHashNode), hash_node_other); - w_strdup("other_session", hash_node_other->key); - hash_node_other->data = &other_session; - - will_return(__wrap_OSHash_Begin, hash_node_other); - will_return(__wrap_OSHash_Next, hash_node_old); - - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - /* w_logtest_remove_session */ - expect_value(__wrap_OSHash_Delete, key, old_session->token); - will_return(__wrap_OSHash_Delete, old_session); - - will_return(__wrap_OSStore_Free, NULL); - - will_return(__wrap_OSHash_Free, old_session); - - will_return(__wrap_OSHash_Free, old_session); - - will_return(__wrap_pthread_mutex_destroy, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7206): The session 'old_session' was closed successfully"); - - w_logtest_remove_old_session(&connection); - assert_int_equal(connection.active_client, w_logtest_conf.max_sessions); - - os_free(hash_node_other->key); - os_free(hash_node_old->key); - os_free(hash_node_other); - os_free(hash_node_old); -} - -/* w_logtest_register_session */ -void test_w_logtest_register_session_dont_remove(void ** state) { - w_logtest_connection_t connection; - const int active_session = 5; - - connection.active_client = active_session; - w_logtest_conf.max_sessions = active_session + 1; - - w_logtest_session_t session; - w_strdup("test", session.token); - - expect_value(__wrap_OSHash_Add, key, session.token); - expect_value(__wrap_OSHash_Add, data, &session); - will_return(__wrap_OSHash_Add, 0); - - w_logtest_register_session(&connection, &session); - - assert_int_equal(connection.active_client, active_session + 1); - - os_free(session.token) -} - -void test_w_logtest_register_session_remove_old(void ** state) { - w_logtest_connection_t connection; - const int active_session = 5; - - connection.active_client = active_session; - w_logtest_conf.max_sessions = active_session; - - /* New session */ - w_logtest_session_t session; - w_strdup("new_session", session.token); - - /* Oldest session */ - w_logtest_session_t * old_session; - os_calloc(1, sizeof(w_logtest_session_t), old_session); - old_session->last_connection = 100; - w_strdup("old_session", old_session->token); - OSHashNode * hash_node_old; - os_calloc(1, sizeof(OSHashNode), hash_node_old); - w_strdup("old_session", hash_node_old->key); - hash_node_old->data = old_session; - - /* Other session */ - w_logtest_session_t other_session; - other_session.last_connection = 300; - OSHashNode * hash_node_other; - os_calloc(1, sizeof(OSHashNode), hash_node_other); - w_strdup("other_session", hash_node_other->key); - hash_node_other->data = &other_session; - - will_return(__wrap_OSHash_Begin, hash_node_other); - will_return(__wrap_OSHash_Next, hash_node_old); - - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - - /* w_logtest_remove_session */ - expect_value(__wrap_OSHash_Delete, key, old_session->token); - will_return(__wrap_OSHash_Delete, old_session); - - will_return(__wrap_OSStore_Free, NULL); - - will_return(__wrap_OSHash_Free, old_session); - - will_return(__wrap_OSHash_Free, old_session); - - will_return(__wrap_pthread_mutex_destroy, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7206): The session 'old_session' was closed successfully"); - - expect_value(__wrap_OSHash_Add, key, session.token); - expect_value(__wrap_OSHash_Add, data, &session); - will_return(__wrap_OSHash_Add, 0); - - - w_logtest_register_session(&connection, &session); - assert_int_equal(connection.active_client, active_session); - - os_free(session.token); - os_free(hash_node_other->key); - os_free(hash_node_old->key); - os_free(hash_node_other); - os_free(hash_node_old); -} - -/* w_logtest_initialize_session */ -void test_w_logtest_initialize_session_error_load_ruleset(void ** state) { - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - // test_w_logtest_remove_session_ok_error_load_decoder_cbd_rules_hash - /* w_logtest_ruleset_load */ - will_return(__wrap_OS_ReadXML, -1); - will_return(__wrap_OS_ReadXML, "unknown"); - will_return(__wrap_OS_ReadXML, 5); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, - "(1226): Error reading XML file 'etc/ossec.conf': " - "unknown (line 5)."); - - will_return(__wrap_pthread_mutex_destroy, 0); - - session = w_logtest_initialize_session(msg); - - assert_null(session); - - os_free(token); -} - -void test_w_logtest_initialize_session_error_decoders(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 0); - - - will_return(__wrap_pthread_mutex_destroy, 0); - - session = w_logtest_initialize_session(msg); - - assert_null(session); - - os_free(token); -} - -void test_w_logtest_initialize_session_error_set_decoders(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 1; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 0); - - // test_w_logtest_remove_session_ok_error_load_decoder_cbd_rules_hash - will_return(__wrap_OSStore_Free, (OSStore *) 8); - - will_return(__wrap_pthread_mutex_destroy, 0); - - session = w_logtest_initialize_session(msg); - - assert_null(session); - os_free(token); -} - -void test_w_logtest_initialize_session_error_cbd_list(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, -1); - - // test_w_logtest_remove_session_ok_error_load_decoder_cbd_rules_hash - will_return(__wrap_OSStore_Free, (OSStore *) 8); - - will_return(__wrap_pthread_mutex_destroy, 0); - - session = w_logtest_initialize_session(msg); - - assert_null(session); - os_free(token); -} - -void test_w_logtest_initialize_session_error_rules(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, -1); - - // test_w_logtest_remove_session_ok_error_load_decoder_cbd_rules_hash - will_return(__wrap_OSStore_Free, (OSStore *) 8); - - will_return(__wrap_pthread_mutex_destroy, 0); - - session = w_logtest_initialize_session(msg); - - assert_null(session); - os_free(token); -} - -void test_w_logtest_initialize_session_error_hash_rules(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 0); - - // test_w_logtest_remove_session_ok_error_load_decoder_cbd_rules_hash - will_return(__wrap_OSStore_Free, (OSStore *) 8); - - will_return(__wrap_pthread_mutex_destroy, 0); - - session = w_logtest_initialize_session(msg); - - assert_null(session); - - os_free(token); -} - -void test_w_logtest_initialize_session_error_fts_init(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init fail */ - OSList * fts_list; - OSHash * fts_store; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, NULL); - expect_string(__wrap__merror, formatted_msg, "(1290): Unable to create a new list (calloc)."); - - // test_w_logtest_remove_session_ok_error_FTS_INIT - will_return(__wrap_OSStore_Free, (OSStore *) 8); - will_return(__wrap_OSHash_Free, (OSHash *) 0); - - will_return(__wrap_pthread_mutex_destroy, 0); - - session = w_logtest_initialize_session(msg); - - assert_null(session); - - os_free(token); -} - -void test_w_logtest_initialize_session_error_accumulate_init(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list; - os_calloc(1, sizeof(OSList), list); - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - will_return(__wrap_Accumulate_Init, 0); - - // test_w_logtest_remove_session_ok_error_acm - will_return(__wrap_OSStore_Free, (OSStore *) 8); - will_return(__wrap_OSHash_Free, (OSStore *) 8); - will_return(__wrap_OSHash_Free, (OSStore *) 8); - - will_return(__wrap_OSHash_Free, (OSStore *) 8); - will_return(__wrap_pthread_mutex_destroy, 0); - - session_load_acm_store = true; - - session = w_logtest_initialize_session(msg); - - session_load_acm_store = false; - - assert_null(session); - - os_free(token); -} - -void test_w_logtest_initialize_session_success(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 1212); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list = (OSList *) 8; - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - will_return(__wrap_Accumulate_Init, 1); - - session = w_logtest_initialize_session(msg); - - assert_non_null(session); - assert_int_equal(session->last_connection, 1212); - - os_free(token); - os_free(session->eventlist); - os_free(session->token); - os_free(session); - -} - -void test_w_logtest_initialize_session_success_duplicate_key(void ** state) { - - char * token = strdup("test"); - OSList * msg = (OSList *) 8; - w_logtest_session_t * session; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, (void *) 8); - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 1212); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list = (OSList *) 8; - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - will_return(__wrap_Accumulate_Init, 1); - - session = w_logtest_initialize_session(msg); - - assert_non_null(session); - assert_int_equal(session->last_connection, 1212); - - os_free(token); - os_free(session->eventlist); - os_free(session->token); - os_free(session); -} -/* w_logtest_generate_token */ -void test_w_logtest_generate_token_success(void ** state) { - - char * token = NULL; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - token = w_logtest_generate_token(); - - assert_non_null(token); - assert_string_equal(token, "4995f9b3"); - - os_free(token); -} - -void test_w_logtest_generate_token_success_empty_bytes(void ** state) { - - char * token = NULL; - - random_bytes_result = 5555; // 0x15_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - token = w_logtest_generate_token(); - - assert_non_null(token); - assert_string_equal(token, "000015b3"); - - os_free(token); -} - -void test_w_logtest_add_msg_response_null_list(void ** state) { - cJSON * response; - OSList * list_msg; - int retval = 0; - const int ret_expect = retval; - - will_return(__wrap_OSList_GetFirstNode, NULL); - - w_logtest_add_msg_response(response, list_msg, &retval); - - assert_int_equal(retval, ret_expect); - -} - -void test_w_logtest_add_msg_response_new_field_msg(void ** state) { - cJSON * response = (cJSON*) 8; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - const int ret_expect = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval = 999; - - cJSON * json_arr_msg = (cJSON*) 2; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - will_return(__wrap_cJSON_CreateArray, (cJSON*) 8); - - expect_value(__wrap_cJSON_AddItemToObject, object, response); - expect_string(__wrap_cJSON_AddItemToObject, string, "messages"); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - w_logtest_add_msg_response(response, list_msg, &retval); - - assert_int_equal(retval, ret_expect); - os_free(list_msg); -} - -void test_w_logtest_add_msg_response_error_msg(void ** state) { - cJSON * response = (cJSON*) 8; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - const int ret_expect = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval = 999; - - cJSON * json_arr_msg = (cJSON*) 2; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - w_logtest_add_msg_response(response, list_msg, &retval); - - assert_int_equal(retval, ret_expect); - os_free(list_msg); -} - -void test_w_logtest_add_msg_response_warn_msg(void ** state) { - cJSON * response = (cJSON*) 8;; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - const int ret_expect = W_LOGTEST_RCODE_WARNING; - int retval = W_LOGTEST_RCODE_SUCCESS; - - cJSON * json_arr_msg = (cJSON*) 2; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_WARNING; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "WARNING: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - w_logtest_add_msg_response(response, list_msg, &retval); - - assert_int_equal(retval, ret_expect); - os_free(list_msg); -} - -void test_w_logtest_add_msg_response_warn_dont_remplaze_error_msg(void ** state) { - cJSON * response = (cJSON*) 8; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - const int ret_expect = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval = W_LOGTEST_RCODE_ERROR_PROCESS; - - cJSON * json_arr_msg = (cJSON*) 2; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_WARNING; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "WARNING: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - w_logtest_add_msg_response(response, list_msg, &retval); - - assert_int_equal(retval, ret_expect); - os_free(list_msg); -} - -void test_w_logtest_add_msg_response_info_msg(void ** state) { - cJSON * response = (cJSON*) 8;; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - const int ret_expect = 999; - int retval = ret_expect; - - cJSON * json_arr_msg = (cJSON*) 2; - - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - w_logtest_add_msg_response(response, list_msg, &retval); - - assert_int_equal(retval, ret_expect); - os_free(list_msg); - -} - -/* w_logtest_check_input */ -void test_w_logtest_check_input_malformed_json_long(void ** state) { - - char * input_raw_json = strdup("Test_input_json|_longTest_i|nput_json_long"); - int pos_error = 25; - char expect_slice_json[] = "|_longTest_i|"; - - int retval; - const int ret_expect = W_LOGTEST_CODE_ERROR_PARSING; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char ** command_value = (char **) 3; - char * msg = NULL; - - cJSON_error_ptr = input_raw_json + pos_error; - will_return(__wrap_cJSON_ParseWithOpts, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7307): Error parsing JSON in position 25, ... |_longTest_i| ..."); - - - retval = w_logtest_check_input(input_raw_json, &request, command_value, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal("(7307): Error parsing JSON in position 25, ... |_longTest_i| ...", msg); - - os_free(input_raw_json); - os_free(msg); -} - -void test_w_logtest_check_input_malformed_json_short(void ** state) { - - char * input_raw_json = strdup("jsonjson"); - int pos_error = 7; - char expect_slice_json[] = "jsonjson"; - - int retval; - const int ret_expect = W_LOGTEST_CODE_ERROR_PARSING; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char ** command_value = (char **) 3; - char * msg = NULL; - - cJSON_error_ptr = input_raw_json + pos_error; - will_return(__wrap_cJSON_ParseWithOpts, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7307): Error parsing JSON in position 7, ... jsonjson ..."); - - - retval = w_logtest_check_input(input_raw_json, &request, command_value, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal("(7307): Error parsing JSON in position 7, ... jsonjson ...", msg); - - os_free(input_raw_json); - os_free(msg); -} - -void test_w_logtest_check_input_parameter_not_found(void ** state) { - - char * input_raw_json = (char *) 8; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char ** command_value = (char **) 3; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7313): 'parameters' JSON field not found"); - - - retval = w_logtest_check_input(input_raw_json, &request, command_value, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal("(7313): 'parameters' JSON field not found", msg); - - os_free(msg); - -} - -void test_w_logtest_check_input_parameter_bad_type(void ** state) { - - char * input_raw_json = (char *) 8; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char ** command_value = (char **) 3; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, (cJSON *) 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7317): 'parameters' JSON field value is not valid"); - - - retval = w_logtest_check_input(input_raw_json, &request, command_value, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal("(7317): 'parameters' JSON field value is not valid", msg); - - os_free(msg); - -} - -void test_w_logtest_check_input_command_not_found(void ** state) { - - char * input_raw_json = (char *) 8; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char ** command_value = (char **) 3; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7313): 'command' JSON field not found"); - - - retval = w_logtest_check_input(input_raw_json, &request, command_value, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal("(7313): 'command' JSON field not found", msg); - - os_free(msg); - -} - -void test_w_logtest_check_input_command_bad_type(void ** state) { - - char * input_raw_json = (char *) 8; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char * command_value; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7317): 'command' JSON field value is not valid"); - - - retval = w_logtest_check_input(input_raw_json, &request, &command_value, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal("(7317): 'command' JSON field value is not valid", msg); - - os_free(msg); - -} - -void test_w_logtest_check_input_invalid_command(void ** state) { - - char * input_raw_json = (char *) 8; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char * command_value; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_COMMAND_NOT_ALLOWED; - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, "invalid_command"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7306): Unable to process command"); - - - retval = w_logtest_check_input(input_raw_json, &request, &command_value, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal("(7306): Unable to process command", msg); - - os_free(msg); - -} - -void test_w_logtest_check_input_type_remove_sesion_ok(void ** state) { - - char * input_raw_json = (char *) 8; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char * command_value; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_SUCCESS; - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, "remove_session"); - - // w_logtest_check_input_remove_session ok - cJSON token = {0}; - token.valuestring = strdup("12345678"); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - - assert_int_equal(W_LOGTEST_TOKEN_LENGH, strlen(token.valuestring)); - - retval = w_logtest_check_input(input_raw_json, &request, &command_value, &msg, list_msg); - - assert_string_equal(command_value, "remove_session"); - assert_int_equal(retval, ret_expect); - os_free(token.valuestring); - -} - -void test_w_logtest_check_input_type_request_ok(void ** state) { - - char * input_raw_json = strdup("{input json}"); - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_SUCCESS; - - cJSON * request; - OSList * list_msg = (OSList *) 2; - char * command; - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, "log_processing"); - - // w_logtest_check_input_request ok - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - cJSON event = {0}; - event.valuestring = strdup("event str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &event); - will_return(__wrap_cJSON_IsString, true); - - /* token */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* The optional parameters */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - retval = w_logtest_check_input(input_raw_json, &request, &command, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_null(msg); - assert_string_equal(command, "log_processing"); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(event.valuestring); - os_free(input_raw_json); - -} - -// w_logtest_check_input_request -void test_w_logtest_check_input_request_empty_json(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - OSList * list_msg = (OSList *) 2; - - /* location */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - will_return(__wrap_cJSON_IsString, false); - - expect_string(__wrap__mdebug1, formatted_msg, "(7308): 'location' JSON field is required and must be a string"); - - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal(msg, "(7308): 'location' JSON field is required and must be a string"); - os_free(msg); -} - -void test_w_logtest_check_input_request_missing_location(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - OSList * list_msg = (OSList *) 2; - - /* location */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - will_return(__wrap_cJSON_IsString, false); - - expect_string(__wrap__mdebug1, formatted_msg, "(7308): 'location' JSON field is required and must be a string"); - - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_string_equal(msg, "(7308): 'location' JSON field is required and must be a string"); - os_free(msg); -} - -void test_w_logtest_check_input_request_missing_log_format(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - will_return(__wrap_cJSON_IsString, false); - - expect_string(__wrap__mdebug1, formatted_msg, "(7308): 'log_format' JSON field is required and must be a string"); - - retval = retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - os_free(location.valuestring); - os_free(msg); -} - -void test_w_logtest_check_input_request_missing_event(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7313): 'event' JSON field not found"); - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_string_equal(msg, "(7313): 'event' JSON field not found"); - assert_int_equal(retval, ret_expect); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(msg); -} - -void test_w_logtest_check_input_request_invalid_event(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_INVALID_JSON; - - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsString, false); - will_return(__wrap_cJSON_IsObject, false); - - expect_string(__wrap__mdebug1, formatted_msg, "(7317): 'event' JSON field value is not valid"); - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_string_equal(msg, "(7317): 'event' JSON field value is not valid"); - assert_int_equal(retval, ret_expect); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(msg); -} - -void test_w_logtest_check_input_request_full(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_SUCCESS; - - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - cJSON event = {0}; - event.valuestring = strdup("event str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &event); - will_return(__wrap_cJSON_IsString, true); - - /* token */ - cJSON token = {0}; - token.valuestring = strdup("12345678"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, true); - will_return(__wrap_cJSON_IsString, true); - - /* The optional parameters */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_null(msg); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(event.valuestring); - os_free(token.valuestring); -} - -void test_w_logtest_check_input_request_full_empty_token(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_SUCCESS; - - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - cJSON event = {0}; - event.valuestring = strdup("event str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &event); - will_return(__wrap_cJSON_IsString, true); - - /* token */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* The optional parameters */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_null(msg); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(event.valuestring); -} - -void test_w_logtest_check_input_request_bad_token_lenght(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_SUCCESS; - - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - cJSON event = {0}; - event.valuestring = strdup("event str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &event); - will_return(__wrap_cJSON_IsString, true); - - /* token */ - cJSON token = {0}; - token.valuestring = strdup("1234"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, true); - will_return(__wrap_cJSON_IsString, true); - will_return(__wrap_cJSON_IsString, true); - - expect_string(__wrap__mdebug1, formatted_msg, "(7309): '1234' is not a valid token"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7309): '1234' is not a valid token"); - - /* The optional parameters */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_null(msg); - assert_int_equal(retval, ret_expect); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(event.valuestring); - os_free(token.valuestring); -} - -void test_w_logtest_check_input_request_bad_token_type(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_SUCCESS; - - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - cJSON event = {0}; - event.valuestring = strdup("event str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &event); - will_return(__wrap_cJSON_IsString, true); - - /* token */ - cJSON token = {0}; - token.type = cJSON_Number; - token.valueint = 1234; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, false); - - will_return(__wrap_cJSON_IsString, false); - - will_return(__wrap_cJSON_PrintUnformatted, strdup("1234")); - - expect_string(__wrap__mdebug1, formatted_msg, "(7309): '1234' is not a valid token"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7309): '1234' is not a valid token"); - - /* The optional parameters */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_null(msg); - assert_int_equal(retval, ret_expect); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(event.valuestring); -} - -void test_w_logtest_check_input_request_debug_rules(void ** state) { - - cJSON root = {0}; - char * msg = NULL; - - int retval; - const int ret_expect = W_LOGTEST_CODE_SUCCESS; - OSList * list_msg = (OSList *) 2; - - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - cJSON event = {0}; - event.valuestring = strdup("event str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &event); - will_return(__wrap_cJSON_IsString, true); - - /* token */ - cJSON token = {0}; - token.valuestring = strdup("12345678"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, true); - will_return(__wrap_cJSON_IsString, true); - - /* The optional parameters */ - cJSON options = {0}; - options.valuestring = strdup("options"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &options); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7005): 'options' field must be a JSON object. The parameter will be ignored"); - will_return(__wrap_cJSON_IsObject, 0); - - retval = w_logtest_check_input_request(&root, &msg, list_msg); - - assert_int_equal(retval, ret_expect); - assert_null(msg); - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(event.valuestring); - os_free(token.valuestring); - os_free(options.valuestring) -} - - -// w_logtest_check_input_remove_session -void test_w_logtest_check_input_remove_session_not_string(void ** state) -{ - cJSON root = {0}; - char * msg = NULL; - - const int expected_retval = W_LOGTEST_CODE_INVALID_TOKEN; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 0); - - expect_string(__wrap__mdebug1, formatted_msg, - "(7316): Failure to remove session. token JSON field must be a string"); - - retval = w_logtest_check_input_remove_session(&root, &msg); - - assert_int_equal(retval, expected_retval); - assert_string_equal(msg, "(7316): Failure to remove session. token JSON field must be a string"); - - os_free(msg); - -} - -void test_w_logtest_check_input_remove_session_invalid_token(void ** state) -{ - cJSON root = {0}; - cJSON token = {0}; - token.valuestring = strdup("1234567"); - char * msg = NULL; - - const int expected_retval = W_LOGTEST_CODE_INVALID_TOKEN; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - - expect_string(__wrap__mdebug1, formatted_msg, "(7309): '1234567' is not a valid token"); - - assert_int_not_equal(W_LOGTEST_TOKEN_LENGH, strlen(token.valuestring)); - retval = w_logtest_check_input_remove_session(&root, &msg); - - assert_int_equal(retval, expected_retval); - assert_string_equal(msg, "(7309): '1234567' is not a valid token"); - - os_free(token.valuestring); - os_free(msg); -} - -void test_w_logtest_check_input_remove_session_ok(void ** state) -{ - cJSON root = {0}; - cJSON token = {0}; - token.valuestring = strdup("12345678"); - char * msg = NULL; - - const int expected_retval = W_LOGTEST_CODE_SUCCESS; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - - assert_int_equal(W_LOGTEST_TOKEN_LENGH, strlen(token.valuestring)); - - retval = w_logtest_check_input_remove_session(&root, &msg); - - assert_null(msg); - assert_int_equal(retval, expected_retval); - os_free(token.valuestring); -} - -/* w_logtest_process_request */ -void test_w_logtest_process_request_error_list(void ** state) { - - char raw_request[] = "Test request"; - w_logtest_connection_t connection; - char * retval; - - will_return(__wrap_OSList_Create, NULL); - expect_string(__wrap__merror, formatted_msg, "(1290): Unable to create a new list (calloc)."); - - retval = w_logtest_process_request(raw_request, &connection); - - assert_null(retval); - -} - -void test_w_logtest_process_request_error_check_input(void ** state) { - - char * retval; - w_logtest_connection_t connection; - - - /* w_logtest_add_msg_response */ - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - /* w_logtest_process_request */ - will_return(__wrap_OSList_Create, list_msg); - will_return(__wrap_OSList_SetMaxSize, 0); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - - /* Error w_logtest_check_input */ - char * input_raw_json = strdup("Test request"); - int pos_error = 7; - cJSON_error_ptr = input_raw_json + pos_error; - - will_return(__wrap_cJSON_ParseWithOpts, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7307): Error parsing JSON in position 7, ... Test request ..."); - - /* w_logtest_process_request */ - will_return(__wrap_cJSON_AddStringToObject, NULL); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_any(__wrap_cJSON_AddItemToObject, object); - expect_string(__wrap_cJSON_AddItemToObject, string, "data"); - - will_return(__wrap_cJSON_PrintUnformatted, "{json response}"); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - will_return(__wrap_pthread_mutex_destroy, 0); - - retval = w_logtest_process_request(input_raw_json, &connection); - - assert_string_equal(retval, "{json response}"); - - os_free(input_raw_json); - cJSON_error_ptr = NULL; - -} - -void test_w_logtest_process_request_type_remove_session_ok(void ** state) { - - char * retval; - char * input_raw_json = strdup("Test request"); - - /* w_logtest_add_msg_response */ - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - /* w_logtest_process_request */ - will_return(__wrap_OSList_Create, list_msg); - will_return(__wrap_OSList_SetMaxSize, 0); - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - - /* w_logtest_check_input */ - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, true); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, "remove_session"); - - // w_logtest_check_input_remove_session ok - cJSON token = {0}; - token.valuestring = strdup("12345678"); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - - /* w_logtest_process_request_remove_session_fail */ - w_logtest_connection_t connection = {0}; - connection.active_client = 5; - cJSON parameters = {0}; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, ¶meters); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7316): Failure to remove session. token JSON field must be a string"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7316): Failure to remove session. token JSON field must be a string"); - - - /*w_logtest_add_msg_response error*/ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - /* w_logtest_process_request */ - expect_string(__wrap_cJSON_AddNumberToObject, name, "codemsg"); - expect_value(__wrap_cJSON_AddNumberToObject, number, -1); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_any(__wrap_cJSON_AddItemToObject, object); - expect_string(__wrap_cJSON_AddItemToObject, string, "data"); - - will_return(__wrap_cJSON_PrintUnformatted, "{json response}"); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - will_return(__wrap_pthread_mutex_destroy, 0); - - retval = w_logtest_process_request(input_raw_json, &connection); - - assert_string_equal(retval, "{json response}"); - - os_free(input_raw_json); - os_free(token.valuestring); - -} - -void test_w_logtest_process_request_type_log_processing(void ** state) { - - char * retval; - char * input_raw_json = strdup("Test request"); - - w_logtest_connection_t connection = {0}; - connection.active_client = 5; - - /* w_logtest_add_msg_response */ - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - /* w_logtest_process_request */ - will_return(__wrap_OSList_Create, list_msg); - will_return(__wrap_OSList_SetMaxSize, 0); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, "log_processing"); - - // w_logtest_check_input_requeset ok - /* location */ - cJSON location = {0}; - location.valuestring = strdup("location str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &location); - will_return(__wrap_cJSON_IsString, true); - - /* log_format */ - cJSON log_format = {0}; - log_format.valuestring = strdup("log format str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &log_format); - will_return(__wrap_cJSON_IsString, true); - - /* event */ - cJSON event = {0}; - event.valuestring = strdup("event str"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &event); - will_return(__wrap_cJSON_IsString, true); - - /* token */ - cJSON token = {0}; - token.valuestring = strdup("12345678"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, true); - will_return(__wrap_cJSON_IsString, true); - - /* The optional parameters */ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* w_logtest_process_request */ - cJSON parameters = {0}; - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, ¶meters); - - /* log processing fail get session*/ - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* Generate token */ - random_bytes_result = 5555; // 0x00_00_15_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "000015b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - /* Initialize session*/ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 0); - - // test_w_logtest_remove_session_ok_error_load_decoder_cbd_rules_hash - will_return(__wrap_pthread_mutex_destroy, 0); - - - /* w_logtest_get_session */ - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7311): Failure to initializing session"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7311): Failure to initializing session"); - - - /*w_logtest_add_msg_response error*/ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "codemsg"); - expect_value(__wrap_cJSON_AddNumberToObject, number, -1); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_any(__wrap_cJSON_AddItemToObject, object); - expect_string(__wrap_cJSON_AddItemToObject, string, "data"); - - will_return(__wrap_cJSON_PrintUnformatted, "{json response}"); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - will_return(__wrap_pthread_mutex_destroy, 0); - - retval = w_logtest_process_request(input_raw_json, &connection); - - os_free(location.valuestring); - os_free(log_format.valuestring); - os_free(event.valuestring); - os_free(token.valuestring); - os_free(input_raw_json); - -} - -// test_w_logtest_generate_error_response_ok -void test_w_logtest_generate_error_response_ok(void ** state) { - const char * retval_exp = "{json response}"; - char * retval; - - cJSON response = {0}; - - will_return(__wrap_cJSON_CreateObject, &response); - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - expect_value(__wrap_cJSON_AddItemToObject, object, &response); - expect_string(__wrap_cJSON_AddItemToObject, string, "message"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - will_return(__wrap_cJSON_PrintUnformatted, "{json response}"); - - retval = w_logtest_generate_error_response("test msg"); - - assert_string_equal(retval_exp, retval); -} - -// Tests w_logtest_decoding_phase -void test_w_logtest_decoding_phase_program_name(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - - lf.program_name = strdup("program name test"); - os_calloc(1, sizeof(OSDecoderNode), session.decoderlist_forpname); - - expect_value(__wrap_DecodeEvent, node, session.decoderlist_forpname); - w_logtest_decoding_phase(&lf, &session); - - os_free(lf.program_name); - os_free(session.decoderlist_forpname); - -} - -void test_w_logtest_decoding_phase_no_program_name(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - - lf.program_name = NULL; - os_calloc(1, sizeof(OSDecoderNode), session.decoderlist_nopname); - - expect_value(__wrap_DecodeEvent, node, session.decoderlist_nopname); - w_logtest_decoding_phase(&lf, &session); - - os_free(session.decoderlist_nopname); -} - -// w_logtest_preprocessing_phase -void test_w_logtest_preprocessing_phase_json_location_to_scape_ok(void ** state) -{ - Eventinfo lf = {0}; - cJSON request = {0}; - - cJSON json_event = {0}; - cJSON json_event_child = {0}; - char * raw_event = strdup("{event}"); - char * str_location = strdup("loc:at\\ion"); - - lf.log = strdup("{event}"); - - json_event.child = &json_event_child; - - - const int expect_retval = 0; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_PrintUnformatted, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - will_return(__wrap_OS_CleanMSG, 0); - - - retval = w_logtest_preprocessing_phase(&lf, &request); - - assert_int_equal(retval, expect_retval); - - - os_free(str_location); - os_free(lf.log); - - -} - -void test_w_logtest_preprocessing_phase_json_event_ok(void ** state) -{ - Eventinfo lf = {0}; - cJSON request = {0}; - - cJSON json_event = {0}; - cJSON json_event_child = {0}; - char * raw_event = strdup("{event}"); - char * str_location = strdup("location"); - - lf.log = strdup("{event}"); - - json_event.child = &json_event_child; - - - const int expect_retval = 0; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_PrintUnformatted, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - will_return(__wrap_OS_CleanMSG, 0); - - - retval = w_logtest_preprocessing_phase(&lf, &request); - - assert_int_equal(retval, expect_retval); - - - os_free(str_location); - os_free(lf.log); - - -} - -void test_w_logtest_preprocessing_phase_json_event_fail(void ** state) -{ - Eventinfo * lf; - os_calloc(1, sizeof(Eventinfo), lf); - - cJSON request = {0}; - - cJSON json_event = {0}; - cJSON json_event_child = {0}; - char * raw_event = strdup("{event}"); - char * str_location = strdup("location"); - - json_event.child = &json_event_child; - - - const int expect_retval = -1; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_PrintUnformatted, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - will_return(__wrap_OS_CleanMSG, -1); - - - retval = w_logtest_preprocessing_phase(lf, &request); - - assert_int_equal(retval, expect_retval); - - os_free(str_location); - Free_Eventinfo(lf); - -} - -void test_w_logtest_preprocessing_phase_str_event_ok(void ** state) -{ - Eventinfo * lf; - os_calloc(1, sizeof(Eventinfo), lf); - - cJSON request = {0}; - cJSON json_event = {0}; - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - lf->log = strdup("test log"); - - const int expect_retval = 0; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - will_return(__wrap_OS_CleanMSG, 0); - - - retval = w_logtest_preprocessing_phase(lf, &request); - - assert_int_equal(retval, expect_retval); - - os_free(str_location); - os_free(raw_event); - os_free(lf->log); - os_free(lf); - -} - -void test_w_logtest_preprocessing_phase_str_event_fail(void ** state) -{ - Eventinfo * lf; - os_calloc(1, sizeof(Eventinfo), lf); - - cJSON request = {0}; - cJSON json_event = {0}; - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - - - const int expect_retval = -1; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - will_return(__wrap_OS_CleanMSG, -1); - - - retval = w_logtest_preprocessing_phase(lf, &request); - - assert_int_equal(retval, expect_retval); - - Free_Eventinfo(lf); - os_free(str_location); - os_free(raw_event); - -} - -// w_logtest_rulesmatching_phase -void test_w_logtest_rulesmatching_phase_no_load_rules(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = -1; - int retval; - - session.rule_list = NULL; - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - - -} - -void test_w_logtest_rulesmatching_phase_ossec_alert(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 0; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = OSSEC_ALERT; - lf.generated_rule = NULL; - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - - os_free(session.rule_list); - - -} - -void test_w_logtest_rulesmatching_phase_dont_match_category(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 0; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.category = FIREWALL; - - assert_int_not_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - - os_free(session.rule_list); - - -} - -void test_w_logtest_rulesmatching_phase_dont_match(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 0; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.category = SYSLOG; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, NULL); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - - os_free(session.rule_list); - - -} - -void test_w_logtest_rulesmatching_phase_match_level_0(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 0; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 0; - ruleinfo.category = SYSLOG; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - - os_free(session.rule_list); - -} - -void test_w_logtest_rulesmatching_phase_match_dont_ignore_first_time(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 1; - int retval; - - lf.generate_time = (time_t) 2020; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ignore_time = 1; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - assert_ptr_equal(lf.generated_rule->time_ignored, (time_t) 2020); - - os_free(session.rule_list); - -} - -void test_w_logtest_rulesmatching_phase_match_ignore_time_ignore(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 0; - int retval; - - lf.generate_time = (time_t) 2020; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ignore_time = 10; // ignore - ruleinfo.time_ignored = (time_t) 2015; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - - os_free(session.rule_list); - -} - -void test_w_logtest_rulesmatching_phase_match_dont_ignore_time_out_windows(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 1; - int retval; - - lf.generate_time = (time_t) 2020; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ignore_time = 3; // Dont ignore - ruleinfo.time_ignored = (time_t) 2015; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - assert_ptr_equal(lf.generated_rule->time_ignored, (time_t) 0); - - os_free(session.rule_list); - -} - -void test_w_logtest_rulesmatching_phase_match_ignore_event(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 0; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ckignore = 1; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - will_return(__wrap_IGnore, 1); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - - os_free(session.rule_list); - -} - -void test_w_logtest_rulesmatching_phase_match_and_if_matched_sid_ok(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 1; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ckignore = 0; - - - OSList pre_matched_list = {0}; - pre_matched_list.last_node = (OSListNode *) 80; - ruleinfo.sid_prev_matched = &pre_matched_list; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - will_return(__wrap_OSList_AddData, 1); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - assert_ptr_equal(lf.sid_node_to_delete, (OSListNode *) 80); - - os_free(session.rule_list); - -} - -void test_w_logtest_rulesmatching_phase_match_and_if_matched_sid_fail(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 1; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ckignore = 0; - - OSList pre_matched_list = {0}; - pre_matched_list.last_node = (OSListNode *) 80; - ruleinfo.sid_prev_matched = &pre_matched_list; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - will_return(__wrap_OSList_AddData, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "Unable to add data to sig list."); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - assert_ptr_equal(lf.sid_node_to_delete, (OSListNode *) 0); - - os_free(session.rule_list); - -} - -void test_w_logtest_rulesmatching_phase_match_and_group_prev_matched_fail(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 1; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ckignore = 0; - ruleinfo.sid_prev_matched = (OSList *) 0; - ruleinfo.group_prev_matched_sz = 1; - os_calloc(1, sizeof(RuleInfo *), ruleinfo.group_prev_matched); - - OSList pre_matched_list = {0}; - pre_matched_list.last_node = (OSListNode *) 80; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - will_return(__wrap_OSList_AddData, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "Unable to add data to grp list."); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - assert_ptr_equal(lf.sid_node_to_delete, (OSListNode *) 0); - - os_free(session.rule_list); - os_free(ruleinfo.group_prev_matched); - os_free(lf.group_node_to_delete); - -} - -void test_w_logtest_rulesmatching_phase_match_and_group_prev_matched(void ** state) -{ - Eventinfo lf = {0}; - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - const int expect_retval = 1; - int retval; - - OSDecoderInfo decoder_info = {0}; - lf.decoder_info = &decoder_info; - decoder_info.type = SYSLOG; - lf.generated_rule = NULL; - - RuleInfo ruleinfo = {0}; - ruleinfo.level = 5; - ruleinfo.category = SYSLOG; - ruleinfo.ckignore = 0; - ruleinfo.sid_prev_matched = (OSList *) 0; - ruleinfo.group_prev_matched_sz = 1; - os_calloc(1, sizeof(RuleInfo *), ruleinfo.group_prev_matched); - - OSList pre_matched_list = {0}; - pre_matched_list.last_node = (OSListNode *) 80; - - assert_int_equal(ruleinfo.category, decoder_info.type); - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - will_return(__wrap_OSList_AddData, 1); - - cJSON * rules_debug_list = NULL; - - retval = w_logtest_rulesmatching_phase(&lf, &session, rules_debug_list, &list_msg); - - assert_int_equal(retval, expect_retval); - assert_ptr_equal(lf.generated_rule, &ruleinfo); - - os_free(lf.group_node_to_delete); - os_free(session.rule_list); - os_free(ruleinfo.group_prev_matched); -} - -// w_logtest_process_log -void test_w_logtest_process_log_preprocessing_fail(void ** state) -{ - Config.decoder_order_size = 1; - - w_logtest_extra_data_t extra_data; - - extra_data.alert_generated = false; - - cJSON request = {0}; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - - cJSON * retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - will_return(__wrap_OS_CleanMSG, -1); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(1106): String not correctly formatted."); - - retval = w_logtest_process_log(&request, &session, &extra_data, &list_msg); - - assert_null(retval); - assert_false(extra_data.alert_generated); - os_free(str_location); - os_free(raw_event); -} - -void test_w_logtest_process_log_rule_match_fail(void ** state) -{ - Config.decoder_order_size = 1; - - w_logtest_extra_data_t extra_data; - - extra_data.alert_generated = false; - - cJSON request = {0}; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 0; - decoder_CleanMSG = &decoder_info; - - cJSON * retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - expect_value(__wrap_DecodeEvent, node, session.decoderlist_forpname); - - retval = w_logtest_process_log(&request, &session, &extra_data, &list_msg); - - assert_null(retval); - assert_false(extra_data.alert_generated); - os_free(str_location); - os_free(raw_event); - refill_OS_CleanMSG = false; - -} - -void test_w_logtest_process_log_rule_dont_match(void ** state) -{ - Config.decoder_order_size = 1; - - cJSON * output; - os_calloc(1, sizeof(cJSON), output); - - w_logtest_extra_data_t extra_data; - - extra_data.alert_generated = false; - - cJSON request = {0}; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - RuleInfo ruleinfo = {0}; - ruleinfo.category = FIREWALL; - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - cJSON * retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - // w_logtest_decoding_phase - expect_value(__wrap_DecodeEvent, node, session.decoderlist_forpname); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup("output example")); - will_return(__wrap_cJSON_Parse, output); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 0); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 0); - - retval = w_logtest_process_log(&request, &session, &extra_data, &list_msg); - - assert_non_null(retval); - assert_false(extra_data.alert_generated); - os_free(str_location); - os_free(raw_event); - os_free(session.rule_list); - refill_OS_CleanMSG = false; - os_free(output); - -} - -void test_w_logtest_process_log_rule_match(void ** state) -{ - Config.decoder_order_size = 1; - - w_logtest_extra_data_t extra_data; - - extra_data.alert_generated = false; - - Config.logbylevel = 3; - - cJSON * output; - os_calloc(1, sizeof(cJSON), output); - - cJSON request = {0}; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - RuleInfo ruleinfo = {0}; - ruleinfo.category = SYSLOG; - ruleinfo.level = 10; - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - cJSON * retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_value(__wrap_DecodeEvent, node, session.decoderlist_forpname); - - // w_logtest_rulesmatching_phase - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - - will_return(__wrap_ParseRuleComment, strdup("Comment test")); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup("output example")); - will_return(__wrap_cJSON_Parse, output); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - retval = w_logtest_process_log(&request, &session, &extra_data, &list_msg); - - assert_true(extra_data.alert_generated); - assert_non_null(retval); - - Free_Eventinfo(event_OS_AddEvent); - os_free(str_location); - os_free(raw_event); - os_free(session.rule_list); - refill_OS_CleanMSG = false; - os_free(output); -} - -void test_w_logtest_process_log_rule_match_level_0(void ** state) -{ - Config.decoder_order_size = 1; - - w_logtest_extra_data_t extra_data; - - extra_data.alert_generated = false; - - Config.logbylevel = 3; - - cJSON * output; - os_calloc(1, sizeof(cJSON), output); - - cJSON request = {0}; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - w_logtest_session_t session = {0}; - OSList list_msg = {0}; - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - RuleInfo ruleinfo = {0}; - ruleinfo.category = SYSLOG; - ruleinfo.level = 0; - - os_calloc(1, sizeof(RuleNode), session.rule_list); - session.rule_list->next = NULL; - session.rule_list->ruleinfo = &ruleinfo; - - cJSON * retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_value(__wrap_DecodeEvent, node, session.decoderlist_forpname); - - // w_logtest_rulesmatching_phase - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - - will_return(__wrap_ParseRuleComment, strdup("Comment test")); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup("output example")); - will_return(__wrap_cJSON_Parse, output); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 0); - expect_string(__wrap_cJSON_AddNumberToObject, name, "level"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - retval = w_logtest_process_log(&request, &session, &extra_data, &list_msg); - - assert_false(extra_data.alert_generated); - assert_non_null(retval); - - os_free(str_location); - os_free(raw_event); - os_free(session.rule_list); - refill_OS_CleanMSG = false; - os_free(output); -} - -// w_logtest_process_request_remove_session -void test_w_logtest_process_request_remove_session_invalid_token(void ** state) -{ - cJSON * json_request = (cJSON *) 8; - cJSON * json_response = (cJSON *) 2; - OSList list_msg = {0}; - OSList mock_list = {0}; - w_logtest_connection_t connection = {0}; - connection.active_client = 5; - - const int expect_retval = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7316): Failure to remove session. token JSON field must be a string"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &mock_list); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7316): Failure to remove session. token JSON field must be a string"); - - - /*w_logtest_add_msg_response error*/ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg.cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - - retval = w_logtest_process_request_remove_session(json_request, json_response, &mock_list, &connection); - - assert_int_equal(retval, expect_retval); - assert_int_equal(connection.active_client, 5); - - os_free(list_msg_node); -} - -void test_w_logtest_process_request_remove_session_session_not_found(void ** state) -{ - cJSON * json_request = (cJSON *) 8; - cJSON * json_response = (cJSON *) 2; - OSList list_msg = {0}; - w_logtest_connection_t connection = {0}; - connection.active_client = 5; - - cJSON token = {0}; - token.valuestring = "000015b3"; - - const int expect_retval = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_string(__wrap_OSHash_Get, key, "000015b3"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7004): No session found for token '000015b3'"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, NULL); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7004): No session found for token '000015b3'"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - /*w_logtest_add_msg_response error*/ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg.cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - - retval = w_logtest_process_request_remove_session(json_request, json_response, NULL, &connection); - - assert_int_equal(retval, expect_retval); - assert_int_equal(connection.active_client, 5); - os_free(list_msg_node); -} - -void test_w_logtest_process_request_remove_session_session_in_use(void ** state) -{ - cJSON * json_request = (cJSON *) 8; - cJSON * json_response = (cJSON *) 2; - OSList list_msg = {0}; - w_logtest_connection_t connection = {0}; - connection.active_client = 5; - - cJSON token = {0}; - token.valuestring = "000015b3"; - - const int expect_retval = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_string(__wrap_OSHash_Get, key, "000015b3"); - will_return(__wrap_OSHash_Get, (void *) 8); - will_return(__wrap_pthread_mutex_trylock, EBUSY); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, NULL); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7318): Failure to remove session '000015b3'"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - /*w_logtest_add_msg_response error*/ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg.cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - - retval = w_logtest_process_request_remove_session(json_request, json_response, NULL, &connection); - - assert_int_equal(retval, expect_retval); - assert_int_equal(connection.active_client, 5); - os_free(list_msg_node); -} - -void test_w_logtest_process_request_remove_session_ok(void ** state) -{ - cJSON * json_request = (cJSON *) 8; - cJSON * json_response = (cJSON *) 2; - OSList list_msg = {0}; - w_logtest_connection_t connection = {0}; - connection.active_client = 5; - - cJSON token = {0}; - token.valuestring = "000015b3"; - - w_logtest_session_t *session; - os_calloc(1, sizeof(w_logtest_session_t), session); - - const int expect_retval = W_LOGTEST_RCODE_SUCCESS; - int retval; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_string(__wrap_OSHash_Get, key, "000015b3"); - will_return(__wrap_OSHash_Get, session); - will_return(__wrap_pthread_mutex_trylock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - - // remove session ok - - expect_value(__wrap_OSHash_Delete, key, "000015b3"); - will_return(__wrap_OSHash_Delete, session); - - will_return(__wrap_OSStore_Free, session->decoder_store); - - will_return(__wrap_OSHash_Free, session); - - will_return(__wrap_OSHash_Free, session); - - will_return(__wrap_pthread_mutex_destroy, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_INFO); - expect_value(__wrap__os_analysisd_add_logmsg, list, NULL); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7206): The session '000015b3' was closed successfully"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7206): The session '000015b3' was closed successfully"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - /*w_logtest_add_msg_response error*/ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg.cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - - retval = w_logtest_process_request_remove_session(json_request, json_response, NULL, &connection); - - assert_int_equal(retval, expect_retval); - assert_int_equal(connection.active_client, 4); - - os_free(list_msg_node); -} - -void test_w_logtest_clients_handler_error_acept(void ** state) -{ - w_logtest_connection_t conection = {0}; - char expected_str[OS_SIZE_1024]; - - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - - will_return(__wrap_accept, -1); - - will_return(__wrap_pthread_mutex_unlock, 0); - errno = ENOMEM; - snprintf(expected_str, OS_SIZE_1024, "(7301): Failure to accept connection. Errno: %s", strerror(errno)); - - expect_string(__wrap__merror, formatted_msg, expected_str); - - will_return(__wrap_FOREVER, 0); - - assert_null(w_logtest_clients_handler(&conection)); - -} - -void test_w_logtest_clients_handler_error_acept_close_socket(void ** state) -{ - w_logtest_connection_t conection = {0}; - char expected_str[OS_SIZE_1024]; - - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - - will_return(__wrap_accept, -1); - - will_return(__wrap_pthread_mutex_unlock, 0); - errno = EBADF; - snprintf(expected_str, OS_SIZE_1024, "(7301): Failure to accept connection. Errno: %s", strerror(errno)); - - expect_string(__wrap__merror, formatted_msg, expected_str); - - assert_null(w_logtest_clients_handler(&conection)); - -} - -void test_w_logtest_clients_handler_recv_error(void ** state) -{ - w_logtest_connection_t conection = {0}; - char expected_str[OS_SIZE_1024]; - - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - - will_return(__wrap_accept, 5); - - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_OS_RecvSecureTCP, -1); - errno = ENOTCONN; - snprintf(expected_str, OS_SIZE_1024, "(7302): Failure to receive message: Errno: %s", strerror(ENOTCONN)); - - expect_string(__wrap__mdebug1, formatted_msg, expected_str); - - will_return(__wrap_close, 0); - will_return(__wrap_FOREVER, 0); - - - assert_null(w_logtest_clients_handler(&conection)); - -} - -void test_w_logtest_clients_handler_recv_msg_empty(void ** state) -{ - w_logtest_connection_t conection = {0}; - - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - - will_return(__wrap_accept, 5); - - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7314): Failure to receive message: empty or reception timeout"); - - will_return(__wrap_close, 0); - will_return(__wrap_FOREVER, 0); - - - assert_null(w_logtest_clients_handler(&conection)); - -} - -void test_w_logtest_clients_handler_recv_msg_oversize(void ** state) -{ - w_logtest_connection_t conection = {0}; - - will_return(__wrap_FOREVER, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - - will_return(__wrap_accept, 5); - - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_OS_RecvSecureTCP, -6); - - expect_string(__wrap__mdebug1, formatted_msg, "(7315): Failure to receive message: size is bigger than expected"); - - // w_logtest_generate_error_response - cJSON response = {0}; - will_return(__wrap_cJSON_CreateObject, &response); - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - expect_value(__wrap_cJSON_AddItemToObject, object, &response); - expect_string(__wrap_cJSON_AddItemToObject, string, "message"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - will_return(__wrap_cJSON_PrintUnformatted, strdup("{json response}")); - will_return(__wrap_OS_SendSecureTCP, 0); - - will_return(__wrap_close, 0); - will_return(__wrap_FOREVER, 0); - - - assert_null(w_logtest_clients_handler(&conection)); - -} - -void test_w_logtest_clients_handler_ok(void ** state) -{ - w_logtest_connection_t conection = {0}; - - will_return(__wrap_FOREVER, 1); - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_accept, 5); - will_return(__wrap_pthread_mutex_unlock, 0); - will_return(__wrap_OS_RecvSecureTCP, 100); - - /* w_logtest_process_request */ - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - will_return(__wrap_OSList_Create, list_msg); - will_return(__wrap_OSList_SetMaxSize, 0); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - will_return(__wrap_cJSON_CreateObject, (cJSON *) 8); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_IsObject, true); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, "remove_session"); - - /* w_logtest_check_input_remove_session ok */ - cJSON token = {0}; - token.valuestring = strdup("12345678"); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &token); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - will_return(__wrap_cJSON_IsString, (cJSON_bool) 1); - - /* w_logtest_process_request */ - cJSON parameter = {0}; - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, ¶meter); - - /* w_logtest_process_request_remove_session_fail */ - w_logtest_connection_t connection = {0}; - connection.active_client = 5; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "(7316): Failure to remove session. token JSON field must be a string"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7316): Failure to remove session. token JSON field must be a string"); - - - /*w_logtest_add_msg_response error*/ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - /* w_logtest_process_request */ - expect_string(__wrap_cJSON_AddNumberToObject, name, "codemsg"); - expect_value(__wrap_cJSON_AddNumberToObject, number, -1); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_any(__wrap_cJSON_AddItemToObject, object); - expect_string(__wrap_cJSON_AddItemToObject, string, "data"); - - will_return(__wrap_cJSON_PrintUnformatted, strdup("{json response}")); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_pthread_mutex_unlock, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - will_return(__wrap_pthread_mutex_destroy, 0); - - will_return(__wrap_OS_SendSecureTCP, 0); - - will_return(__wrap_close, 0); - will_return(__wrap_FOREVER, 0); - - assert_null(w_logtest_clients_handler(&conection)); - - os_free(token.valuestring); - -} - -// w_logtest_process_request_log_processing -void test_w_logtest_process_request_log_processing_fail_session(void ** state) -{ - cJSON json_request = {0}; - cJSON json_response = {0}; - OSList list_msg = {0}; - w_logtest_connection_t connection = {0}; - - const int extpect_retval = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval; - - // Fail get session - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* Generate token */ - random_bytes_result = 5555; // 0x00_00_15_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "000015b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - /* Initialize session*/ - char * decoder_file = "test.xml"; - Config.decoders = calloc(2, sizeof(char *)); - Config.decoders[0] = decoder_file; - - will_return(__wrap_time, 0); - will_return(__wrap_pthread_mutex_init, 0); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 0); - - // test_w_logtest_remove_session_ok_error_load_decoder_cbd_rules_hash - will_return(__wrap_pthread_mutex_destroy, 0); - - - /* w_logtest_get_session */ - expect_string(__wrap__mdebug1, formatted_msg, "(7311): Failure to initializing session"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7311): Failure to initializing session"); - - /* error w_logtest_add_msg_response */ - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_ERROR; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - - OSListNode * list_msg_node; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg.cur_node = list_msg_node; - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, &list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - os_free(Config.includes); - os_free(Config.decoders); - os_free(Config.lists); -} - -void test_w_logtest_process_request_log_processing_fail_process_log(void ** state) -{ - cJSON json_request = {0}; - cJSON json_response = {0}; - w_logtest_connection_t connection = {0}; - - const int extpect_retval = W_LOGTEST_RCODE_ERROR_PROCESS; - int retval; - - // get session - cJSON * json_request_token; - w_logtest_session_t active_session; - char * token = strdup("test_token"); - const time_t now = (time_t) 2020; - - os_calloc(1, sizeof(cJSON), json_request_token); - json_request_token->valuestring = token; - active_session.last_connection = 0; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, json_request_token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - - expect_value(__wrap_OSHash_Get, key, token); - will_return(__wrap_OSHash_Get, &active_session); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_time, now); - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_cJSON_AddStringToObject, NULL); - - /* now msg w_logtest_add_msg_response */ - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* Fail w_logtest_process_log */ - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - will_return(__wrap_OS_CleanMSG, -1); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(1106): String not correctly formatted."); - - // w_logtest_process_request_log_processing - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7312): Failed to process the event"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7312): Failed to process the event"); - - // w_logtest_add_msg_response - os_analysisd_log_msg_t * message_error; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message_error); - message_error->level = LOGLEVEL_ERROR; - message_error->msg = strdup("Test Message"); - message_error->file = NULL; - message_error->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message_error; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - - os_free(token); - os_free(json_request_token); - os_free(list_msg_node); - os_free(list_msg); - os_free(str_location); - os_free(raw_event); -} - -void test_w_logtest_process_request_log_processing_ok_and_alert(void ** state) -{ - cJSON json_request = {0}; - cJSON json_response = {0}; - w_logtest_connection_t connection = {0}; - - const int extpect_retval = W_LOGTEST_RCODE_SUCCESS; - int retval; - - // get session - cJSON * json_request_token; - w_logtest_session_t active_session; - char * token = strdup("test_token"); - const time_t now = (time_t) 2020; - - os_calloc(1, sizeof(cJSON), json_request_token); - json_request_token->valuestring = token; - active_session.last_connection = 0; - active_session.logbylevel = 3; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, json_request_token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_value(__wrap_OSHash_Get, key, token); - will_return(__wrap_OSHash_Get, &active_session); - will_return(__wrap_pthread_rwlock_unlock, 0); - - will_return(__wrap_pthread_mutex_lock, 0); - will_return(__wrap_time, now); - will_return(__wrap_pthread_mutex_unlock, 0); - - will_return(__wrap_cJSON_AddStringToObject, NULL); - - /* now msg w_logtest_add_msg_response */ - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - OSListNode * list_msg_node; - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON*) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* Alert w_logtest_process_log */ - Config.decoder_order_size = 1; - - cJSON * output; - os_calloc(1, sizeof(cJSON), output); - - cJSON request = {0}; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - RuleInfo ruleinfo = {0}; - ruleinfo.category = SYSLOG; - ruleinfo.level = 5; - - os_calloc(1, sizeof(RuleNode), active_session.rule_list); - active_session.rule_list->next = NULL; - active_session.rule_list->ruleinfo = &ruleinfo; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_any(__wrap_DecodeEvent, node); - - // w_logtest_rulesmatching_phase - will_return(__wrap_OS_CheckIfRuleMatch, &ruleinfo); - - will_return(__wrap_ParseRuleComment, "Comment test"); - - will_return(__wrap_Eventinfo_to_jsonstr, strdup("output example")); - will_return(__wrap_cJSON_Parse, output); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - // w_logtest_process_request_log_processing - - expect_any(__wrap_cJSON_AddItemToObject, object); - expect_string(__wrap_cJSON_AddItemToObject, string, "output"); - - // w_logtest_add_msg_response - will_return(__wrap_OSList_GetFirstNode, NULL); - - // Alert level - cJSON * json_level; - os_calloc(1, sizeof(cJSON), json_level); - cJSON * json_rule = (cJSON *) 8; - json_level->valueint = 5; - - - will_return(__wrap_cJSON_AddBoolToObject, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - - os_free(token); - os_free(json_request_token); - os_free(list_msg); - os_free(str_location); - os_free(raw_event); - os_free(json_level); - os_free(output); - os_free(active_session.rule_list); -} - -void test_w_logtest_process_request_log_processing_ok_session_expired(void ** state) { - cJSON json_request = {0}; - cJSON json_response = {0}; - w_logtest_connection_t connection = {0}; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - const int extpect_retval = -1; - int retval; - - // get session - cJSON * json_request_token; - w_logtest_session_t active_session; - char * token = strdup("test_token"); - const time_t now = (time_t) 2020; - - os_calloc(1, sizeof(cJSON), json_request_token); - json_request_token->valuestring = token; - active_session.last_connection = 0; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, json_request_token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_value(__wrap_OSHash_Get, key, token); - will_return(__wrap_OSHash_Get, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(7003): 'test_token' token expires"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7003): 'test_token' token expires"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - // w_logtest_initialize_session - - /* Generate session token */ - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_pthread_mutex_init, 0); - will_return(__wrap_time, 1212); - - /* w_logtest_ruleset_load */ - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 1); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list = (OSList *) 8; - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - will_return(__wrap_Accumulate_Init, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - /* w_logtest_register_session */ - will_return(__wrap_pthread_rwlock_wrlock, 0); - store_session = true; - expect_string(__wrap_OSHash_Add, key, "4995f9b3"); - expect_any(__wrap_OSHash_Add, data); - will_return(__wrap_OSHash_Add, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_INFO); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - /* now msg w_logtest_add_msg_response */ - OSListNode * list_msg_node; - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - will_return(__wrap_cJSON_AddStringToObject, NULL); - - // Optionals parameters - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* Alert w_logtest_process_log */ - Config.decoder_order_size = 1; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_any(__wrap_DecodeEvent, node); - - // w_logtest_process_request_log_processing - will_return(__wrap_pthread_mutex_unlock, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7312): Failed to process the event"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7312): Failed to process the event"); - - // w_logtest_add_msg_response - os_analysisd_log_msg_t * message_error; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message_error); - message_error->level = LOGLEVEL_ERROR; - message_error->msg = strdup("Test Message"); - message_error->file = NULL; - message_error->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message_error; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - - os_free(stored_session->token); - os_free(stored_session->eventlist); - os_free(stored_session); - os_free(token); - os_free(json_request_token); - os_free(list_msg); - os_free(str_location); - os_free(raw_event); - os_free(list_msg_node); - os_free(Config.includes); - os_free(Config.decoders); - os_free(Config.lists); - store_session = false; -} - -void test_w_logtest_process_request_log_processing_options_without_rules_debug(void ** state) { - cJSON json_request = {0}; - cJSON json_response = {0}; - w_logtest_connection_t connection = {0}; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - const int extpect_retval = -1; - int retval; - - // get session - cJSON * json_request_token; - w_logtest_session_t active_session; - char * token = strdup("test_token"); - const time_t now = (time_t) 2020; - - os_calloc(1, sizeof(cJSON), json_request_token); - json_request_token->valuestring = token; - active_session.last_connection = 0; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, json_request_token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_value(__wrap_OSHash_Get, key, token); - will_return(__wrap_OSHash_Get, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(7003): 'test_token' token expires"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7003): 'test_token' token expires"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - // w_logtest_initialize_session - - /* Generate session token */ - char * decoder_file = "test.xml"; - Config.decoders = calloc(2, sizeof(char *)); - Config.decoders[0] = decoder_file; - - char * cbd_file = "test.xml"; - Config.lists = calloc(2, sizeof(char *)); - Config.lists[0] = cbd_file; - - char * include_file = "test.xml"; - Config.includes = calloc(2, sizeof(char *)); - Config.includes[0] = include_file; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_pthread_mutex_init, 0); - will_return(__wrap_time, 1212); - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 0); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list = (OSList *) 8; - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - will_return(__wrap_Accumulate_Init, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - /* w_logtest_register_session */ - will_return(__wrap_pthread_rwlock_wrlock, 0); - store_session = true; - expect_string(__wrap_OSHash_Add, key, "4995f9b3"); - expect_any(__wrap_OSHash_Add, data); - will_return(__wrap_OSHash_Add, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_INFO); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - /* now msg w_logtest_add_msg_response */ - OSListNode * list_msg_node; - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - will_return(__wrap_cJSON_AddStringToObject, NULL); - - // Optional parameters - cJSON options = {0}; - options.valuestring = strdup("options"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &options); - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, NULL); - - /* Alert w_logtest_process_log */ - Config.decoder_order_size = 1; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_any(__wrap_DecodeEvent, node); - - // w_logtest_process_request_log_processing - will_return(__wrap_pthread_mutex_unlock, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7312): Failed to process the event"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7312): Failed to process the event"); - - // w_logtest_add_msg_response - os_analysisd_log_msg_t * message_error; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message_error); - message_error->level = LOGLEVEL_ERROR; - message_error->msg = strdup("Test Message"); - message_error->file = NULL; - message_error->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message_error; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - - os_free(stored_session->token); - os_free(stored_session->eventlist); - os_free(stored_session); - os_free(token); - os_free(json_request_token); - os_free(list_msg); - os_free(str_location); - os_free(raw_event); - os_free(list_msg_node); - os_free(Config.includes); - os_free(Config.decoders); - os_free(Config.lists); - os_free(options.valuestring); - store_session = false; - -} - -void test_w_logtest_process_request_log_processing_rules_debug_not_bolean(void ** state) { - cJSON json_request = {0}; - cJSON json_response = {0}; - w_logtest_connection_t connection = {0}; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - const int extpect_retval = -1; - int retval; - - // get session - cJSON * json_request_token; - w_logtest_session_t active_session; - char * token = strdup("test_token"); - const time_t now = (time_t) 2020; - - os_calloc(1, sizeof(cJSON), json_request_token); - json_request_token->valuestring = token; - active_session.last_connection = 0; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, json_request_token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_value(__wrap_OSHash_Get, key, token); - will_return(__wrap_OSHash_Get, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(7003): 'test_token' token expires"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7003): 'test_token' token expires"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - // w_logtest_initialize_session - - /* Generate session token */ - char * decoder_file = "test.xml"; - Config.decoders = calloc(2, sizeof(char *)); - Config.decoders[0] = decoder_file; - - char * cbd_file = "test.xml"; - Config.lists = calloc(2, sizeof(char *)); - Config.lists[0] = cbd_file; - - char * include_file = "test.xml"; - Config.includes = calloc(2, sizeof(char *)); - Config.includes[0] = include_file; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_pthread_mutex_init, 0); - will_return(__wrap_time, 1212); - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 0); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list = (OSList *) 8; - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - will_return(__wrap_Accumulate_Init, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - /* w_logtest_register_session */ - will_return(__wrap_pthread_rwlock_wrlock, 0); - store_session = true; - expect_string(__wrap_OSHash_Add, key, "4995f9b3"); - expect_any(__wrap_OSHash_Add, data); - will_return(__wrap_OSHash_Add, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_INFO); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - /* now msg w_logtest_add_msg_response */ - OSListNode * list_msg_node; - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - will_return(__wrap_cJSON_AddStringToObject, NULL); - - // Optional parameters - cJSON options = {0}; - options.valuestring = strdup("options"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &options); - - cJSON rules_debug = {0}; - rules_debug.valuestring = strdup("rules_debug_not_bolean"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &rules_debug); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7006): 'rules_debug' field must be a boolean. The parameter will be ignored"); - - /* Alert w_logtest_process_log */ - Config.decoder_order_size = 1; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_any(__wrap_DecodeEvent, node); - - // w_logtest_process_request_log_processing - will_return(__wrap_pthread_mutex_unlock, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7312): Failed to process the event"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7312): Failed to process the event"); - - // w_logtest_add_msg_response - os_analysisd_log_msg_t * message_error; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message_error); - message_error->level = LOGLEVEL_ERROR; - message_error->msg = strdup("Test Message"); - message_error->file = NULL; - message_error->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message_error; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - - os_free(stored_session->token); - os_free(stored_session->eventlist); - os_free(stored_session); - os_free(token); - os_free(json_request_token); - os_free(list_msg); - os_free(str_location); - os_free(raw_event); - os_free(list_msg_node); - os_free(Config.includes); - os_free(Config.decoders); - os_free(Config.lists); - os_free(options.valuestring); - os_free(rules_debug.valuestring); - store_session = false; -} - -void test_w_logtest_process_request_log_processing_rules_debug_false(void ** state) { - cJSON json_request = {0}; - cJSON json_response = {0}; - w_logtest_connection_t connection = {0}; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - const int extpect_retval = -1; - int retval; - - // get session - cJSON * json_request_token; - w_logtest_session_t active_session; - char * token = strdup("test_token"); - const time_t now = (time_t) 2020; - - os_calloc(1, sizeof(cJSON), json_request_token); - json_request_token->valuestring = token; - active_session.last_connection = 0; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, json_request_token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_value(__wrap_OSHash_Get, key, token); - will_return(__wrap_OSHash_Get, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(7003): 'test_token' token expires"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7003): 'test_token' token expires"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - // w_logtest_initialize_session - - /* Generate session token */ - char * decoder_file = "test.xml"; - Config.decoders = calloc(2, sizeof(char *)); - Config.decoders[0] = decoder_file; - - char * cbd_file = "test.xml"; - Config.lists = calloc(2, sizeof(char *)); - Config.lists[0] = cbd_file; - - char * include_file = "test.xml"; - Config.includes = calloc(2, sizeof(char *)); - Config.includes[0] = include_file; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_pthread_mutex_init, 0); - will_return(__wrap_time, 1212); - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 0); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list = (OSList *) 8; - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - will_return(__wrap_Accumulate_Init, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - /* w_logtest_register_session */ - will_return(__wrap_pthread_rwlock_wrlock, 0); - store_session = true; - expect_string(__wrap_OSHash_Add, key, "4995f9b3"); - expect_any(__wrap_OSHash_Add, data); - will_return(__wrap_OSHash_Add, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_INFO); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - /* now msg w_logtest_add_msg_response */ - OSListNode * list_msg_node; - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - will_return(__wrap_cJSON_AddStringToObject, NULL); - - // Optional parameters - cJSON options = {0}; - options.valuestring = strdup("options"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &options); - - cJSON rules_debug = {0}; - rules_debug.type = 1; - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &rules_debug); - - /* Alert w_logtest_process_log */ - Config.decoder_order_size = 1; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_any(__wrap_DecodeEvent, node); - - // w_logtest_process_request_log_processing - will_return(__wrap_pthread_mutex_unlock, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7312): Failed to process the event"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7312): Failed to process the event"); - - // w_logtest_add_msg_response - os_analysisd_log_msg_t * message_error; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message_error); - message_error->level = LOGLEVEL_ERROR; - message_error->msg = strdup("Test Message"); - message_error->file = NULL; - message_error->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message_error; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - - os_free(stored_session->token); - os_free(stored_session->eventlist); - os_free(stored_session); - os_free(token); - os_free(json_request_token); - os_free(list_msg); - os_free(str_location); - os_free(raw_event); - os_free(list_msg_node); - os_free(Config.includes); - os_free(Config.decoders); - os_free(Config.lists); - os_free(options.valuestring); - os_free(rules_debug.valuestring); - store_session = false; -} - -void test_w_logtest_process_request_log_processing_rules_debug_true(void ** state) { - cJSON json_request = {0}; - cJSON json_response = {0}; - w_logtest_connection_t connection = {0}; - OSList * list_msg; - os_calloc(1, sizeof(OSList), list_msg); - - const int extpect_retval = -1; - int retval; - - // get session - cJSON * json_request_token; - w_logtest_session_t active_session; - char * token = strdup("test_token"); - const time_t now = (time_t) 2020; - - os_calloc(1, sizeof(cJSON), json_request_token); - json_request_token->valuestring = token; - active_session.last_connection = 0; - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, json_request_token); - - will_return(__wrap_pthread_rwlock_wrlock, 0); - expect_value(__wrap_OSHash_Get, key, token); - will_return(__wrap_OSHash_Get, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(7003): 'test_token' token expires"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7003): 'test_token' token expires"); - - will_return(__wrap_pthread_rwlock_unlock, 0); - - // w_logtest_initialize_session - - /* Generate session token */ - char * decoder_file = "test.xml"; - Config.decoders = calloc(2, sizeof(char *)); - Config.decoders[0] = decoder_file; - - char * cbd_file = "test.xml"; - Config.lists = calloc(2, sizeof(char *)); - Config.lists[0] = cbd_file; - - char * include_file = "test.xml"; - Config.includes = calloc(2, sizeof(char *)); - Config.includes[0] = include_file; - - random_bytes_result = 1234565555; // 0x49_95_f9_b3 - expect_value(__wrap_randombytes, length, W_LOGTEST_TOKEN_LENGH >> 1); - - expect_string(__wrap_OSHash_Get_ex, key, "4995f9b3"); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_pthread_mutex_init, 0); - will_return(__wrap_time, 1212); - will_return(__wrap_ReadDecodeXML, 1); - will_return(__wrap_SetDecodeXML, 0); - will_return(__wrap_Lists_OP_LoadList, 0); - will_return(__wrap_Rules_OP_ReadRules, 0); - will_return(__wrap__setlevels, 0); - will_return(__wrap_OSHash_Create, 8); - will_return(__wrap_AddHash_Rule, 0); - - /* FTS init success */ - OSList * fts_list; - OSHash * fts_store; - OSList * list = (OSList *) 8; - OSHash * hash = (OSHash *) 8; - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OSList_Create, list); - will_return(__wrap_OSList_SetMaxSize, 1); - will_return(__wrap_OSHash_Create, hash); - expect_value(__wrap_OSHash_setSize, new_size, 2048); - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - will_return(__wrap_Accumulate_Init, 1); - - will_return(__wrap_pthread_mutex_lock, 0); - /* w_logtest_register_session */ - will_return(__wrap_pthread_rwlock_wrlock, 0); - store_session = true; - expect_string(__wrap_OSHash_Add, key, "4995f9b3"); - expect_any(__wrap_OSHash_Add, data); - will_return(__wrap_OSHash_Add, 0); - will_return(__wrap_pthread_rwlock_unlock, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_INFO); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7202): Session initialized with token '4995f9b3'"); - - /* now msg w_logtest_add_msg_response */ - OSListNode * list_msg_node; - os_analysisd_log_msg_t * message; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message); - message->level = LOGLEVEL_INFO; - message->msg = strdup("Test Message"); - message->file = NULL; - message->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message; - list_msg->cur_node = list_msg_node; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "INFO: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - will_return(__wrap_cJSON_AddStringToObject, NULL); - - // Optional parameters - cJSON options = {0}; - options.valuestring = strdup("options"); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &options); - - cJSON rules_debug = {0}; - rules_debug.type = 2; - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &rules_debug); - - will_return(__wrap_cJSON_CreateArray, (cJSON*) 8); - - /* Alert w_logtest_process_log */ - Config.decoder_order_size = 1; - cJSON json_event = {0}; - json_event.child = false; - - char * raw_event = strdup("event"); - char * str_location = strdup("location"); - - OSDecoderInfo decoder_info = {0}; - decoder_info.accumulate = 1; - decoder_info.type = SYSLOG; - decoder_CleanMSG = &decoder_info; - - - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, &json_event); - will_return(__wrap_cJSON_GetStringValue, raw_event); - - // w_logtest_preprocessing_phase - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - will_return(__wrap_cJSON_GetStringValue, str_location); - - refill_OS_CleanMSG = true; - will_return(__wrap_OS_CleanMSG, 0); - - // w_logtest_decoding_phase - expect_any(__wrap_DecodeEvent, node); - - // w_logtest_process_request_log_processing - will_return(__wrap_pthread_mutex_unlock, 0); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(7312): Failed to process the event"); - - expect_string(__wrap__mdebug1, formatted_msg, "(7312): Failed to process the event"); - - expect_any(__wrap_cJSON_AddItemToObject, object); - expect_string(__wrap_cJSON_AddItemToObject, string, "rules_debug"); - - // w_logtest_add_msg_response - os_analysisd_log_msg_t * message_error; - os_calloc(1, sizeof(os_analysisd_log_msg_t), message_error); - message_error->level = LOGLEVEL_ERROR; - message_error->msg = strdup("Test Message"); - message_error->file = NULL; - message_error->func = NULL; - os_calloc(1, sizeof(OSListNode), list_msg_node); - list_msg_node->data = message_error; - - will_return(__wrap_OSList_GetFirstNode, list_msg_node); - will_return(__wrap_cJSON_GetObjectItemCaseSensitive, (cJSON *) 8); - - will_return(__wrap_os_analysisd_string_log_msg, strdup("Test Message")); - - expect_string(__wrap_wm_strcat, str2, "ERROR: "); - will_return(__wrap_wm_strcat, 0); - - expect_string(__wrap_wm_strcat, str2, "Test Message"); - will_return(__wrap_wm_strcat, 0); - - will_return(__wrap_cJSON_CreateString, (cJSON *) 8); - - will_return(__wrap_OSList_GetFirstNode, NULL); - - retval = w_logtest_process_request_log_processing(&json_request, &json_response, list_msg, &connection); - - assert_int_equal(extpect_retval, retval); - - os_free(stored_session->token); - os_free(stored_session->eventlist); - os_free(stored_session); - os_free(token); - os_free(json_request_token); - os_free(list_msg); - os_free(str_location); - os_free(raw_event); - os_free(list_msg_node); - os_free(Config.includes); - os_free(Config.decoders); - os_free(Config.lists); - os_free(options.valuestring); - store_session = false; -} - -/* w_logtest_ruleset_free_config */ -void test_w_logtest_ruleset_free_config_empty_config(void ** state) { - _Config ruleset_config = {0}; - w_logtest_ruleset_free_config(&ruleset_config); -} - -void test_w_logtest_ruleset_free_config_ok(void ** state) { - _Config ruleset_config = {0}; - os_calloc(2, sizeof(char *), ruleset_config.includes); - os_strdup("test", ruleset_config.includes[0]); - os_calloc(3, sizeof(char *), ruleset_config.decoders); - os_strdup("test", ruleset_config.decoders[0]); - os_strdup("test", ruleset_config.decoders[1]); - os_calloc(3, sizeof(char *), ruleset_config.lists); - os_strdup("test", ruleset_config.lists[0]); - os_strdup("test", ruleset_config.lists[1]); - - w_logtest_ruleset_free_config(&ruleset_config); -} - -/* w_logtest_ruleset_load_config */ -void test_w_logtest_ruleset_load_config_empty_element(void ** state) { - bool retval = true; - bool EXPECT_RETVAL = false; - - OS_XML xml = {0}; - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - /* xml config */ - XML_NODE conf_section_nodes; - os_calloc(2, sizeof(xml_node *), conf_section_nodes); - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - retval = w_logtest_ruleset_load_config(&xml, conf_section_nodes, &ruleset_config, &list_msg); - assert_int_equal(retval, EXPECT_RETVAL); - - os_free(conf_section_nodes[0]); - os_free(conf_section_nodes); -} - -void test_w_logtest_ruleset_load_config_empty_option_node(void ** state) { - bool retval = true; - bool EXPECT_RETVAL = false; - - OS_XML xml = {0}; - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - /* xml config */ - XML_NODE conf_section_nodes; - os_calloc(2, sizeof(xml_node *), conf_section_nodes); - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - conf_section_nodes[0]->element = (char *) 1; - - will_return(__wrap_OS_GetElementsbyNode, NULL); - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - retval = w_logtest_ruleset_load_config(&xml, conf_section_nodes, &ruleset_config, &list_msg); - assert_int_equal(retval, EXPECT_RETVAL); - - os_free(conf_section_nodes[0]); - os_free(conf_section_nodes); -} - -void test_w_logtest_ruleset_load_config_fail_read_rules(void ** state) { - bool retval = true; - bool EXPECT_RETVAL = false; - - OS_XML xml = {0}; - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - /* xml config */ - XML_NODE conf_section_nodes; - os_calloc(2, sizeof(xml_node *), conf_section_nodes); - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - - /* xml ruleset */ - expect_function_call_any(__wrap_OS_ClearNode); - os_strdup("ruleset", conf_section_nodes[0]->element); - - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, -1); - - retval = w_logtest_ruleset_load_config(&xml, conf_section_nodes, &ruleset_config, &list_msg); - assert_int_equal(retval, EXPECT_RETVAL); - - os_free(conf_section_nodes[0]->element); - os_free(conf_section_nodes[0]); - os_free(conf_section_nodes); -} - -void test_w_logtest_ruleset_load_config_fail_read_alerts(void ** state) { - bool retval = true; - bool EXPECT_RETVAL = false; - - OS_XML xml = {0}; - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - /* xml config */ - XML_NODE conf_section_nodes; - os_calloc(2, sizeof(xml_node *), conf_section_nodes); - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - - /* xml ruleset */ - expect_function_call_any(__wrap_OS_ClearNode); - os_strdup("alerts", conf_section_nodes[0]->element); - - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, -1); - - retval = w_logtest_ruleset_load_config(&xml, conf_section_nodes, &ruleset_config, &list_msg); - assert_int_equal(retval, EXPECT_RETVAL); - - os_free(conf_section_nodes[0]->element); - os_free(conf_section_nodes[0]); - os_free(conf_section_nodes); -} - -void test_w_logtest_ruleset_load_config_ok(void ** state) { - - bool retval = false; - bool EXPECT_RETVAL = true; - - OS_XML xml = {0}; - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - /* xml config */ - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - - /* xml ruleset */ - expect_function_call_any(__wrap_OS_ClearNode); - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - retval = w_logtest_ruleset_load_config(&xml, conf_section_nodes, &ruleset_config, &list_msg); - - assert_int_equal(retval, EXPECT_RETVAL); - assert_int_equal(ruleset_config.logbylevel, session_level_alert); - assert_non_null(ruleset_config.decoders); - assert_non_null(ruleset_config.decoders[0]); - assert_non_null(ruleset_config.includes); - assert_non_null(ruleset_config.includes[0]); - assert_non_null(ruleset_config.lists); - assert_non_null(ruleset_config.lists[0]); - - os_free(conf_section_nodes[0]->element); - os_free(conf_section_nodes[0]); - os_free(conf_section_nodes[1]->element); - os_free(conf_section_nodes[1]); - os_free(conf_section_nodes); - w_logtest_ruleset_free_config(&ruleset_config); -} - -/* w_logtest_ruleset_load */ -void test_w_logtest_ruleset_load_fail_readxml(void ** state) { - - bool retval = true; - bool EXPECT_RETVAL = false; - - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - will_return(__wrap_OS_ReadXML, -1); - will_return(__wrap_OS_ReadXML, "unknown"); - will_return(__wrap_OS_ReadXML, 5); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, - "(1226): Error reading XML file 'etc/ossec.conf': " - "unknown (line 5)."); - - retval = w_logtest_ruleset_load(&ruleset_config, &list_msg); - - assert_int_equal(retval, EXPECT_RETVAL); -} - -void test_w_logtest_ruleset_empty_file(void ** state) { - - bool retval = true; - bool EXPECT_RETVAL = false; - - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - will_return(__wrap_OS_ReadXML, 0); - will_return(__wrap_OS_GetElementsbyNode, NULL); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "There are no configuration blocks inside of 'etc/ossec.conf'"); - - retval = w_logtest_ruleset_load(&ruleset_config, &list_msg); - - assert_int_equal(retval, EXPECT_RETVAL); -} - -void test_w_logtest_ruleset_load_null_element(void ** state) { - - bool retval = true; - bool EXPECT_RETVAL = false; - - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - - will_return(__wrap_OS_GetElementsbyNode, node); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - retval = w_logtest_ruleset_load(&ruleset_config, &list_msg); - - assert_int_equal(retval, EXPECT_RETVAL); -} - -void test_w_logtest_ruleset_load_empty_ossec_label(void ** state) { - - bool retval = false; - bool EXPECT_RETVAL = true; - - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - will_return(__wrap_OS_GetElementsbyNode, NULL); - - retval = w_logtest_ruleset_load(&ruleset_config, &list_msg); - - assert_int_equal(retval, EXPECT_RETVAL); -} - -void test_w_logtest_ruleset_load_fail_load_ruleset_config(void ** state) { - - bool retval = true; - bool EXPECT_RETVAL = false; - - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - - // Fail w_logtest_ruleset_load_config - XML_NODE conf_section_nodes; - os_calloc(2, sizeof(xml_node *), conf_section_nodes); - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, "(1202): Configuration error at 'etc/ossec.conf'."); - - retval = w_logtest_ruleset_load(&ruleset_config, &list_msg); - - assert_int_equal(retval, EXPECT_RETVAL); -} - -void test_w_logtest_ruleset_load_ok(void ** state) { - - bool retval = false; - bool EXPECT_RETVAL = true; - - _Config ruleset_config = {0}; - OSList list_msg = {0}; - - expect_function_call_any(__wrap_OS_ClearNode); - will_return(__wrap_OS_ReadXML, 0); - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - will_return(__wrap_OS_GetElementsbyNode, node); - - // w_logtest_ruleset_load_config ok - XML_NODE conf_section_nodes; - os_calloc(3, sizeof(xml_node *), conf_section_nodes); - // Alert - os_calloc(1, sizeof(xml_node), conf_section_nodes[0]); - // Ruleset - os_calloc(1, sizeof(xml_node), conf_section_nodes[1]); - will_return(__wrap_OS_GetElementsbyNode, conf_section_nodes); - - /* xml ruleset */ - os_strdup("alerts", conf_section_nodes[0]->element); - os_strdup("ruleset", conf_section_nodes[1]->element); - - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Alerts, 0); - - will_return(__wrap_OS_GetElementsbyNode, (xml_node **) calloc(1, sizeof(xml_node *))); - will_return(__wrap_Read_Rules, 0); - - retval = w_logtest_ruleset_load(&ruleset_config, &list_msg); - - assert_int_equal(retval, EXPECT_RETVAL); - assert_int_equal(ruleset_config.logbylevel, session_level_alert); - assert_non_null(ruleset_config.decoders); - assert_non_null(ruleset_config.decoders[0]); - assert_non_null(ruleset_config.includes); - assert_non_null(ruleset_config.includes[0]); - assert_non_null(ruleset_config.lists); - assert_non_null(ruleset_config.lists[0]); - - w_logtest_ruleset_free_config(&ruleset_config); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests w_logtest_init_parameters - cmocka_unit_test(test_w_logtest_init_parameters_invalid), - cmocka_unit_test(test_w_logtest_init_parameters_done), - // Tests w_logtest_init - cmocka_unit_test(test_w_logtest_init_error_parameters), - cmocka_unit_test(test_w_logtest_init_logtest_disabled), - cmocka_unit_test(test_w_logtest_init_conection_fail), - cmocka_unit_test(test_w_logtest_init_OSHash_create_fail), - cmocka_unit_test(test_w_logtest_init_OSHash_setSize_fail), - cmocka_unit_test(test_w_logtest_init_pthread_fail), - cmocka_unit_test(test_w_logtest_init_unlink_fail), - cmocka_unit_test(test_w_logtest_init_done), - // Tests w_logtest_fts_init - cmocka_unit_test(test_w_logtest_fts_init_create_list_failure), - cmocka_unit_test(test_w_logtest_fts_init_SetMaxSize_failure), - cmocka_unit_test(test_w_logtest_fts_init_create_hash_failure), - cmocka_unit_test(test_w_logtest_fts_init_setSize_failure), - cmocka_unit_test(test_w_logtest_fts_init_success), - // Tests w_logtest_remove_session - cmocka_unit_test(test_w_logtest_remove_session_fail), - cmocka_unit_test(test_w_logtest_remove_session_OK), - // Tests w_logtest_check_inactive_sessions - cmocka_unit_test(test_w_logtest_check_inactive_sessions_no_remove), - cmocka_unit_test(test_w_logtest_check_inactive_sessions_remove), - // Test w_logtest_remove_old_session - cmocka_unit_test(test_w_logtest_remove_old_session_Begin_fail), - cmocka_unit_test(test_w_logtest_remove_old_session_one), - cmocka_unit_test(test_w_logtest_remove_old_session_many), - // Test w_logtest_register_session - cmocka_unit_test(test_w_logtest_register_session_dont_remove), - cmocka_unit_test(test_w_logtest_register_session_remove_old), - // Tests w_logtest_initialize_session - cmocka_unit_test(test_w_logtest_initialize_session_error_load_ruleset), - cmocka_unit_test(test_w_logtest_initialize_session_error_decoders), - cmocka_unit_test(test_w_logtest_initialize_session_error_set_decoders), - cmocka_unit_test(test_w_logtest_initialize_session_error_cbd_list), - cmocka_unit_test(test_w_logtest_initialize_session_error_rules), - cmocka_unit_test(test_w_logtest_initialize_session_error_hash_rules), - cmocka_unit_test(test_w_logtest_initialize_session_error_fts_init), - cmocka_unit_test(test_w_logtest_initialize_session_error_accumulate_init), - cmocka_unit_test(test_w_logtest_initialize_session_success), - cmocka_unit_test(test_w_logtest_initialize_session_success_duplicate_key), - // Tests w_logtest_generate_token - cmocka_unit_test(test_w_logtest_generate_token_success), - cmocka_unit_test(test_w_logtest_generate_token_success_empty_bytes), - // Tests w_logtest_add_msg_response - cmocka_unit_test(test_w_logtest_add_msg_response_null_list), - cmocka_unit_test(test_w_logtest_add_msg_response_new_field_msg), - cmocka_unit_test(test_w_logtest_add_msg_response_error_msg), - cmocka_unit_test(test_w_logtest_add_msg_response_warn_msg), - cmocka_unit_test(test_w_logtest_add_msg_response_warn_dont_remplaze_error_msg), - cmocka_unit_test(test_w_logtest_add_msg_response_info_msg), - // Tests w_logtest_check_input - cmocka_unit_test(test_w_logtest_check_input_malformed_json_long), - cmocka_unit_test(test_w_logtest_check_input_malformed_json_short), - cmocka_unit_test(test_w_logtest_check_input_parameter_not_found), - cmocka_unit_test(test_w_logtest_check_input_parameter_bad_type), - cmocka_unit_test(test_w_logtest_check_input_command_not_found), - cmocka_unit_test(test_w_logtest_check_input_command_bad_type), - cmocka_unit_test(test_w_logtest_check_input_invalid_command), - cmocka_unit_test(test_w_logtest_check_input_type_remove_sesion_ok), - cmocka_unit_test(test_w_logtest_check_input_type_request_ok), - // Tests w_logtest_check_input_request - cmocka_unit_test(test_w_logtest_check_input_request_empty_json), - cmocka_unit_test(test_w_logtest_check_input_request_missing_location), - cmocka_unit_test(test_w_logtest_check_input_request_missing_log_format), - cmocka_unit_test(test_w_logtest_check_input_request_missing_event), - cmocka_unit_test(test_w_logtest_check_input_request_invalid_event), - cmocka_unit_test(test_w_logtest_check_input_request_full_empty_token), - cmocka_unit_test(test_w_logtest_check_input_request_full), - cmocka_unit_test(test_w_logtest_check_input_request_bad_token_lenght), - cmocka_unit_test(test_w_logtest_check_input_request_bad_token_type), - cmocka_unit_test(test_w_logtest_check_input_request_debug_rules), - // Tests w_logtest_check_input_remove_session - cmocka_unit_test(test_w_logtest_check_input_remove_session_not_string), - cmocka_unit_test(test_w_logtest_check_input_remove_session_invalid_token), - cmocka_unit_test(test_w_logtest_check_input_remove_session_ok), - // Tests w_logtest_process_request - cmocka_unit_test(test_w_logtest_process_request_error_list), - cmocka_unit_test(test_w_logtest_process_request_error_check_input), - cmocka_unit_test(test_w_logtest_process_request_type_remove_session_ok), - cmocka_unit_test(test_w_logtest_process_request_type_log_processing), - // Tests w_logtest_generate_error_response - cmocka_unit_test(test_w_logtest_generate_error_response_ok), - // Tests w_logtest_preprocessing_phase - cmocka_unit_test(test_w_logtest_preprocessing_phase_json_location_to_scape_ok), - cmocka_unit_test(test_w_logtest_preprocessing_phase_json_event_ok), - cmocka_unit_test(test_w_logtest_preprocessing_phase_json_event_fail), - cmocka_unit_test(test_w_logtest_preprocessing_phase_str_event_ok), - cmocka_unit_test(test_w_logtest_preprocessing_phase_str_event_fail), - // Tests w_logtest_decoding_phase - cmocka_unit_test(test_w_logtest_decoding_phase_program_name), - cmocka_unit_test(test_w_logtest_decoding_phase_no_program_name), - // Tests w_logtest_rulesmatching_phase - cmocka_unit_test(test_w_logtest_rulesmatching_phase_no_load_rules), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_ossec_alert), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_dont_match_category), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_dont_match), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_level_0), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_dont_ignore_first_time), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_ignore_time_ignore), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_dont_ignore_time_out_windows), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_ignore_event), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_and_if_matched_sid_ok), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_and_if_matched_sid_fail), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_and_group_prev_matched), - cmocka_unit_test(test_w_logtest_rulesmatching_phase_match_and_group_prev_matched_fail), - // Tests w_logtest_process_log - cmocka_unit_test(test_w_logtest_process_log_preprocessing_fail), - cmocka_unit_test(test_w_logtest_process_log_rule_match_fail), - cmocka_unit_test(test_w_logtest_process_log_rule_dont_match), - cmocka_unit_test(test_w_logtest_process_log_rule_match), - cmocka_unit_test(test_w_logtest_process_log_rule_match_level_0), - // Tests w_logtest_process_request_remove_session - cmocka_unit_test(test_w_logtest_process_request_remove_session_invalid_token), - cmocka_unit_test(test_w_logtest_process_request_remove_session_session_not_found), - cmocka_unit_test(test_w_logtest_process_request_remove_session_session_in_use), - cmocka_unit_test(test_w_logtest_process_request_remove_session_ok), - // Tests w_logtest_clients_handler - cmocka_unit_test(test_w_logtest_clients_handler_error_acept), - cmocka_unit_test(test_w_logtest_clients_handler_error_acept_close_socket), - cmocka_unit_test(test_w_logtest_clients_handler_recv_error), - cmocka_unit_test(test_w_logtest_clients_handler_recv_msg_empty), - cmocka_unit_test(test_w_logtest_clients_handler_recv_msg_oversize), - cmocka_unit_test(test_w_logtest_clients_handler_ok), - // w_logtest_process_request_log_processing - cmocka_unit_test(test_w_logtest_process_request_log_processing_fail_session), - cmocka_unit_test(test_w_logtest_process_request_log_processing_fail_process_log), - cmocka_unit_test(test_w_logtest_process_request_log_processing_ok_and_alert), - cmocka_unit_test(test_w_logtest_process_request_log_processing_ok_session_expired), - // w_logtest_ruleset_free_config - cmocka_unit_test(test_w_logtest_ruleset_free_config_empty_config), - cmocka_unit_test(test_w_logtest_ruleset_free_config_ok), - // w_logtest_ruleset_load_config - cmocka_unit_test(test_w_logtest_ruleset_load_config_empty_element), - cmocka_unit_test(test_w_logtest_ruleset_load_config_empty_option_node), - cmocka_unit_test(test_w_logtest_ruleset_load_config_fail_read_rules), - cmocka_unit_test(test_w_logtest_ruleset_load_config_fail_read_alerts), - cmocka_unit_test(test_w_logtest_ruleset_load_config_ok), - // w_logtest_ruleset_load - cmocka_unit_test(test_w_logtest_ruleset_load_fail_readxml), - cmocka_unit_test(test_w_logtest_ruleset_empty_file), - cmocka_unit_test(test_w_logtest_ruleset_load_null_element), - cmocka_unit_test(test_w_logtest_ruleset_load_empty_ossec_label), - cmocka_unit_test(test_w_logtest_ruleset_load_fail_load_ruleset_config), - cmocka_unit_test(test_w_logtest_ruleset_load_ok), - - }; - - return cmocka_run_group_tests(tests, setup_group, NULL); -} diff --git a/src/unit_tests/analysisd/test_mitre.c b/src/unit_tests/analysisd/test_mitre.c deleted file mode 100644 index 5b1e52ccb4b..00000000000 --- a/src/unit_tests/analysisd/test_mitre.c +++ /dev/null @@ -1,694 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - - -#include "../analysisd/mitre.h" - -extern OSHash *techniques_table; - -/* setup/teardown */ - -static int setup_group(void **state) { - if (setup_hashmap(state) != 0) { - return 1; - } - - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - - if (teardown_hashmap(NULL) != 0) { - return -1; - } - - return 0; -} - -static int teardown_techniques_table(void **state) { - OSHash_Free(techniques_table); - return 0; -} - -/* tests */ - -void test_queryid_error_socket(void **state) -{ - (void) state; - int ret; - cJSON * id_array = NULL; - - will_return(__wrap_wdbc_query_parse_json, -2); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_string(__wrap__merror, formatted_msg, "Unable to connect to socket 'queue/db/wdb'"); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryid_no_response(void **state) -{ - (void) state; - int ret; - cJSON * id_array = NULL; - - will_return(__wrap_wdbc_query_parse_json, -1); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_string(__wrap__merror, formatted_msg, "No response from wazuh-db."); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryid_bad_response(void **state) -{ - (void) state; - int ret; - cJSON * id_array = NULL; - - char *response_ids = "err not found"; - will_return(__wrap_wdbc_query_parse_json, 1); - will_return(__wrap_wdbc_query_parse_json, response_ids); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_string(__wrap__merror, formatted_msg, "Bad response from wazuh-db: not found"); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryid_error_parse(void **state) -{ - (void) state; - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":}]"); - - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryid_empty_array(void **state) -{ - (void) state; - int ret; - cJSON * id_array = cJSON_Parse("[ ]"); - - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database has 0 elements."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryid_error_parse_technique_id(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"ids\":\"technique-0001\"},{\"ids\":\"technique-0002\"}]"); - - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - expect_string(__wrap__merror, formatted_msg, "It was not possible to get Mitre technique ID."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryid_error_parse_technique_name(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\"},{\"id\":\"technique-0002\"}]"); - - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - expect_string(__wrap__merror, formatted_msg, "It was not possible to get Mitre technique name."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryid_error_parse_technique_external_id(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\"}]"); - - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - expect_string(__wrap__merror, formatted_msg, "It was not possible to get Mitre technique external ID."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_querytactics_error_socket(void **state) { - (void) state; - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = NULL; - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, -2); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - expect_string(__wrap__merror, formatted_msg, "Unable to connect to socket 'queue/db/wdb'"); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_querytactics_no_response(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = NULL; - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, -1); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - expect_string(__wrap__merror, formatted_msg, "No response from wazuh-db."); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_querytactics_bad_response(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = NULL; - char * response_tactics = "err not found"; - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 1); - will_return(__wrap_wdbc_query_parse_json, response_tactics); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - expect_string(__wrap__merror, formatted_msg, "Bad response from wazuh-db: not found"); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_querytactics_error_parse(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"phase_name\":}]"); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_querytactics_empty_array(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[ ]"); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database has 0 elements."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_querytactics_error_parse_tactics(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"phase\":\"Discovery\"}]"); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - expect_string(__wrap__merror, formatted_msg, "It was not possible to get MITRE tactic ID."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryname_error_socket(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = NULL; - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, -2); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - expect_string(__wrap__merror, formatted_msg, "Unable to connect to socket 'queue/db/wdb'"); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryname_no_response(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = NULL; - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, -1); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - expect_string(__wrap__merror, formatted_msg, "No response from wazuh-db."); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryname_bad_response(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = NULL; - char * response_tactics = "err not found"; - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, 1); - will_return(__wrap_wdbc_query_parse_json, response_tactics); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - expect_string(__wrap__merror, formatted_msg, "Bad response from wazuh-db: not found"); - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryname_error_parse(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = cJSON_Parse("[{\"info\":}]"); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - expect_string(__wrap__merror, formatted_msg, "Response from the Mitre database cannot be parsed."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryname_error_parse_technique_name(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = cJSON_Parse("[{\"info\":\"Tactic1\"}]"); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - expect_string(__wrap__merror, formatted_msg, "It was not possible to get Mitre tactic name."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_queryname_error_parse_technique_external_id(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"},{\"id\":\"technique-0002\",\"name\":\"Technique2\",\"external_id\":\"T1002\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = cJSON_Parse("[{\"name\":\"Tactic1\"}]"); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - expect_string(__wrap__merror, formatted_msg, "It was not possible to get Mitre tactic external ID."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_query_tactics_error_filling_technique(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = cJSON_Parse("[{\"name\":\"Tactic1\",\"external_id\":\"TA001\"}]"); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - /* OSHash */ - expect_string(__wrap_OSHash_Add, key, "T1001"); - will_return(__wrap_OSHash_Add, 0); - - expect_string(__wrap__merror, formatted_msg, "Mitre techniques hash table adding failed. Mitre Technique ID 'T1001' cannot be stored."); - expect_string(__wrap__merror, formatted_msg, "Mitre matrix information could not be loaded."); - - ret = mitre_load(); - assert_int_equal(-1, ret); - -} - -void test_query_tactics_success(void **state) { - int ret; - cJSON * id_array = cJSON_Parse("[{\"id\":\"technique-0001\",\"name\":\"Technique1\",\"external_id\":\"T1001\"}]"); - cJSON * tactic_array = cJSON_Parse("[{\"tactic_id\":\"tactic-0001\"}]"); - cJSON * tactic_info_array = cJSON_Parse("[{\"name\":\"Tactic1\",\"external_id\":\"TA001\"}]"); - cJSON * technique_last = cJSON_Parse(" "); - - /* Mitre's techniques IDs query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, id_array); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_hashmap); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - /* Mitre's tactics query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_array); - - /* Mitre tactic's information query */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, tactic_info_array); - - /* OSHash */ - expect_string(__wrap_OSHash_Add, key, "T1001"); - will_return(__wrap_OSHash_Add, 1); - - /* Last Getting technique ID and name from Mitre's database in Wazuh-DB */ - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, technique_last); - - ret = mitre_load(); - assert_int_equal(0, ret); - -} - -void test_mitre_get_attack(void **state) { - technique_data tech; - technique_data tech_rec; - technique_data *p_tech; - char *mitre_id = "T1001"; - p_tech = &tech_rec; - - tech.technique_id = mitre_id; - tech.technique_name = "Technique1"; - - /* set string to receive*/ - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, mitre_id); - will_return(__wrap_OSHash_Get, &tech); - - p_tech = mitre_get_attack((const char *)mitre_id); - /* compare name string searched by id */ - assert_string_equal(tech.technique_name, p_tech->technique_name); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_queryid_error_socket), - cmocka_unit_test(test_queryid_no_response), - cmocka_unit_test(test_queryid_bad_response), - cmocka_unit_test(test_queryid_error_parse), - cmocka_unit_test(test_queryid_empty_array), - cmocka_unit_test(test_queryid_error_parse_technique_id), - cmocka_unit_test(test_queryid_error_parse_technique_name), - cmocka_unit_test(test_queryid_error_parse_technique_external_id), - cmocka_unit_test(test_querytactics_error_socket), - cmocka_unit_test(test_querytactics_no_response), - cmocka_unit_test(test_querytactics_bad_response), - cmocka_unit_test(test_querytactics_error_parse), - cmocka_unit_test(test_querytactics_empty_array), - cmocka_unit_test(test_querytactics_error_parse_tactics), - cmocka_unit_test(test_queryname_error_socket), - cmocka_unit_test(test_queryname_no_response), - cmocka_unit_test(test_queryname_bad_response), - cmocka_unit_test(test_queryname_error_parse), - cmocka_unit_test(test_queryname_error_parse_technique_name), - cmocka_unit_test(test_queryname_error_parse_technique_external_id), - cmocka_unit_test(test_query_tactics_error_filling_technique), - cmocka_unit_test(test_query_tactics_success), - cmocka_unit_test(test_mitre_get_attack), - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/analysisd/test_rule_list.c b/src/unit_tests/analysisd/test_rule_list.c deleted file mode 100644 index d027e23feb9..00000000000 --- a/src/unit_tests/analysisd/test_rule_list.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../analysisd/eventinfo.h" -#include "../../analysisd/cdb/cdb.h" -#include "../../analysisd/analysisd.h" -#include "../../analysisd/rules.h" - -void os_count_rules(RuleNode *node, int *num_rules); -void os_remove_rulenode(RuleNode *node, RuleInfo **rules, int *pos, int *max_size); -void os_remove_ruleinfo(RuleInfo *ruleinfo); -void os_remove_rules_list(RuleNode *node); -int OS_AddChild(RuleInfo *read_rule, RuleNode **r_node, OSList* log_msg); - -/* setup/teardown */ - -static int setup_AR(void **state) { - active_response *ar_info; - os_calloc(1, sizeof(active_response), ar_info); - - os_strdup("test_ar_name", ar_info->name); - os_strdup("test_ar_command", ar_info->command); - os_strdup("test_ar_agent_id", ar_info->agent_id); - os_strdup("test_ar_rules_id", ar_info->rules_id); - os_strdup("test_ar_rules_group", ar_info->rules_group); - os_calloc(1, sizeof(ar_command), ar_info->ar_cmd); - os_strdup("test_ar_command_name", ar_info->ar_cmd->name); - os_strdup("test_ar_command_executable", ar_info->ar_cmd->executable); - os_strdup("test_ar_command_extra_args", ar_info->ar_cmd->extra_args); - - *state = ar_info; - return OS_SUCCESS; -} - -static int teardown_AR(void **state) { - active_response *ar_info = *state; - - os_free(ar_info->name); - os_free(ar_info->command); - os_free(ar_info->agent_id); - os_free(ar_info->rules_id); - os_free(ar_info->rules_group); - os_free(ar_info->ar_cmd->name); - os_free(ar_info->ar_cmd->executable); - os_free(ar_info->ar_cmd->extra_args); - os_free(ar_info->ar_cmd); - os_free(ar_info); - - return OS_SUCCESS; -} - -/* wraps */ - -void __wrap_OSMatch_FreePattern(OSMatch *reg) { - return; -} - -void __wrap_OSRegex_FreePattern(OSRegex *reg) { - return; -} - -void __wrap_os_remove_cdbrules(ListRule **l_rule) { - os_free(*l_rule); - return; -} - -void __wrap__os_analysisd_add_logmsg(OSList * list, int level, int line, const char * func, - const char * file, char * msg, ...) { - char formatted_msg[OS_MAXSTR]; - va_list args; - - va_start(args, msg); - vsnprintf(formatted_msg, OS_MAXSTR, msg, args); - va_end(args); - - check_expected(level); - check_expected_ptr(list); - check_expected(formatted_msg); -} - - -/* tests */ - -/* os_count_rules */ -void test_os_count_rules_no_child(void **state) -{ - RuleNode *node; - os_calloc(1,sizeof(RuleNode), node); - - int num_rules = 0; - - os_count_rules(node, &num_rules); - - os_free(node); - -} - -void test_os_count_rules_child(void **state) -{ - RuleNode *node; - os_calloc(1, sizeof(RuleNode), node); - os_calloc(1, sizeof(OSDecoderNode), node->child); - - int num_rules = 0; - - os_count_rules(node, &num_rules); - - os_free(node->child); - os_free(node); - -} - -/* os_remove_rulenode */ -void test_os_remove_rulenode_no_child(void **state) -{ - int pos = 0; - int max_size = 2; - - RuleNode * node; - os_calloc(1, sizeof(RuleNode), node); - os_calloc(1, sizeof(RuleInfo), node->ruleinfo); - node->ruleinfo->internal_saving = false; - - RuleInfo **rules_info; - os_calloc(1, sizeof(OSDecoderInfo *), rules_info); - - int num_decoders = 0; - - os_remove_rulenode(node, rules_info, &pos, &max_size); - - os_free(rules_info[0]); - os_free(rules_info); - -} - -void test_os_remove_rulenode_child(void **state) -{ - int pos = 0; - int max_size = 2; - - RuleNode * node; - os_calloc(1, sizeof(RuleNode), node); - os_calloc(1, sizeof(RuleNode), node->child); - os_calloc(1, sizeof(RuleInfo), node->ruleinfo); - os_calloc(1, sizeof(RuleInfo), node->child->ruleinfo); - node->ruleinfo->internal_saving = false; - node->child->ruleinfo->internal_saving = false; - - RuleInfo **rules_info; - os_calloc(2, sizeof(RuleInfo *), rules_info); - - int num_decoders = 0; - - os_remove_rulenode(node, rules_info, &pos, &max_size); - - os_free(rules_info[0]); - os_free(rules_info[1]); - os_free(rules_info); - -} - -/* os_remove_ruleinfo */ -void test_os_remove_ruleinfo_NULL(void **state) -{ - RuleInfo *ruleinfo = NULL; - - os_remove_ruleinfo(ruleinfo); - -} - -void test_os_remove_ruleinfo_OK(void **state) -{ - RuleInfo *ruleinfo; - os_calloc(1, sizeof(RuleInfo), ruleinfo); - - os_calloc(2, sizeof(char*), ruleinfo->ignore_fields); - os_strdup("test_ignore_fields", ruleinfo->ignore_fields[0]); - - os_calloc(2, sizeof(char*), ruleinfo->ckignore_fields); - os_strdup("test_ckignore_felds", ruleinfo->ckignore_fields[0]); - - expect_any(__wrap_OS_IsValidIP, ip_address); - expect_any(__wrap_OS_IsValidIP, final_ip); - will_return(__wrap_OS_IsValidIP, -1); - w_expression_add_osip(&ruleinfo->srcip, "0.0.0.0"); - - expect_any(__wrap_OS_IsValidIP, ip_address); - expect_any(__wrap_OS_IsValidIP, final_ip); - will_return(__wrap_OS_IsValidIP, -1); - w_expression_add_osip(&ruleinfo->dstip, "0.0.0.0"); - - os_calloc(2, sizeof(FieldInfo*), ruleinfo->fields); - os_calloc(1, sizeof(FieldInfo), ruleinfo->fields[0]); - os_strdup("test_name", ruleinfo->fields[0]->name); - os_calloc(1, sizeof(OSRegex), ruleinfo->fields[0]->regex); - - os_calloc(1, sizeof(RuleInfoDetail), ruleinfo->info_details); - - os_calloc(2, sizeof(active_response*), ruleinfo->ar); - ruleinfo->ar[0] = *state; - os_calloc(1, sizeof(ListRule), ruleinfo->lists); - - os_calloc(2, sizeof(char*), ruleinfo->same_fields); - os_strdup("test_same_fields", ruleinfo->same_fields[0]); - - os_calloc(2, sizeof(char*), ruleinfo->not_same_fields); - os_strdup("test_not_same_fields", ruleinfo->not_same_fields[0]); - - os_calloc(2, sizeof(char*), ruleinfo->mitre_id); - os_strdup("test_mitre_id", ruleinfo->mitre_id[0]); - - w_calloc_expression_t(&ruleinfo->match, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->regex, EXP_TYPE_OSREGEX); - w_calloc_expression_t(&ruleinfo->dstgeoip, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->srcport, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->dstport, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->user, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->url, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->id, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->status, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->hostname, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->program_name, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->data, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->extra_data, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->location, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->system_name, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&ruleinfo->protocol, EXP_TYPE_OSMATCH); - - os_calloc(1, sizeof(OSRegex), ruleinfo->if_matched_regex); - os_calloc(1, sizeof(OSMatch), ruleinfo->if_matched_group); - - os_remove_ruleinfo(ruleinfo); -} - -/* os_remove_rules_list */ -void test_os_remove_rules_list_OK(void **state) -{ - RuleNode *node; - os_calloc(1,sizeof(RuleNode), node); - - os_calloc(1, sizeof(RuleInfo), node->ruleinfo); - - os_calloc(2, sizeof(char*), node->ruleinfo->ignore_fields); - os_strdup("test_ignore_fields", node->ruleinfo->ignore_fields[0]); - - os_calloc(2, sizeof(char*), node->ruleinfo->ckignore_fields); - os_strdup("test_ckignore_felds", node->ruleinfo->ckignore_fields[0]); - - expect_any(__wrap_OS_IsValidIP, ip_address); - expect_any(__wrap_OS_IsValidIP, final_ip); - will_return(__wrap_OS_IsValidIP, -1); - - w_expression_add_osip(&node->ruleinfo->srcip, "0.0.0.0"); - - expect_any(__wrap_OS_IsValidIP, ip_address); - expect_any(__wrap_OS_IsValidIP, final_ip); - will_return(__wrap_OS_IsValidIP, -1); - - w_expression_add_osip(&node->ruleinfo->dstip, "0.0.0.0"); - - os_calloc(2, sizeof(FieldInfo*), node->ruleinfo->fields); - os_calloc(1, sizeof(FieldInfo), node->ruleinfo->fields[0]); - os_strdup("test_name", node->ruleinfo->fields[0]->name); - os_calloc(1, sizeof(OSRegex), node->ruleinfo->fields[0]->regex); - - os_calloc(1, sizeof(RuleInfoDetail), node->ruleinfo->info_details); - - os_calloc(2, sizeof(active_response*), node->ruleinfo->ar); - node->ruleinfo->ar[0] = *state; - os_calloc(1, sizeof(ListRule), node->ruleinfo->lists); - - os_calloc(2, sizeof(char*), node->ruleinfo->same_fields); - os_strdup("test_same_fields", node->ruleinfo->same_fields[0]); - - os_calloc(2, sizeof(char*), node->ruleinfo->not_same_fields); - os_strdup("test_same_fields", node->ruleinfo->not_same_fields[0]); - - os_calloc(2, sizeof(char*), node->ruleinfo->mitre_id); - os_strdup("test_mitre_id", node->ruleinfo->mitre_id[0]); - - w_calloc_expression_t(&node->ruleinfo->match, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->regex, EXP_TYPE_OSREGEX); - w_calloc_expression_t(&node->ruleinfo->dstgeoip, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->srcport, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->dstport, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->user, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->url, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->id, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->status, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->hostname, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->program_name, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->data, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->extra_data, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->location, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->system_name, EXP_TYPE_OSMATCH); - w_calloc_expression_t(&node->ruleinfo->protocol, EXP_TYPE_OSMATCH); - - os_calloc(1, sizeof(OSRegex), node->ruleinfo->if_matched_regex); - os_calloc(1, sizeof(OSMatch), node->ruleinfo->if_matched_group); - - os_remove_rules_list(node); - -} - - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests os_count_rules - cmocka_unit_test(test_os_count_rules_no_child), - cmocka_unit_test(test_os_count_rules_child), - // Tests os_remove_rulenode - cmocka_unit_test(test_os_remove_rulenode_no_child), - cmocka_unit_test(test_os_remove_rulenode_child), - // Tests os_remove_ruleinfo - cmocka_unit_test(test_os_remove_ruleinfo_NULL), - cmocka_unit_test_setup_teardown(test_os_remove_ruleinfo_OK, setup_AR, teardown_AR), - // Tests os_remove_rules_list - cmocka_unit_test_setup_teardown(test_os_remove_rules_list_OK, setup_AR, teardown_AR) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_rules.c b/src/unit_tests/analysisd/test_rules.c deleted file mode 100644 index e32bce262eb..00000000000 --- a/src/unit_tests/analysisd/test_rules.c +++ /dev/null @@ -1,904 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../analysisd/rules.h" -#include "../../analysisd/config.h" -#include "../../analysisd/eventinfo.h" -#include "../../analysisd/analysisd.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_xml/os_xml_wrappers.h" - -char *loadmemory(char *at, const char *str, OSList* log_msg); -int get_info_attributes(char **attributes, char **values, OSList* log_msg); -bool w_check_attr_negate(xml_node *node, int rule_id, OSList* log_msg); -bool w_check_attr_field_name(xml_node * node, FieldInfo ** field, int rule_id, OSList* log_msg); -w_exp_type_t w_check_attr_type(xml_node *node, w_exp_type_t default_type, int rule_id, OSList* log_msg); -void w_free_rules_tmp_params(rules_tmp_params_t * rule_tmp_params); - -/* setup/teardown */ - -/* wraps */ -void __wrap__os_analysisd_add_logmsg(OSList * list, int level, int line, const char * func, - const char * file, char * msg, ...) { - char formatted_msg[OS_MAXSTR]; - va_list args; - - va_start(args, msg); - vsnprintf(formatted_msg, OS_MAXSTR, msg, args); - va_end(args); - - check_expected(level); - check_expected_ptr(list); - check_expected(formatted_msg); -} - -/* tests */ -// loadmemory -void test_loadmemory_null_append_ok(void ** state) -{ - char * at = NULL; - char * str; - - const size_t len = 1000; - char * expect_retval; - char * retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - os_calloc(len, sizeof(char), expect_retval); - memset(expect_retval, (int) '-', len - 1); - expect_retval[len-1] = '\0'; - - retval = loadmemory(at,str, NULL); - - assert_string_equal(retval, expect_retval); - - os_free(str); - os_free(retval); - os_free(expect_retval); - -} - -void test_loadmemory_null_append_oversize(void ** state) -{ - char * at = NULL; - char * str; - OSList list_msg = {0}; - - const size_t len = 2049; - char * retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - char expect_msg[OS_SIZE_4096]; - - snprintf(expect_msg, OS_SIZE_4096, "(1104): Maximum string size reached for: %s.", str); - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, expect_msg); - - retval = loadmemory(at,str, &list_msg); - - assert_null(retval); - - os_free(str); - -} - -void test_loadmemory_append_oversize(void ** state) -{ - char * at = NULL; - char * str = NULL; - OSList list_msg = {0}; - - const size_t len = 2050; - char * retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - os_calloc(len, sizeof(char), at); - memset(at, (int) '+', len - 1); - str[len-1] = '\0'; - - char expect_msg[OS_SIZE_20480]; - - snprintf(expect_msg, OS_SIZE_20480, "(1104): Maximum string size reached for: %s.", str); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &list_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, expect_msg); - - retval = loadmemory(at,str, &list_msg); - - assert_null(retval); - - os_free(str); - os_free(at); - -} - -void test_loadmemory_append_ok(void ** state) -{ - char * at = NULL; - char * str = NULL; - OSList list_msg = {0}; - - const size_t len = 512; - char * retval; - char * expect_retval; - - os_calloc(len, sizeof(char), str); - memset(str, (int) '-', len - 1); - str[len-1] = '\0'; - - os_calloc(len, sizeof(char), at); - memset(at, (int) '+', len - 1); - at[len-1] = '\0'; - - os_calloc(len * 2, sizeof(char), expect_retval); - strncat(expect_retval, at, len * 2); - strncat(expect_retval, str, len * 2); - - retval = loadmemory(at,str, &list_msg); - - assert_non_null(retval); - assert_string_equal(retval, expect_retval); - - os_free(str); - os_free(retval); - os_free(expect_retval); - -} - -// get_info_attributes -void test_get_info_attributes_null(void ** state) -{ - OSList log_msg = {0}; - char ** values = NULL; - char ** attributes = NULL; - - int retval; - const int expect_retval = 0; - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); -} - -void test_get_info_attributes_empty(void ** state) -{ - OSList log_msg = {0}; - char ** values = NULL; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = NULL; - - int retval; - const int expect_retval = 0; - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); -} - -void test_get_info_attributes_without_value(void ** state) -{ - OSList log_msg = {0}; - char * attribute_k = "type"; - - char ** values; - os_calloc(1,sizeof(char *), values); - values[0] = NULL; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = attribute_k; - - int retval; - const int expect_retval = -1; - - char excpect_msg[OS_SIZE_2048]; - snprintf(excpect_msg, OS_SIZE_2048, "rules_op: Element info attribute \"%s\" does not have a value", attributes[0]); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &log_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, excpect_msg); - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); - os_free(values); -} - -void test_get_info_attributes_text(void ** state) -{ - OSList log_msg = {0}; - char * attribute_k = "type"; - char * values_k = "text"; - - char ** values; - os_calloc(1,sizeof(char *), values); - values[0] = values_k; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = attribute_k; - - int retval; - const int expect_retval = 0; - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); - os_free(values); -} - -void test_get_info_attributes_link(void ** state) -{ - OSList log_msg = {0}; - char * attribute_k = "type"; - char * values_k = "link"; - - char ** values; - os_calloc(1,sizeof(char *), values); - values[0] = values_k; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = attribute_k; - - int retval; - const int expect_retval = 1; - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); - os_free(values); -} - -void test_get_info_attributes_cve(void ** state) -{ - OSList log_msg = {0}; - char * attribute_k = "type"; - char * values_k = "cve"; - - char ** values; - os_calloc(1,sizeof(char *), values); - values[0] = values_k; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = attribute_k; - - int retval; - const int expect_retval = 2; - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); - os_free(values); -} - -void test_get_info_attributes_osvdb(void ** state) -{ - OSList log_msg = {0}; - char * attribute_k = "type"; - char * values_k = "osvdb"; - - char ** values; - os_calloc(1,sizeof(char *), values); - values[0] = values_k; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = attribute_k; - - int retval; - const int expect_retval = 3; - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); - os_free(values); -} - -void test_get_info_attributes_invalid_value(void ** state) -{ - OSList log_msg = {0}; - char * attribute_k = "bad_type"; - char * values_k = "test_value"; - - char ** values; - os_calloc(1,sizeof(char *), values); - values[0] = values_k; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = attribute_k; - - int retval; - const int expect_retval = -1; - - char excpect_msg[OS_SIZE_2048]; - snprintf(excpect_msg, OS_SIZE_2048, "rules_op: Element info has invalid attribute \"%s\"", attributes[0]); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &log_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, excpect_msg); - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); - os_free(values); -} - -void test_get_info_attributes_invalid_type(void ** state) -{ - OSList log_msg = {0}; - char * attribute_k = "type"; - char * values_k = "bad_value"; - - char ** values; - os_calloc(1,sizeof(char *), values); - values[0] = values_k; - - char ** attributes; - os_calloc(1,sizeof(char *), attributes); - attributes[0] = attribute_k; - - int retval; - const int expect_retval = -1; - - char excpect_msg[OS_SIZE_2048]; - snprintf(excpect_msg, OS_SIZE_2048, "rules_op: Element info attribute \"%s\"" - " has invalid value \"%s\"", attributes[0], values[0]); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &log_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, excpect_msg); - - retval = get_info_attributes(attributes, values, &log_msg); - - assert_int_equal(retval, expect_retval); - - os_free(attributes); - os_free(values); -} - -// w_check_attr_negate - -void w_check_attr_negate_non_attr(void **state) -{ - OSList log_msg = {0}; - xml_node node = {0, NULL, NULL, NULL, NULL}; - int rule_id = 1234; - bool ret_val; - - ret_val = w_check_attr_negate(&node, rule_id, &log_msg); - - assert_false(ret_val); -} - -void w_check_attr_negate_attr_to_yes(void **state) -{ - OSList log_msg = {0}; - xml_node node; - int rule_id = 1234; - bool ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("negate", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("yes", node.values[0]); - - ret_val = w_check_attr_negate(&node, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_true(ret_val); -} - -void w_check_attr_negate_attr_to_no(void **state) -{ - OSList log_msg = {0}; - xml_node node; - int rule_id = 1234; - bool ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("negate", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("no", node.values[0]); - - ret_val = w_check_attr_negate(&node, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_false(ret_val); -} - -void w_check_attr_negate_attr_unknow_val(void **state) -{ - xml_node node; - int rule_id = 1234; - bool ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("negate", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("hello", node.values[0]); - - OSList log_msg = {0}; - char expected_msg[OS_SIZE_2048]; - snprintf(expected_msg, OS_SIZE_2048, "(7600): Invalid value 'hello' for attribute 'negate' in rule 1234."); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, &log_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, expected_msg); - - ret_val = w_check_attr_negate(&node, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_false(ret_val); -} - -void w_check_attr_negate_attr_non_negate_attr(void **state) -{ - OSList log_msg = {0}; - xml_node node; - int rule_id = 1234; - bool ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("hello", node.attributes[0]); - node.attributes[1] = NULL; - - ret_val = w_check_attr_negate(&node, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.attributes); - - assert_false(ret_val); -} - -// w_check_attr_field_name - -void w_check_attr_field_name_non_attr(void **state) -{ - OSList log_msg = {0}; - xml_node node = {0, NULL, NULL, NULL, NULL}; - int rule_id = 1234; - FieldInfo *field = NULL; - bool ret_val; - - ret_val = w_check_attr_field_name(&node, &field, rule_id, &log_msg); - - assert_false(ret_val); -} - -void w_check_attr_field_name_static_field(void **state) -{ - xml_node node; - int rule_id = 1234; - FieldInfo *field = NULL; - bool ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("name", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("action", node.values[0]); - - OSList log_msg = {0}; - char expected_msg[OS_SIZE_2048]; - snprintf(expected_msg, OS_SIZE_2048, "Failure to read rule 1234. Field 'action' is static."); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &log_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, expected_msg); - - ret_val = w_check_attr_field_name(&node, &field, rule_id, &log_msg); - - assert_false(ret_val); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); -} - -void w_check_attr_field_name_non_name_attr(void **state) -{ - xml_node node; - int rule_id = 1234; - FieldInfo *field = NULL; - bool ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("hello", node.attributes[0]); - node.attributes[1] = NULL; - - OSList log_msg = {0}; - char expected_msg[OS_SIZE_2048]; - snprintf(expected_msg, OS_SIZE_2048, "Failure to read rule 1234. No such attribute 'name' for field."); - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_ERROR); - expect_value(__wrap__os_analysisd_add_logmsg, list, &log_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, expected_msg); - - ret_val = w_check_attr_field_name(&node, &field, rule_id, &log_msg); - - assert_false(ret_val); - - os_free(node.attributes[0]); - os_free(node.attributes); -} - -void w_check_attr_field_name_dynamic_field(void **state) -{ - OSList log_msg = {0}; - xml_node node; - int rule_id = 1234; - FieldInfo *field = NULL; - bool ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("name", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("dynamicField", node.values[0]); - - ret_val = w_check_attr_field_name(&node, &field, rule_id, &log_msg); - - assert_true(ret_val); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - os_free(field->name); - os_free(field); -} - -// w_check_attr_type - -void w_check_attr_type_non_attr(void **state) -{ - xml_node node = {0, NULL, NULL, NULL, NULL}; - int rule_id = 1234; - w_exp_type_t ret_val; - OSList log_msg = {0}; - - ret_val = w_check_attr_type(&node, EXP_TYPE_OSMATCH, rule_id, &log_msg); - - assert_int_equal(ret_val, EXP_TYPE_OSMATCH); -} - -void w_check_attr_type_non_type_attr(void **state) -{ - xml_node node; - int rule_id = 1234; - w_exp_type_t ret_val; - OSList log_msg = {0}; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("non_type", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("osmatch", node.values[0]); - - ret_val = w_check_attr_type(&node, EXP_TYPE_OSREGEX, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_int_equal(ret_val, EXP_TYPE_OSREGEX); -} - -void w_check_attr_type_attr_to_osmatch(void **state) -{ - xml_node node; - int rule_id = 1234; - w_exp_type_t ret_val; - OSList log_msg = {0}; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("type", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("osmatch", node.values[0]); - - ret_val = w_check_attr_type(&node, EXP_TYPE_OSREGEX, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_int_equal(ret_val, EXP_TYPE_OSMATCH); -} - -void w_check_attr_type_attr_to_osregex(void **state) -{ - xml_node node; - int rule_id = 1234; - w_exp_type_t ret_val; - OSList log_msg = {0}; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("type", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("osregex", node.values[0]); - - ret_val = w_check_attr_type(&node, EXP_TYPE_OSMATCH, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_int_equal(ret_val, EXP_TYPE_OSREGEX); -} - -void w_check_attr_type_attr_to_pcre2(void **state) -{ - xml_node node; - int rule_id = 1234; - w_exp_type_t ret_val; - OSList log_msg = {0}; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("type", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("pcre2", node.values[0]); - - ret_val = w_check_attr_type(&node, EXP_TYPE_OSMATCH, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_int_equal(ret_val, EXP_TYPE_PCRE2); -} - -void w_check_attr_type_attr_unknow_val(void **state) -{ - xml_node node; - int rule_id = 1234; - w_exp_type_t ret_val; - - node.key = 0; - node.element = NULL; - os_calloc(2, sizeof(char*), node.attributes); - os_strdup("type", node.attributes[0]); - node.attributes[1] = NULL; - os_calloc(1, sizeof(char*), node.values); - os_strdup("hello", node.values[0]); - - OSList log_msg = {0}; - char excpect_msg[70] = "(7600): Invalid value 'hello' for attribute 'type' in rule 1234."; - - expect_value(__wrap__os_analysisd_add_logmsg, level, LOGLEVEL_WARNING); - expect_value(__wrap__os_analysisd_add_logmsg, list, &log_msg); - expect_string(__wrap__os_analysisd_add_logmsg, formatted_msg, excpect_msg); - - ret_val = w_check_attr_type(&node, EXP_TYPE_OSMATCH, rule_id, &log_msg); - - os_free(node.attributes[0]); - os_free(node.values[0]); - os_free(node.attributes); - os_free(node.values); - - assert_int_equal(ret_val, EXP_TYPE_OSMATCH); -} - -// Test w_free_rules_tmp_params - -void w_free_rules_tmp_params_all(void ** state){ - - rules_tmp_params_t rule_tmp_params = {0}; - - rule_tmp_params.regex = strdup("test 123"); - rule_tmp_params.match = strdup("test 123"); - rule_tmp_params.url = strdup("test 123"); - rule_tmp_params.if_matched_regex = strdup("test 123"); - rule_tmp_params.if_matched_group = strdup("test 123"); - rule_tmp_params.user = strdup("test 123"); - rule_tmp_params.id = strdup("test 123"); - rule_tmp_params.srcport = strdup("test 123"); - rule_tmp_params.dstport = strdup("test 123"); - rule_tmp_params.srcgeoip = strdup("test 123"); - rule_tmp_params.dstgeoip = strdup("test 123"); - rule_tmp_params.protocol = strdup("test 123"); - rule_tmp_params.system_name = strdup("test 123"); - rule_tmp_params.status = strdup("test 123"); - rule_tmp_params.hostname = strdup("test 123"); - rule_tmp_params.data = strdup("test 123"); - rule_tmp_params.extra_data = strdup("test 123"); - rule_tmp_params.program_name = strdup("test 123"); - rule_tmp_params.location = strdup("test 123"); - rule_tmp_params.action = strdup("test 123"); - - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - - rule_tmp_params.rule_arr_opt = node; - - expect_function_call(__wrap_OS_ClearNode); - - w_free_rules_tmp_params(&rule_tmp_params); -} - -void w_free_rules_tmp_params_only_rule_arr(void ** state){ - - rules_tmp_params_t rule_tmp_params = {0}; - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - /* */ - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("ossec_config", node[0]->element); - - rule_tmp_params.rule_arr_opt = node; - - expect_function_call(__wrap_OS_ClearNode); - - w_free_rules_tmp_params(&rule_tmp_params); -} - -void w_free_rules_tmp_params_only_params(void ** state){ - - rules_tmp_params_t rule_tmp_params = {0}; - - rule_tmp_params.regex = strdup("test 123"); - rule_tmp_params.match = strdup("test 123"); - rule_tmp_params.url = strdup("test 123"); - rule_tmp_params.if_matched_regex = strdup("test 123"); - rule_tmp_params.if_matched_group = strdup("test 123"); - rule_tmp_params.user = strdup("test 123"); - rule_tmp_params.id = strdup("test 123"); - rule_tmp_params.srcport = strdup("test 123"); - rule_tmp_params.dstport = strdup("test 123"); - rule_tmp_params.srcgeoip = strdup("test 123"); - rule_tmp_params.dstgeoip = strdup("test 123"); - rule_tmp_params.protocol = strdup("test 123"); - rule_tmp_params.system_name = strdup("test 123"); - rule_tmp_params.status = strdup("test 123"); - rule_tmp_params.hostname = strdup("test 123"); - rule_tmp_params.data = strdup("test 123"); - rule_tmp_params.extra_data = strdup("test 123"); - rule_tmp_params.program_name = strdup("test 123"); - rule_tmp_params.location = strdup("test 123"); - rule_tmp_params.action = strdup("test 123"); - rule_tmp_params.rule_arr_opt = NULL; - - - w_free_rules_tmp_params(&rule_tmp_params); -} - - -void w_free_rules_tmp_params_null(void ** state){ - - w_free_rules_tmp_params(NULL); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests _loadmemory - cmocka_unit_test(test_loadmemory_null_append_ok), - cmocka_unit_test(test_loadmemory_null_append_oversize), - cmocka_unit_test(test_loadmemory_append_oversize), - cmocka_unit_test(test_loadmemory_append_ok), - // Tests get_info_attributes - cmocka_unit_test(test_get_info_attributes_null), - cmocka_unit_test(test_get_info_attributes_empty), - cmocka_unit_test(test_get_info_attributes_without_value), - cmocka_unit_test(test_get_info_attributes_text), - cmocka_unit_test(test_get_info_attributes_link), - cmocka_unit_test(test_get_info_attributes_cve), - cmocka_unit_test(test_get_info_attributes_osvdb), - cmocka_unit_test(test_get_info_attributes_invalid_value), - cmocka_unit_test(test_get_info_attributes_invalid_type), - // Test w_check_attr_negate - cmocka_unit_test(w_check_attr_negate_non_attr), - cmocka_unit_test(w_check_attr_negate_attr_to_yes), - cmocka_unit_test(w_check_attr_negate_attr_to_no), - cmocka_unit_test(w_check_attr_negate_attr_unknow_val), - cmocka_unit_test(w_check_attr_negate_attr_non_negate_attr), - // Test w_check_attr_field_name - cmocka_unit_test(w_check_attr_field_name_non_attr), - cmocka_unit_test(w_check_attr_field_name_static_field), - cmocka_unit_test(w_check_attr_field_name_non_name_attr), - cmocka_unit_test(w_check_attr_field_name_dynamic_field), - // Test w_check_attr_type - cmocka_unit_test(w_check_attr_type_non_attr), - cmocka_unit_test(w_check_attr_type_non_type_attr), - cmocka_unit_test(w_check_attr_type_attr_to_osmatch), - cmocka_unit_test(w_check_attr_type_attr_to_osregex), - cmocka_unit_test(w_check_attr_type_attr_to_pcre2), - cmocka_unit_test(w_check_attr_type_attr_unknow_val), - // Test w_free_rules_tmp_params - cmocka_unit_test(w_free_rules_tmp_params_all), - cmocka_unit_test(w_free_rules_tmp_params_only_rule_arr), - cmocka_unit_test(w_free_rules_tmp_params_only_params), - cmocka_unit_test(w_free_rules_tmp_params_null), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/analysisd/test_same_different_loop.c b/src/unit_tests/analysisd/test_same_different_loop.c deleted file mode 100644 index 99d3a507875..00000000000 --- a/src/unit_tests/analysisd/test_same_different_loop.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../analysisd/rules.h" -#include "../analysisd/eventinfo.h" - -/* setup */ - -static int testSetup(void **state) { - RuleInfo * rule = calloc(1, sizeof(RuleInfo)); - Eventinfo * lf = calloc(1, sizeof(Eventinfo)); - Eventinfo * same_lf = calloc(1, sizeof(Eventinfo)); - Eventinfo * different_lf = calloc(1, sizeof(Eventinfo)); - - if(!rule || !lf || !same_lf || !different_lf) { - return -1; - } - - lf->srcip = "100.200.40.20"; - lf->id = "001"; - lf->dstip = "100.200.50.30"; - lf->srcport = "30"; - lf->dstport = "40"; - lf->srcuser = "User"; - lf->dstuser = "User"; - lf->protocol = "TCP"; - lf->action = "install"; - lf->url = "url1.com"; - lf->data = "data1"; - lf->extra_data = "extra data1"; - lf->status = "started"; - lf->systemname = "centos"; - lf->srcgeoip = "ES / Madrid"; - lf->dstgeoip = "ES / Madrid"; - lf->location = "/var/ossec/logs/field1"; - - same_lf->srcip = "100.200.40.20"; - same_lf->id = "001"; - same_lf->dstip = "100.200.50.30"; - same_lf->srcport = "30"; - same_lf->dstport = "40"; - same_lf->srcuser = "User"; - same_lf->dstuser = "User"; - same_lf->protocol = "TCP"; - same_lf->action = "install"; - same_lf->url = "url1.com"; - same_lf->data = "data1"; - same_lf->extra_data = "extra data1"; - same_lf->status = "started"; - same_lf->systemname = "centos"; - same_lf->srcgeoip = "ES / Madrid"; - same_lf->dstgeoip = "ES / Madrid"; - same_lf->location = "/var/ossec/logs/field1"; - - different_lf->srcip = "100.37.58.104"; - different_lf->id = "002"; - different_lf->dstip = "100.200.50.3"; - different_lf->srcport = "3"; - different_lf->dstport = "4"; - different_lf->srcuser = "Admin"; - different_lf->dstuser = "Admin"; - different_lf->protocol = "UDP"; - different_lf->action = "remove"; - different_lf->url = "url2.com"; - different_lf->data = "data2"; - different_lf->extra_data = "extra data2"; - different_lf->status = "finished"; - different_lf->systemname = "Ubuntu"; - different_lf->srcgeoip = "ES / Granade"; - different_lf->dstgeoip = "ES / Granade"; - different_lf->location = "/var/ossec/logs/field2"; - - state[0] = rule; - state[1] = lf; - state[2] = same_lf; - state[3] = different_lf; - - return 0; -} - -/* tests for same_loop and different_loop from eventinfo.c */ - -void test_same(void **state) -{ - (void) state; - bool ret; - RuleInfo *rule = state[0]; - Eventinfo *lf = state[1]; - Eventinfo *same_lf = state[2]; - Eventinfo *different_lf = state[3]; - u_int32_t a = 65536; - - while (a != 2) { - rule->same_field = a; - - /* Same static field values should return true */ - ret = same_loop(rule, lf, same_lf); - assert_true(ret); - - /* Different static field values should return false */ - ret = same_loop(rule, lf, different_lf); - assert_false(ret); - - a >>= 1; - } - - os_free(rule); - os_free(lf); - os_free(same_lf); - os_free(different_lf); -} - -void test_different(void **state) -{ - (void) state; - bool ret; - RuleInfo *rule = state[0]; - Eventinfo *lf = state[1]; - Eventinfo *same_lf = state[2]; - Eventinfo *different_lf = state[3]; - u_int32_t a = 65536; - - while (a != 0) { - rule->different_field = a; - - /* Same static field values should return false */ - ret = different_loop(rule, lf, same_lf); - assert_false(ret); - - /* Different static field values should return true */ - ret = same_loop(rule, lf, different_lf); - assert_true(ret); - - a >>= 1; - } - - os_free(rule); - os_free(lf); - os_free(same_lf); - os_free(different_lf); -} - -int main(void) { - const struct CMUnitTest tests[] = { - /* Tests for same loop function */ - cmocka_unit_test_setup(test_same, testSetup), - cmocka_unit_test_setup(test_different, testSetup) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/client-agent/CMakeLists.txt b/src/unit_tests/client-agent/CMakeLists.txt deleted file mode 100644 index 5c4db1541f7..00000000000 --- a/src/unit_tests/client-agent/CMakeLists.txt +++ /dev/null @@ -1,119 +0,0 @@ -# Generate client-agent library -file(GLOB client-agent_files - ${SRC_FOLDER}/client-agent/*.o - ${SRC_FOLDER}/monitord/*.o) - -list(REMOVE_ITEM client-agent_files ${SRC_FOLDER}/client-agent/main.o) - -add_library(CLIENT-AGENT STATIC ${client-agent_files}) - -set_source_files_properties( - ${client-agent_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - CLIENT-AGENT - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(CLIENT-AGENT ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate agentd tests -list(APPEND client-agent_names "test_start_agent") -set(START_AGENT_BASE_FLAGS "-Wl,--wrap,w_rotate_log -Wl,--wrap,getDefine_Int -Wl,--wrap,OS_ConnectUDP \ - -Wl,--wrap,OS_ConnectTCP -Wl,--wrap,OS_SetRecvTimeout -Wl,--wrap,OS_GetHost \ - -Wl,--wrap,send_msg -Wl,--wrap,recv -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,fseek \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=fim_db_teardown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize \ - -Wl,--wrap,fprintf -Wl,--wrap,fflush -Wl,--wrap,ReadSecMSG -Wl,--wrap,wnet_select \ - -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,OS_SendUDPbySize -Wl,--wrap,getpid ${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,w_calloc_expression_t -Wl,--wrap,w_expression_compile -Wl,--wrap,w_expression_match \ - -Wl,--wrap,w_free_expression_t") -if(${TARGET} STREQUAL "winagent") - list(APPEND client-agent_flags "${START_AGENT_BASE_FLAGS} -Wl,--wrap,os_random -Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck") -else() - list(APPEND client-agent_flags "${START_AGENT_BASE_FLAGS} -Wl,--wrap=close") -endif() - -list(APPEND client-agent_names "test_notify") -if(${TARGET} STREQUAL "winagent") -list(APPEND client-agent_flags "-Wl,--wrap,control_check_connection,--wrap,OS_SendUnix,--wrap,OS_RecvUnix,--wrap,close \ - -Wl,--wrap,strftime -Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=fim_db_teardown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize \ - -Wl,--wrap=getsockname -Wl,--wrap,get_ipv4_string -Wl,--wrap,get_ipv6_string \ - -Wl,--wrap,sleep,--wrap,w_rotate_log,--wrap,getpid,--wrap,time ${DEBUG_OP_WRAPPERS}") -else() -list(APPEND client-agent_flags "-Wl,--wrap,control_check_connection,--wrap,OS_SendUnix,--wrap,OS_RecvUnix,--wrap,close \ - -Wl,--wrap=getsockname -Wl,--wrap,get_ipv4_string -Wl,--wrap,get_ipv6_string \ - -Wl,--wrap,sleep,--wrap,w_rotate_log,--wrap,getpid,--wrap,time ${DEBUG_OP_WRAPPERS}") -endif() - -list(APPEND client-agent_names "test_agentd_state") -if(${TARGET} STREQUAL "winagent") - # cJSON_func@x instead of cJSON_func since linker will be looking for cdecl forma - # More info at: (https://devblogs.microsoft.com/oldnewthing/20040108-00/?p=41163) - list(APPEND client-agent_flags "-Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap,cJSON_CreateObject@0 -Wl,--wrap,cJSON_AddNumberToObject@16 \ - -Wl,--wrap,cJSON_AddItemToObject@12 -Wl,--wrap,cJSON_AddStringToObject@12 \ - -Wl,--wrap,cJSON_Delete@4 -Wl,--wrap,strftime -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap=is_fim_shutdown -Wl,--wrap=fim_db_teardown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize \ - -Wl,--wrap,cJSON_PrintUnformatted@4 -Wl,--wrap,w_agentd_get_buffer_lenght \ - -Wl,--wrap,cJSON_AddBoolToObject@12 -Wl,--enable-stdcall-fixup ${DEBUG_OP_WRAPPERS}") -else() - list(APPEND client-agent_flags "-Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_AddNumberToObject -Wl,--wrap,strftime \ - -Wl,--wrap,cJSON_AddItemToObject -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_Delete \ - -Wl,--wrap,cJSON_PrintUnformatted -Wl,--wrap,w_agentd_get_buffer_lenght \ - -Wl,--wrap,cJSON_AddBoolToObject ${DEBUG_OP_WRAPPERS}") -endif() - -list(APPEND client-agent_names "test_buffer") -if(${TARGET} STREQUAL "winagent") -list(APPEND client-agent_flags "-Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap=is_fim_shutdown -Wl,--wrap=fim_db_teardown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize") -else() -list(APPEND client-agent_flags "-Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock") -endif() - -list(LENGTH client-agent_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET client-agent_names ${counter} client-agent_test_name) - list(GET client-agent_flags ${counter} client-agent_test_flags) - - add_executable(${client-agent_test_name} ${client-agent_test_name}.c) - - target_link_libraries( - ${client-agent_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - CLIENT-AGENT - ${TEST_DEPS} - ) - - if(${TARGET} STREQUAL "winagent") - target_link_libraries(${client-agent_test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - - if(NOT client-agent_test_flags STREQUAL " ") - target_link_libraries( - ${client-agent_test_name} - ${client-agent_test_flags} - ) - endif() - add_test(NAME ${client-agent_test_name} COMMAND ${client-agent_test_name}) -endforeach() diff --git a/src/unit_tests/client-agent/test_agentd_state.c b/src/unit_tests/client-agent/test_agentd_state.c deleted file mode 100644 index 9b917049315..00000000000 --- a/src/unit_tests/client-agent/test_agentd_state.c +++ /dev/null @@ -1,704 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/client-agent/buffer_wrappers.h" -#include "../wrappers/libc/time_wrappers.h" - -#include "../../client-agent/state.h" - -const char * get_str_status(agent_status_t status); -void w_agentd_state_update(w_agentd_state_update_t type, void * data); -char * w_agentd_state_get(); - -extern agent_state_t agent_state; - -/* setup/teardown */ - -static int setup_group(void **state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - -/* tests */ - -/* get_str_status */ - -void test_get_str_status_pending(void ** state) -{ - agent_status_t status = GA_STATUS_PENDING; - - const char * retval = get_str_status(status); - - assert_string_equal(retval,"pending"); - -} - -void test_get_str_status_connected(void ** state) -{ - agent_status_t status = GA_STATUS_ACTIVE; - - const char * retval = get_str_status(status); - - assert_string_equal(retval,"connected"); - -} - -void test_get_str_status_disconnected(void ** state) -{ - agent_status_t status = GA_STATUS_NACTIVE; - - const char * retval = get_str_status(status); - - assert_string_equal(retval,"disconnected"); - -} - -void test_get_str_status_unknown(void ** state) -{ - agent_status_t status = 10; - - expect_string(__wrap__merror, formatted_msg, "At get_str_status(): Unknown status (10)"); - - const char * retval = get_str_status(status); - - assert_string_equal(retval,"unknown"); - -} - -/* w_agentd_state_update */ - -void test_w_agentd_state_update_status(void ** state) -{ - w_agentd_state_update_t type = UPDATE_STATUS; - agent_status_t data = GA_STATUS_ACTIVE; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_agentd_state_update(type, &data); - -} - -void test_w_agentd_state_update_keepalive_NULL(void ** state) -{ - w_agentd_state_update_t type = UPDATE_KEEPALIVE; - time_t * data = NULL; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_agentd_state_update(type, data); - -} - -void test_w_agentd_state_update_keepalive(void ** state) -{ - w_agentd_state_update_t type = UPDATE_KEEPALIVE; - time_t data = 10; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_agentd_state_update(type, &data); - -} - -void test_w_agentd_state_update_ack_NULL(void ** state) -{ - w_agentd_state_update_t type = UPDATE_ACK; - time_t * data = NULL; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_agentd_state_update(type, &data); - -} - -void test_w_agentd_state_update_ack(void ** state) -{ - w_agentd_state_update_t type = UPDATE_ACK; - time_t data = 10; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_agentd_state_update(type, &data); - -} - -void test_w_agentd_state_update_msg_count(void ** state) -{ - w_agentd_state_update_t type = INCREMENT_MSG_COUNT; - time_t data = 10; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_agentd_state_update(type, &data); - -} - -void test_w_agentd_state_update_msg_send(void ** state) -{ - w_agentd_state_update_t type = INCREMENT_MSG_SEND; - time_t data = 10; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_agentd_state_update(type, &data); - -} - -/* w_agentd_state_get */ - -void test_w_agentd_state_get_last_keepalive(void ** state) -{ - agent_state.status = GA_STATUS_ACTIVE; - agent_state.last_keepalive = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_function_call(__wrap_pthread_mutex_lock); - - will_return(__wrap_strftime,"2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime,"2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, 0); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "connected"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -void test_w_agentd_state_get_last_ack(void ** state) -{ - agent_state.status = GA_STATUS_ACTIVE; - agent_state.last_keepalive = 10; - agent_state.last_ack = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_strftime,"2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime,"2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, 0); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "connected"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -void test_w_agentd_state_get_buffer_disabled(void ** state) -{ - agent_state.status = GA_STATUS_ACTIVE; - agent_state.last_keepalive = 10; - agent_state.last_ack = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_strftime,"2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime,"2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, -1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "connected"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -void test_w_agentd_state_get_buffer_empty(void ** state) -{ - agent_state.status = GA_STATUS_ACTIVE; - agent_state.last_keepalive = 10; - agent_state.last_ack = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_strftime, "2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime, "2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, 0); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "connected"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -void test_w_agentd_state_get_pending(void ** state) -{ - agent_state.status = GA_STATUS_PENDING; - agent_state.last_keepalive = 10; - agent_state.last_ack = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_strftime, "2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime, "2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, 1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "pending"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -void test_w_agentd_state_get_conected(void ** state) -{ - agent_state.status = GA_STATUS_ACTIVE; - agent_state.last_keepalive = 10; - agent_state.last_ack = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_strftime, "2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime, "2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, 1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "connected"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -void test_w_agentd_state_get_disconected(void ** state) -{ - agent_state.status = GA_STATUS_NACTIVE; - agent_state.last_keepalive = 10; - agent_state.last_ack = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_strftime, "2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime, "2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, 1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "disconnected"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -void test_w_agentd_state_get_unknown(void ** state) -{ - agent_state.status = 5; - agent_state.last_keepalive = 10; - agent_state.last_ack = 10; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - expect_string(__wrap__merror, formatted_msg, "At get_str_status(): Unknown status (5)"); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_strftime, "2021-01-25 12:18:37"); - will_return(__wrap_strftime, 20); - - will_return(__wrap_strftime, "2021-01-25 13:00:00"); - will_return(__wrap_strftime, 20); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_w_agentd_get_buffer_lenght, 1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_JSON_ERROR); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_STATUS); - expect_string(__wrap_cJSON_AddStringToObject, string, "unknown"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_KEEP_ALIVE); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 12:18:37"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, W_AGENTD_FIELD_LAST_ACK); - expect_string(__wrap_cJSON_AddStringToObject, string, "2021-01-25 13:00:00"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_COUNT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_SENT); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddNumberToObject, name, W_AGENTD_FIELD_MSG_BUFF); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, (cJSON *)1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *)1); - - will_return(__wrap_cJSON_PrintUnformatted, "unknown"); - - expect_function_call(__wrap_cJSON_Delete); - - const char * retval = w_agentd_state_get(); - - assert_string_equal(retval,"unknown"); - -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Tests get_str_status - cmocka_unit_test(test_get_str_status_pending), - cmocka_unit_test(test_get_str_status_connected), - cmocka_unit_test(test_get_str_status_disconnected), - cmocka_unit_test(test_get_str_status_unknown), - - // Tests w_agentd_state_update - cmocka_unit_test(test_w_agentd_state_update_status), - cmocka_unit_test(test_w_agentd_state_update_keepalive_NULL), - cmocka_unit_test(test_w_agentd_state_update_keepalive), - cmocka_unit_test(test_w_agentd_state_update_ack_NULL), - cmocka_unit_test(test_w_agentd_state_update_ack), - cmocka_unit_test(test_w_agentd_state_update_msg_count), - cmocka_unit_test(test_w_agentd_state_update_msg_send), - - // Tests w_agentd_state_get - cmocka_unit_test(test_w_agentd_state_get_last_keepalive), - cmocka_unit_test(test_w_agentd_state_get_last_ack), - cmocka_unit_test(test_w_agentd_state_get_buffer_disabled), - cmocka_unit_test(test_w_agentd_state_get_buffer_empty), - cmocka_unit_test(test_w_agentd_state_get_pending), - cmocka_unit_test(test_w_agentd_state_get_conected), - cmocka_unit_test(test_w_agentd_state_get_disconected), - cmocka_unit_test(test_w_agentd_state_get_unknown) - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/client-agent/test_buffer.c b/src/unit_tests/client-agent/test_buffer.c deleted file mode 100644 index a64d3086bcf..00000000000 --- a/src/unit_tests/client-agent/test_buffer.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../config/client-config.h" - -#include "../wrappers/posix/pthread_wrappers.h" - -int w_agentd_get_buffer_lenght(); - -extern agent *agt; -extern int i; -extern int j; - -/* setup/teardown */ - -static int setup_group(void **state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - -/* tests */ - -/* w_agentd_get_buffer_lenght */ - -void test_w_agentd_get_buffer_lenght_buffer_disabled(void ** state) -{ - os_calloc(1, sizeof(agent), agt); - agt->buffer = 0; - - int retval = w_agentd_get_buffer_lenght(); - - assert_int_equal(retval, -1); - - os_free(agt); - -} - -void test_w_agentd_get_buffer_lenght_buffer_empty(void ** state) -{ - os_calloc(1, sizeof(agent), agt); - agt->buffer = 1; - agt->buflength = 10; - i = 1; - j = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = w_agentd_get_buffer_lenght(); - - assert_int_equal(retval, 0); - - os_free(agt); - -} - -void test_w_agentd_get_buffer_lenght_buffer(void ** state) -{ - os_calloc(1, sizeof(agent), agt); - agt->buffer = 1; - agt->buflength = 5; - i = 1; - j = 5; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = w_agentd_get_buffer_lenght(); - - assert_int_equal(retval, 2); - - os_free(agt); - -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Tests w_agentd_get_buffer_lenght - cmocka_unit_test(test_w_agentd_get_buffer_lenght_buffer_disabled), - cmocka_unit_test(test_w_agentd_get_buffer_lenght_buffer_empty), - cmocka_unit_test(test_w_agentd_get_buffer_lenght_buffer), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} \ No newline at end of file diff --git a/src/unit_tests/client-agent/test_notify.c b/src/unit_tests/client-agent/test_notify.c deleted file mode 100644 index b53eebf45da..00000000000 --- a/src/unit_tests/client-agent/test_notify.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../client-agent/agentd.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -#define DUMMY_VALID_SOCKET_FD 1 - -static int setup(void **state) { - static agent global_config; - agt = &global_config; - // force init value on every call - agt->sock = DUMMY_VALID_SOCKET_FD; - errno = 0; - return 0; -} - -#ifdef TEST_AGENT -// get_agent_ip -static void get_agent_ip_fail_to_connect(void **state) { - char *retval; - - will_return(__wrap_getsockname, -1); - will_return(__wrap_getsockname, AF_UNSPEC); - - errno = ENOTSOCK; - expect_string(__wrap__mdebug2, formatted_msg, "getsockname() failed: Socket operation on non-socket"); - - retval = get_agent_ip(); - - assert_string_equal(retval, ""); - - free(retval); -} - -static void get_agent_ip_invalid_socket(void **state) { - char *retval; - - // force bad socket id - agt->sock = 0; - errno = EBADF; - expect_string(__wrap__mdebug2, formatted_msg, "getsockname() failed: Bad file descriptor"); - - retval = get_agent_ip(); - - assert_string_equal(retval, ""); - - free(retval); -} - -static void get_agent_ip_unknown_address_family(void **state) { - char *retval; - - will_return(__wrap_getsockname, 0); - will_return(__wrap_getsockname, AF_UNIX); - - expect_string(__wrap__mdebug2, formatted_msg, "Unknown address family: 1"); - - retval = get_agent_ip(); - - assert_string_equal(retval, ""); - - free(retval); -} - -static void get_agent_ip_ipv4_updated_successfully(void **state) { - char *retval; - static const char* const IPV4_ADDRESS = "10.1.2.3"; - - expect_any(__wrap_get_ipv4_string, address_size); - will_return(__wrap_get_ipv4_string, OS_SUCCESS); - will_return(__wrap_get_ipv4_string, IPV4_ADDRESS); - - will_return(__wrap_getsockname, 0); - will_return(__wrap_getsockname, AF_INET); - - retval = get_agent_ip(); - - assert_string_equal(retval, IPV4_ADDRESS); - - free(retval); -} - -static void get_agent_ip_ipv6_updated_successfully(void **state) { - char *retval; - static const char* const IPV6_ADDRESS = "2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b"; - - expect_any(__wrap_get_ipv6_string, address_size); - will_return(__wrap_get_ipv6_string, OS_SUCCESS); - will_return(__wrap_get_ipv6_string, IPV6_ADDRESS); - - will_return(__wrap_getsockname, 0); - will_return(__wrap_getsockname, AF_INET6); - - retval = get_agent_ip(); - - assert_string_equal(retval, IPV6_ADDRESS); - - free(retval); -} - -#endif // TEST_AGENT - -int main(void) { - const struct CMUnitTest tests[] = { -#ifdef TEST_AGENT - cmocka_unit_test_setup(get_agent_ip_fail_to_connect, setup), - cmocka_unit_test_setup(get_agent_ip_invalid_socket, setup), - cmocka_unit_test_setup(get_agent_ip_unknown_address_family, setup), - cmocka_unit_test_setup(get_agent_ip_ipv4_updated_successfully, setup), - cmocka_unit_test_setup(get_agent_ip_ipv6_updated_successfully, setup) -#endif // TEST_AGENT - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/client-agent/test_start_agent.c b/src/unit_tests/client-agent/test_start_agent.c deleted file mode 100644 index c181afd8f4f..00000000000 --- a/src/unit_tests/client-agent/test_start_agent.c +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/client-agent/start_agent.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../wrappers/wazuh/monitord/monitord_wrappers.h" - -#ifdef TEST_WINAGENT -#include "../wrappers/wazuh/shared/randombytes_wrappers.h" -#endif - -#include "../client-agent/agentd.h" - -extern void send_msg_on_startup(void); -extern bool agent_handshake_to_server(int server_id, bool is_startup); -extern void send_agent_stopped_message(); -extern int _s_verify_counter; - -#ifndef TEST_WINAGENT -int __wrap_close(int fd) { - check_expected(fd); - return 0; -} -#endif - -int __wrap_send_msg(const char *msg, ssize_t msg_length) { - check_expected(msg); - return 0; -} - -#ifndef TEST_WINAGENT -ssize_t __wrap_recv(int __fd, void *__buf, size_t __n, int __flags) { - char* rcv = (char*)mock_ptr_type(char *); - int len = strlen(rcv); - snprintf(__buf, len+1, "%s", rcv); - return len; -} -#endif - -int __wrap_fseek(FILE *__stream, long __off, int __whence) { - return 0; -} -int __wrap_fprintf(FILE *__restrict__ __stream, const char *__restrict__ __format, ...) { - return 0; -} -int __wrap_fflush(FILE *__stream) { - return 0; -} - -int __wrap_ReadSecMSG(keystore *keys, char *buffer, char *cleartext, int id, unsigned int buffer_size, size_t *final_size, const char *srcip, char **output) { - check_expected(buffer); - *output = (char*)mock_ptr_type(char *); - return (int)mock(); -} - -/* Aux */ -/* ACK encrypted with id=001, Name=agent0 and key=6958b43cb096e036f872d65d6a4dc01b3c828f64a204c04 */ -char SERVER_ENC_ACK[] = {0x23,0x41,0x45,0x53,0x3a,0x4c,0x63,0x7a,0xef,0x9e,0x16,0xcc,0x94,0xf8,0xfc,0x5e,0x81,0xc9,0x80,0x24,0xd3,0x61,0xc6,0xb7,0x9b,0xdf,0xb1,0xfe,0xf5,0xa0,0x31,0xa7,0xba,0x92,0x74,0x3b,0xda,0x0c,0x70,0xed,0x39,0x8f,0xb7,0xda,0xe2,0xe0,0xcb,0x9c,0x86,0x87,0x39,0xaa,0x7b,0xb9,0x5a,0xb3,0xa5,0x81,0xea,0x78,0x15,0xa9,0xfd,0x8b,0x14,0xfb,0x6b,0xcb,0x08,0x04,0x0d,0x77,0xf6,0xd7,0xbc,0x29,0xeb,0x06,0x84,0x07,0x14,0x55,0xaf,0x0c,0x37,0x00}; -char SERVER_NULL_ACK[] = {0x00}; -char SERVER_WRONG_ACK[] = {0x01,0x02,0x03,0x00}; - -void add_server_config(char* address, int protocol) { - os_realloc(agt->server, sizeof(agent_server) * (agt->rip_id + 2), agt->server); - os_strdup(address, agt->server[agt->rip_id].rip); - agt->server[agt->rip_id].port = 1514; - agt->server[agt->rip_id].protocol = 0; - memset(agt->server + agt->rip_id + 1, 0, sizeof(agent_server)); - agt->server[agt->rip_id].protocol = protocol; - agt->rip_id++; - agt->server_count++; -} - -void keys_init(keystore *keys) { - /* Initialize trees */ - - keys->keytree_id = rbtree_init(); - keys->keytree_ip = rbtree_init(); - keys->keytree_sock = rbtree_init(); - - if (!(keys->keytree_id && keys->keytree_ip && keys->keytree_sock)) { - merror_exit(MEM_ERROR, errno, strerror(errno)); - } - - /* Initialize structure */ - os_calloc(1, sizeof(keyentry*), keys->keyentries); - keys->keysize = 0; - keys->id_counter = 0; - keys->flags.key_mode = W_RAW_KEY; - keys->flags.save_removed = 0; - - /* Add additional entry for sender == keysize */ - os_calloc(1, sizeof(keyentry), keys->keyentries[keys->keysize]); - w_mutex_init(&keys->keyentries[keys->keysize]->mutex, NULL); -} - -/* setup/teardown */ -static int setup_test(void **state) { - agt = (agent *)calloc(1, sizeof(agent)); - /* Default conf */ - agt->server = NULL; - agt->rip_id = 0; - agt->execdq = 0; - agt->cfgadq = -1; - agt->profile = NULL; - agt->buffer = 1; - agt->buflength = 5000; - agt->events_persec = 500; - agt->flags.auto_restart = 1; - agt->crypto_method = W_METH_AES; - /* Connected sock */ - agt->sock = -1; - /* Server */ - add_server_config("127.0.0.1", IPPROTO_UDP); - add_server_config("127.0.0.2", IPPROTO_TCP); - add_server_config("VALID_HOSTNAME/127.0.0.3", IPPROTO_UDP); - add_server_config("INVALID_HOSTNAME/", IPPROTO_UDP); - - expect_value(__wrap_w_calloc_expression_t, type, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, 1); - will_return(__wrap_w_expression_match, 0); - - /* Keys */ - keys_init(&keys); - OS_AddKey(&keys, "001", "agent0", "any", "6958b43cb096e036f872d65d6a4dc01b3c828f64a204c04", 0); - os_set_agent_crypto_method(&keys,agt->crypto_method); - - _s_verify_counter = 0; - - return 0; -} - -static int teardown_test(void **state) { - for (unsigned i=0; agt->server[i].rip; i++) { - os_free(agt->server[i].rip); - } - os_free(agt->server); - os_free(agt); - OS_FreeKeys(&keys); - return 0; -} - -/* tests */ -/* connect_server */ -static void test_connect_server(void **state) { - bool connected = false; - expect_any(__wrap__minfo, formatted_msg); - /* Connect to first server (UDP)*/ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, 11); - - expect_any_count(__wrap__minfo, formatted_msg, 2); - - connected = connect_server(0, true); - assert_int_equal(agt->rip_id, 0); - assert_int_equal(agt->sock, 11); - assert_true(connected); - - /* Connect to second server (TCP), previous connection must be closed*/ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[1].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.2")); - - expect_any(__wrap_OS_ConnectTCP, _port); - expect_any(__wrap_OS_ConnectTCP, _ip); - expect_any(__wrap_OS_ConnectTCP, ipv6); - will_return(__wrap_OS_ConnectTCP, 12); -#ifndef TEST_WINAGENT - expect_value(__wrap_close, fd, 11); -#else - expect_value(wrap_closesocket, fd, 11); -#endif - - expect_any_count(__wrap__minfo, formatted_msg, 2); - - connected = connect_server(1, true); - assert_int_equal(agt->rip_id, 1); - assert_int_equal(agt->sock, 12); - assert_true(connected); - - /* Connect to third server (UDP), valid host name*/ - will_return(__wrap_getDefine_Int, 5); - will_return(__wrap_OS_ConnectUDP, 13); -#ifndef TEST_WINAGENT - expect_value(__wrap_close, fd, 12); -#else - expect_value(wrap_closesocket, fd, 12); -#endif - - expect_any_count(__wrap__minfo, formatted_msg, 2); - - connected = connect_server(2, true); - assert_int_equal(agt->rip_id, 2); - assert_int_equal(agt->sock, 13); - assert_true(connected); - - /* Connect to fourth server (UDP), invalid host name*/ - will_return(__wrap_getDefine_Int, 5); -#ifndef TEST_WINAGENT - expect_value(__wrap_close, fd, 13); -#else - expect_value(wrap_closesocket, fd, 13); -#endif - - expect_any(__wrap__minfo, formatted_msg); - expect_any(__wrap__merror, formatted_msg); - - connected = connect_server(3, true); - assert_false(connected); - - /* Connect to first server (UDP), simulate connection error*/ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, -1); - connected = connect_server(0, true); - assert_false(connected); - - return; -} - -/* agent_handshake_to_server */ -static void test_agent_handshake_to_server(void **state) { - bool handshaked = false; - - /* Handshake with first server (UDP) */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, 21); - #ifndef TEST_WINAGENT - will_return(__wrap_recv, SERVER_ENC_ACK); - #else - will_return(wrap_recv, SERVER_ENC_ACK); - #endif - will_return(__wrap_wnet_select, 1); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - expect_string(__wrap_ReadSecMSG, buffer, SERVER_ENC_ACK); - will_return(__wrap_ReadSecMSG, "#!-agent ack "); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_any_count(__wrap__minfo, formatted_msg, 3); - - handshaked = agent_handshake_to_server(0, false); - assert_true(handshaked); - - /* Handshake with second server (TCP) */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[1].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.2")); - - expect_any(__wrap_OS_ConnectTCP, _port); - expect_any(__wrap_OS_ConnectTCP, _ip); - expect_any(__wrap_OS_ConnectTCP, ipv6); - will_return(__wrap_OS_ConnectTCP, 22); -#ifndef TEST_WINAGENT - expect_value(__wrap_close, fd, 21); -#else - expect_value(wrap_closesocket, fd, 21); -#endif - will_return(__wrap_wnet_select, 1); - expect_any(__wrap_OS_RecvSecureTCP, sock); - expect_any(__wrap_OS_RecvSecureTCP, size); - will_return(__wrap_OS_RecvSecureTCP, SERVER_ENC_ACK); - will_return(__wrap_OS_RecvSecureTCP, strlen(SERVER_ENC_ACK)); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - expect_string(__wrap_ReadSecMSG, buffer, SERVER_ENC_ACK); - will_return(__wrap_ReadSecMSG, "#!-agent ack "); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_any_count(__wrap__minfo, formatted_msg, 6); - - handshaked = agent_handshake_to_server(1, false); - assert_true(handshaked); - - /* Handshake sending the startup message */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[1].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.2")); - - expect_any(__wrap_OS_ConnectTCP, _port); - expect_any(__wrap_OS_ConnectTCP, _ip); - expect_any(__wrap_OS_ConnectTCP, ipv6); - will_return(__wrap_OS_ConnectTCP, 23); -#ifndef TEST_WINAGENT - expect_value(__wrap_close, fd, 22); -#else - expect_value(wrap_closesocket, fd, 22); -#endif - will_return(__wrap_wnet_select, 1); - expect_any(__wrap_OS_RecvSecureTCP, sock); - expect_any(__wrap_OS_RecvSecureTCP, size); - will_return(__wrap_OS_RecvSecureTCP, SERVER_ENC_ACK); - will_return(__wrap_OS_RecvSecureTCP, strlen(SERVER_ENC_ACK)); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - expect_string(__wrap_send_msg, msg, "1:wazuh-agent:ossec: Agent started: 'agent0->any'."); - expect_string(__wrap_ReadSecMSG, buffer, SERVER_ENC_ACK); - will_return(__wrap_ReadSecMSG, "#!-agent ack "); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_any_count(__wrap__minfo, formatted_msg, 3); - - handshaked = agent_handshake_to_server(1, true); - assert_true(handshaked); - - /* Handshake with connection error */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, -1); -#ifndef TEST_WINAGENT - expect_value(__wrap_close, fd, 23); -#else - expect_value(wrap_closesocket, fd, 23); -#endif - - expect_any(__wrap__minfo, formatted_msg); - expect_any(__wrap__merror, formatted_msg); - - handshaked = agent_handshake_to_server(0, false); - assert_false(handshaked); - - /* Handshake with reception error */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, 23); - will_return(__wrap_wnet_select, 0); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - - expect_any(__wrap__mwarn, formatted_msg); - - handshaked = agent_handshake_to_server(0, false); - assert_false(handshaked); - - /* Handshake with decode error */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, 24); -#ifndef TEST_WINAGENT - expect_value(__wrap_close, fd, 23); - will_return(__wrap_recv, SERVER_WRONG_ACK); -#else - expect_value(wrap_closesocket, fd, 23); - will_return(wrap_recv, SERVER_WRONG_ACK); -#endif - will_return(__wrap_wnet_select, 1); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - expect_string(__wrap_ReadSecMSG, buffer, SERVER_WRONG_ACK); - will_return(__wrap_ReadSecMSG, SERVER_WRONG_ACK); - will_return(__wrap_ReadSecMSG, KS_CORRUPT); - - handshaked = agent_handshake_to_server(0, false); - assert_false(handshaked); - - return; -} - - -static void test_agent_handshake_to_server_invalid_version(void **state) { - bool handshaked = false; - - /* Handshake with first server (UDP) */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, 21); - #ifndef TEST_WINAGENT - will_return(__wrap_recv, SERVER_ENC_ACK); - #else - will_return(wrap_recv, SERVER_ENC_ACK); - #endif - will_return(__wrap_wnet_select, 1); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - expect_string(__wrap_ReadSecMSG, buffer, SERVER_ENC_ACK); - will_return(__wrap_ReadSecMSG, "#!-err {\"message\": \"Agent version must be lower or equal to manager version\"}"); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_any_count(__wrap__minfo, formatted_msg, 1); - - expect_string(__wrap__mwarn, formatted_msg ,"Couldn't connect to server '127.0.0.1': 'Agent version must be lower or equal to manager version'"); - - handshaked = agent_handshake_to_server(0, false); - assert_false(handshaked); -} - -static void test_agent_handshake_to_server_error_getting_msg1(void **state) { - bool handshaked = false; - - /* Handshake with first server (UDP) */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, 21); - #ifndef TEST_WINAGENT - will_return(__wrap_recv, SERVER_ENC_ACK); - #else - will_return(wrap_recv, SERVER_ENC_ACK); - #endif - will_return(__wrap_wnet_select, 1); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - expect_string(__wrap_ReadSecMSG, buffer, SERVER_ENC_ACK); - will_return(__wrap_ReadSecMSG, "#!-err \"message\": \"Agent version must be lower or equal to manager version\"}"); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_any_count(__wrap__minfo, formatted_msg, 1); - - expect_string(__wrap__merror, formatted_msg ,"Error getting message from server '127.0.0.1'"); - - handshaked = agent_handshake_to_server(0, false); - assert_false(handshaked); -} - -static void test_agent_handshake_to_server_error_getting_msg2(void **state) { - bool handshaked = false; - - /* Handshake with first server (UDP) */ - will_return(__wrap_getDefine_Int, 5); - expect_string(__wrap_OS_GetHost, host, agt->server[0].rip); - will_return(__wrap_OS_GetHost, strdup("127.0.0.1")); - will_return(__wrap_OS_ConnectUDP, 21); - #ifndef TEST_WINAGENT - will_return(__wrap_recv, SERVER_ENC_ACK); - #else - will_return(wrap_recv, SERVER_ENC_ACK); - #endif - will_return(__wrap_wnet_select, 1); - expect_string(__wrap_send_msg, msg, "#!-agent startup {\"version\":\"v4.5.0\"}"); - expect_string(__wrap_ReadSecMSG, buffer, SERVER_ENC_ACK); - will_return(__wrap_ReadSecMSG, "#!-err {\"key\": \"Agent version must be lower or equal to manager version\"}"); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_any_count(__wrap__minfo, formatted_msg, 1); - - expect_string(__wrap__merror, formatted_msg ,"Error getting message from server '127.0.0.1'"); - - handshaked = agent_handshake_to_server(0, false); - assert_false(handshaked); -} - -/* agent_start_up_to_server */ -static void test_send_msg_on_startup(void **state) { - expect_string(__wrap_send_msg, msg, "1:wazuh-agent:ossec: Agent started: 'agent0->any'."); - send_msg_on_startup(); - return; -} - -/* send_agent_stopped_message */ -static void test_send_agent_stopped_message(void **state) { - - /* Sending the shutdown message */ - expect_string(__wrap_send_msg, msg, "#!-agent shutdown "); - - send_agent_stopped_message(); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_connect_server, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_agent_handshake_to_server, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_agent_handshake_to_server_invalid_version, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_agent_handshake_to_server_error_getting_msg1, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_agent_handshake_to_server_error_getting_msg2, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_send_msg_on_startup, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_send_agent_stopped_message, setup_test, teardown_test), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/config/CMakeLists.txt b/src/unit_tests/config/CMakeLists.txt deleted file mode 100644 index 70795c42513..00000000000 --- a/src/unit_tests/config/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -# Generate config library -file(GLOB config_files - ${SRC_FOLDER}/config/*.o) - -add_library(CONFIG_O STATIC ${config_files}) - -set_source_files_properties( - ${config_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - CONFIG_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(CONFIG_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -# Include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate config tests -list(APPEND config_names "test_client-config_validate_ipv6_link_local_interface") -list(APPEND config_flags "-Wl,--wrap,OS_GetHost -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap,syscom_dispatch \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown ${DEBUG_OP_WRAPPERS}") - -if(${TARGET} STREQUAL "server") - list(APPEND config_names "test_indexer") - list(APPEND config_flags "${DEBUG_OP_WRAPPERS}") -endif() - -# Compiling tests -list(LENGTH config_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET config_names ${counter} test_name) - list(GET config_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - CONFIG_O - ${TEST_DEPS} - ) - if(${TARGET} STREQUAL "winagent") - target_link_libraries(${test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/config/test_client-config_validate_ipv6_link_local_interface.c b/src/unit_tests/config/test_client-config_validate_ipv6_link_local_interface.c deleted file mode 100644 index 6441b183197..00000000000 --- a/src/unit_tests/config/test_client-config_validate_ipv6_link_local_interface.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../config/client-config.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" - -/* tests */ - -/* Validate_IPv6_Link_Local_Interface */ - -void test_Validate_IPv6_Link_Local_Interface_ipv4(void ** state) { - agent_server *servers = NULL; - - os_calloc(2, sizeof(agent_server), servers); - os_strdup("192.168.0.11", servers[0].rip); - servers[1].rip = NULL; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_ipv6_no_link_local(void ** state) { - agent_server *servers = NULL; - - os_calloc(2, sizeof(agent_server), servers); - os_strdup("ABCD::ABCD", servers[0].rip); - servers[1].rip = NULL; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_ipv6_one_link_local_no_interface(void ** state) { - agent_server *servers = NULL; - - os_calloc(2, sizeof(agent_server), servers); - os_strdup("FE80:0000:0000:0000::ABCD", servers[0].rip); - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - expect_string(__wrap__mwarn, formatted_msg, "No network interface index provided to use FE80:0000:0000:0000::ABCD link-local IPv6 address."); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_false(retval); - - os_free(servers[0].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_ipv6_one_link_local_with_interface(void ** state) { - agent_server *servers = NULL; - - os_calloc(2, sizeof(agent_server), servers); - os_strdup("FE80:0000:0000:0000::ABCD", servers[0].rip); - servers[0].network_interface = 1; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_multi_ipv4(void ** state) { - agent_server *servers = NULL; - - os_calloc(3, sizeof(agent_server), servers); - os_strdup("192.168.0.10", servers[0].rip); - os_strdup("192.168.0.20", servers[1].rip); - servers[2].rip = NULL; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - expect_string(__wrap_OS_GetHost, host, servers[1].rip); - will_return(__wrap_OS_GetHost, strdup(servers[1].rip)); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers[1].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_multi_ipv4_ipv6(void ** state) { - agent_server *servers = NULL; - - os_calloc(3, sizeof(agent_server), servers); - os_strdup("192.168.0.10", servers[0].rip); - os_strdup("FE80:0000:0000:0000::ABCD", servers[1].rip); - servers[2].rip = NULL; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - expect_string(__wrap_OS_GetHost, host, servers[1].rip); - will_return(__wrap_OS_GetHost, strdup(servers[1].rip)); - - expect_string(__wrap__mwarn, formatted_msg, "No network interface index provided to use FE80:0000:0000:0000::ABCD link-local IPv6 address."); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers[1].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv4(void ** state) { - agent_server *servers = NULL; - - os_calloc(3, sizeof(agent_server), servers); - os_strdup("FE80:0000:0000:0000::ABCD", servers[0].rip); - os_strdup("192.168.0.10", servers[1].rip); - servers[2].rip = NULL; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - expect_string(__wrap_OS_GetHost, host, servers[1].rip); - will_return(__wrap_OS_GetHost, strdup(servers[1].rip)); - - expect_string(__wrap__mwarn, formatted_msg, "No network interface index provided to use FE80:0000:0000:0000::ABCD link-local IPv6 address."); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers[1].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv6_no_interface(void ** state) { - agent_server *servers = NULL; - - os_calloc(3, sizeof(agent_server), servers); - os_strdup("FE80:0000:0000:0000::ABCD", servers[0].rip); - os_strdup("FE80:0000:0000:0000::EF11", servers[1].rip); - servers[2].rip = NULL; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - expect_string(__wrap_OS_GetHost, host, servers[1].rip); - will_return(__wrap_OS_GetHost, strdup(servers[1].rip)); - - expect_string(__wrap__mwarn, formatted_msg, "No network interface index provided to use FE80:0000:0000:0000::ABCD link-local IPv6 address."); - expect_string(__wrap__mwarn, formatted_msg, "No network interface index provided to use FE80:0000:0000:0000::EF11 link-local IPv6 address."); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_false(retval); - - os_free(servers[0].rip); - os_free(servers[1].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv6_interface(void ** state) { - agent_server *servers = NULL; - - os_calloc(3, sizeof(agent_server), servers); - os_strdup("FE80:0000:0000:0000::ABCD", servers[0].rip); - os_strdup("FE80:0000:0000:0000::ABCD", servers[1].rip); - servers[2].rip = NULL; - servers[1].network_interface = 1; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - expect_string(__wrap_OS_GetHost, host, servers[1].rip); - will_return(__wrap_OS_GetHost, strdup(servers[1].rip)); - - expect_string(__wrap__mwarn, formatted_msg, "No network interface index provided to use FE80:0000:0000:0000::ABCD link-local IPv6 address."); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers[1].rip); - os_free(servers); -} - -void test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv6_all_interface(void ** state) { - agent_server *servers = NULL; - - os_calloc(3, sizeof(agent_server), servers); - os_strdup("FE80:0000:0000:0000::ABCD", servers[0].rip); - servers[0].network_interface = 2; - os_strdup("FE80:0000:0000:0000::ABCD", servers[1].rip); - servers[1].network_interface = 1; - servers[2].rip = NULL; - - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - expect_string(__wrap_OS_GetHost, host, servers[0].rip); - will_return(__wrap_OS_GetHost, strdup(servers[0].rip)); - - bool retval = Validate_IPv6_Link_Local_Interface(servers); - - assert_true(retval); - - os_free(servers[0].rip); - os_free(servers[1].rip); - os_free(servers); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Tests w_agentd_get_buffer_lenght - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_ipv4), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_ipv6_no_link_local), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_ipv6_one_link_local_no_interface), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_ipv6_one_link_local_with_interface), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_multi_ipv4), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_multi_ipv4_ipv6), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv4), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv6_no_interface), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv6_interface), - cmocka_unit_test(test_Validate_IPv6_Link_Local_Interface_multi_ipv6_ipv6_all_interface), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/config/test_indexer.c b/src/unit_tests/config/test_indexer.c deleted file mode 100644 index c209c591416..00000000000 --- a/src/unit_tests/config/test_indexer.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../config/config.h" -#include "../../config/indexer-config.h" - - -typedef struct test_structure { - OS_XML xml; - XML_NODE nodes; -} test_structure; - -static const XML_NODE string_to_xml_node(const char * string, OS_XML *_lxml){ - XML_NODE nodes; - OS_ReadXMLString(string, _lxml); - nodes = OS_GetElementsbyNode(_lxml, NULL); - return nodes; -} - -static int setup_test_read(void **state) { - indexer_config = NULL; - test_structure *test; - os_calloc(1, sizeof(test_structure), test); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - os_free(test); - - if (indexer_config) { - cJSON_Delete(indexer_config); - } - return 0; -} - -void test_read_full_configuration(void **state) { - const char *string = - "yes" - "" - "http://10.2.20.2:9200" - "https://10.2.20.42:9200" - "" - "" - "" - "/var/ossec/" - "/var/ossec_cert/" - "" - "cert" - "key_example" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\",\"hosts\":[\"http://10.2.20.2:9200\",\"https://10.2.20.42:9200\"],\"ssl\":{\"certificate_authorities\":[\"/var/ossec/\",\"/var/ossec_cert/\"],\"certificate\":\"cert\",\"key\":\"key_example\"}}"); - cJSON_free(json_result); -} - -void test_read_duplicate_configuration(void **state) { - const char *string = - "yes" - "" - "http://10.2.20.2:9200" - "https://10.2.20.42:9200" - "" - "" - "" - "/var/ossec/" - "/var/ossec_cert/" - "" - "cert" - "key_example" - "" - "yes" - "" - "http://10.2.20.2:9200" - "https://10.2.20.42:9200" - "" - "" - "" - "/var/ossec/" - "/var/ossec_cert/" - "" - "cert" - "key_example" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\",\"hosts\":[\"http://10.2.20.2:9200\",\"https://10.2.20.42:9200\"],\"ssl\":{\"certificate_authorities\":[\"/var/ossec/\",\"/var/ossec_cert/\"],\"certificate\":\"cert\",\"key\":\"key_example\"}}"); - cJSON_free(json_result); -} - -void test_read_multiple_configuration(void **state) { - const char *string = - "yes" - "" - "http://10.1.10.1:9200" - "https://10.1.10.41:9200" - "" - "" - "" - "/var/ossec/" - "/var/ossec_cert/" - "" - "cert" - "key_example" - "" - "yes" - "" - "http://10.2.20.2:9200" - "https://10.2.20.42:9200" - "" - "" - "" - "/var/ossec2/" - "/var/ossec_cert2/" - "" - "cert_2" - "key_example_2" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\",\"hosts\":[\"http://10.2.20.2:9200\",\"https://10.2.20.42:9200\"],\"ssl\":{\"certificate_authorities\":[\"/var/ossec2/\",\"/var/ossec_cert2/\"],\"certificate\":\"cert_2\",\"key\":\"key_example_2\"}}"); - cJSON_free(json_result); -} - -void test_read_empty_configuration(void **state) { - const char *string = ""; - test_structure *test = *state; - expect_string(__wrap__mdebug1, formatted_msg, "Empty configuration for module 'indexer'"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{}"); - cJSON_free(json_result); -} - -void test_read_empty_field_configuration(void **state) { - const char *string = - "yes" - "" - "http://10.2.20.2:9200" - "https://10.2.20.42:9200" - "" - "" - "" - "/var/ossec/" - "/var/ossec_cert/" - "" - "cert" - "" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\",\"hosts\":[\"http://10.2.20.2:9200\",\"https://10.2.20.42:9200\"],\"ssl\":{\"certificate_authorities\":[\"/var/ossec/\",\"/var/ossec_cert/\"],\"certificate\":\"cert\",\"key\":\"\"}}"); - cJSON_free(json_result); -} - -void test_read_field_host_0_entries_configuration_fail(void **state) { - const char *string = - "yes" - "" - "" - "" - "" - "/var/ossec/" - "/var/ossec_cert/" - "" - "cert" - "key_example" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "indexer.hosts is empty in module 'indexer'. Check configuration"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), OS_MISVALUE); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\"}"); - cJSON_free(json_result); -} - -void test_read_field_host_1_entries_configuration(void **state) { - const char *string = - "yes" - "" - "http://10.2.20.2:9200" - "" - "" - "" - "/var/ossec/" - "/var/ossec_cert/" - "" - "cert" - "key_example" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\",\"hosts\":[\"http://10.2.20.2:9200\"],\"ssl\":{\"certificate_authorities\":[\"/var/ossec/\",\"/var/ossec_cert/\"],\"certificate\":\"cert\",\"key\":\"key_example\"}}"); - cJSON_free(json_result); -} - -void test_read_field_certificate_authorities_0_entries_configuration_fail(void **state) { - const char *string = - "yes" - "" - "http://10.2.20.2:9200" - "https://10.2.20.42:9200" - "" - "" - "" - "" - "cert" - "key_example" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "indexer.ssl.certificate_authorities is empty in module 'indexer'. Check configuration"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\",\"hosts\":[\"http://10.2.20.2:9200\",\"https://10.2.20.42:9200\"],\"ssl\":{}}"); - cJSON_free(json_result); -} - -void test_read_field_certificate_authorities_1_entries_configuration(void **state) { - const char *string = - "yes" - "" - "http://10.2.20.2:9200" - "https://10.2.20.42:9200" - "" - "" - "" - "/var/ossec/" - "" - "cert" - "key_example" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(Read_Indexer(&(test->xml), test->nodes), 0); - char * json_result = cJSON_PrintUnformatted(indexer_config); - assert_string_equal(json_result, "{\"enabled\":\"yes\",\"hosts\":[\"http://10.2.20.2:9200\",\"https://10.2.20.42:9200\"],\"ssl\":{\"certificate_authorities\":[\"/var/ossec/\"],\"certificate\":\"cert\",\"key\":\"key_example\"}}"); - cJSON_free(json_result); -} - -int main(void) { - const struct CMUnitTest tests_configuration[] = { - cmocka_unit_test_setup_teardown(test_read_full_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_duplicate_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_multiple_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_empty_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_empty_field_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_field_host_0_entries_configuration_fail, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_field_host_1_entries_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_field_certificate_authorities_0_entries_configuration_fail, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_field_certificate_authorities_1_entries_configuration, setup_test_read, teardown_test_read), - }; - return cmocka_run_group_tests(tests_configuration, NULL, NULL); -} diff --git a/src/unit_tests/fluentd_forwarder/CMakeLists.txt b/src/unit_tests/fluentd_forwarder/CMakeLists.txt deleted file mode 100644 index d06dce0ebf5..00000000000 --- a/src/unit_tests/fluentd_forwarder/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Generate fluentd_forwarder library -file(GLOB fluentd_forwarder_files - ${SRC_FOLDER}/wazuh_modules/*.o) - -add_library(FLUENTD_FORWARDER_O STATIC ${fluentd_forwarder_files}) - -set_source_files_properties( - ${fluentd_forwarder_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - FLUENTD_FORWARDER_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(FLUENTD_FORWARDER_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate fluentd_forwarder tests -list(APPEND fluentd_forwarder_names "test_fluentd_forwarder") -list(APPEND fluentd_forwarder_flags "-Wl,--wrap,time -Wl,--wrap,OS_SendUnix -Wl,--wrap,OS_ConnectUnixDomain -Wl,--wrap,OS_ConnectTCP ${DEBUG_OP_WRAPPERS}") - -# Compiling tests -list(LENGTH fluentd_forwarder_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET fluentd_forwarder_names ${counter} test_name) - list(GET fluentd_forwarder_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - FLUENTD_FORWARDER_O - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/fluentd_forwarder/test_fluentd_forwarder.c b/src/unit_tests/fluentd_forwarder/test_fluentd_forwarder.c deleted file mode 100644 index 844a1904ce3..00000000000 --- a/src/unit_tests/fluentd_forwarder/test_fluentd_forwarder.c +++ /dev/null @@ -1,680 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/wm_fluent.h" -#include "../../wazuh_modules/wm_fluent.c" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" - -typedef struct test_struct { - wm_fluent_t *fluent; - cJSON * configuration_dump; -} test_struct_t; - -#define SOCKET_PATH "/tmp/socket-tmp" - -time_t __wrap_time(int time) { - check_expected(time); - return mock(); -} - -// Setup / Teardown - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1, sizeof(wm_fluent_t), init_data->fluent); - - *state = init_data; - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - if(data->configuration_dump) { - cJSON_Delete(data->configuration_dump); - } - os_free(data->fluent); - os_free(data); - - return OS_SUCCESS; -} - -void assert_int_lt(int X, int Y) { - if (X < Y) { - assert_true(true); - } else { - assert_false(false); - } -} - -void assert_int_ge(int X, int Y) { - if (X >= Y) { - assert_true(true); - } else { - assert_false(false); - } -} - -// Tests -void test_check_config_no_tag(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap__mterror, tag, "fluent-forward"); - expect_string(__wrap__mterror, formatted_msg, "No tag defined."); - - data->fluent->tag = NULL; - assert_int_lt(wm_fluent_check_config(data->fluent), 0); -} - -void test_check_config_no_socket(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap__mterror, tag, "fluent-forward"); - expect_string(__wrap__mterror, formatted_msg, "No socket_path defined."); - - data->fluent->tag = "debug.test"; - assert_int_lt(wm_fluent_check_config(data->fluent), 0); -} - -void test_check_config_no_address(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap__mtinfo, tag, "fluent-forward"); - expect_string(__wrap__mtinfo, formatted_msg, "No client address defined. Using localhost."); - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/socket.s"; - int simple_configuration_no_address = wm_fluent_check_config(data->fluent); - os_free(data->fluent->address); - assert_int_equal(simple_configuration_no_address, 0); -} - -void test_check_config_invalid_timeout(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/fluent-socket"; - data->fluent->address = "localhost"; - data->fluent->timeout = -1; - - expect_string(__wrap__mterror, tag, "fluent-forward"); - expect_string(__wrap__mterror, formatted_msg, "Invalid timeout value (negative)"); - - assert_int_lt(wm_fluent_check_config(data->fluent), 0); -} - -void test_check_config_no_password(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/fluent-socket"; - data->fluent->address = "localhost"; - data->fluent->timeout = 0; - data->fluent->user_name = "user"; - - expect_string(__wrap__mtwarn, tag, "fluent-forward"); - expect_string(__wrap__mtwarn, formatted_msg, "No shared_key defined. SSL is disabled and the user_name option won't apply."); - - expect_string(__wrap__mterror, tag, "fluent-forward"); - expect_string(__wrap__mterror, formatted_msg, "Password required because user_name is defined"); - - assert_int_lt(wm_fluent_check_config(data->fluent), 0); -} - -void test_check_valid_config_tls(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/fluent-socket"; - data->fluent->address = "localhost"; - data->fluent->certificate = "test.pem"; - data->fluent->shared_key = "secret_key"; - data->fluent->user_name = "foo"; - data->fluent->user_pass = "bar"; - data->fluent->timeout = 0; - int simple_configuration_no_password = wm_fluent_check_config(data->fluent); - - assert_int_equal(simple_configuration_no_password, 0); -} - -void test_check_config_dump(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/fluent-socket"; - data->fluent->address = "localhost"; - data->fluent->timeout = 0; - data->fluent->user_name = "user"; - data->fluent->user_pass = "bar"; - data->fluent->shared_key = "secret_key"; - data->fluent->timeout = 100; - data->fluent->port = 24224; - data->configuration_dump = wm_fluent_dump(data->fluent); - - assert_non_null(data->configuration_dump); -} - -void test_check_default_connection(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/fluent-socket"; - data->fluent->address = "localhost"; - data->fluent->port = 24224; - data->fluent->timeout = 0; - - expect_any(__wrap__mtdebug2, tag); - expect_any(__wrap__mtdebug2, formatted_msg); - - expect_any(__wrap_OS_ConnectTCP, _port); - expect_any(__wrap_OS_ConnectTCP, _ip); - expect_any(__wrap_OS_ConnectTCP, ipv6); - will_return(__wrap_OS_ConnectTCP, 1); - - int simple_configuration_defaut_connection = wm_fluent_connect(data->fluent); - - assert_int_equal(simple_configuration_defaut_connection, 0); -} - -void test_check_default_handshake(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/fluent-socket"; - data->fluent->address = "localhost"; - data->fluent->port = 24224; - data->fluent->timeout = 0; - - expect_string(__wrap__mtinfo, tag, "fluent-forward"); - expect_string(__wrap__mtinfo, formatted_msg, "Connected to host localhost:24224"); - - expect_any(__wrap__mtdebug2, tag); - expect_any(__wrap__mtdebug2, formatted_msg); - - expect_any(__wrap_OS_ConnectTCP, _port); - expect_any(__wrap_OS_ConnectTCP, _ip); - expect_any(__wrap_OS_ConnectTCP, ipv6); - will_return(__wrap_OS_ConnectTCP, 1); - - int simple_configuration_defaut_handshake = wm_fluent_handshake(data->fluent); - assert_int_equal(simple_configuration_defaut_handshake, 0); -} - -void test_check_send(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->fluent->tag = "debug.test"; - data->fluent->sock_path = "/var/run/fluent-socket"; - data->fluent->address = "localhost"; - data->fluent->port = 24224; - data->fluent->timeout = 0; - data->fluent->object_key = "message"; - - expect_string(__wrap__mtinfo, tag, "fluent-forward"); - expect_string(__wrap__mtinfo, formatted_msg, "Connected to host localhost:24224"); - - expect_any(__wrap__mtdebug2, tag); - expect_any(__wrap__mtdebug2, formatted_msg); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 165884); - - expect_any(__wrap_OS_ConnectTCP, _port); - expect_any(__wrap_OS_ConnectTCP, _ip); - expect_any(__wrap_OS_ConnectTCP, ipv6); - will_return(__wrap_OS_ConnectTCP, 1); - - int simple_configuration_defaut_handshake = wm_fluent_handshake(data->fluent); - assert_int_equal(simple_configuration_defaut_handshake, 0); - - char *msg = "{\"json\":\"message\"}"; - assert_int_ge(wm_fluent_send(data->fluent, msg, strlen(msg)), 0); -} - -void test_send_json_message_success_udp(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = -1; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SOCKET_PATH); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_DGRAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR + 256); - will_return(__wrap_OS_ConnectUnixDomain, fdsock); - - expect_value(__wrap_OS_SendUnix, socket, fdsock); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, 1); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 165884); - expect_string_count(__wrap__mdebug1, formatted_msg, "Connected to socket 'fluentd_test' (/tmp/socket-tmp)",1); - - expect_string_count(__wrap__mdebug2, formatted_msg, "Message send to socket 'fluentd_test' (/tmp/socket-tmp) successfully.",1); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_success_udp_again(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = -1; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 165884); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SOCKET_PATH); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_DGRAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR + 256); - will_return(__wrap_OS_ConnectUnixDomain, fdsock); - - expect_string(__wrap__mdebug1, formatted_msg, "Connected to socket 'fluentd_test' (/tmp/socket-tmp)"); - - expect_value(__wrap_OS_SendUnix, socket, fdsock); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, OS_SOCKTERR); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 165884); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SOCKET_PATH); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_DGRAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR + 256); - will_return(__wrap_OS_ConnectUnixDomain, fdsock); - - expect_string(__wrap__mdebug1, formatted_msg, "Connected to socket 'fluentd_test' (/tmp/socket-tmp)"); - - expect_value(__wrap_OS_SendUnix, socket, fdsock); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, 1); - - expect_string_count(__wrap__mdebug2, formatted_msg, "Message send to socket 'fluentd_test' (/tmp/socket-tmp) successfully.",1); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_success_tcp(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_TCP; - socket_info->socket = -1; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_STREAM, OS_MAXSTR); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SOCKET_PATH); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR + 256); - will_return(__wrap_OS_ConnectUnixDomain, fdsock); - - expect_value(__wrap_OS_SendUnix, socket, fdsock); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, 1); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 165884); - - expect_string_count(__wrap__mdebug1, formatted_msg, "Connected to socket 'fluentd_test' (/tmp/socket-tmp)",1); - - expect_string_count(__wrap__mdebug2, formatted_msg, "Message send to socket 'fluentd_test' (/tmp/socket-tmp) successfully.",1); - - int ret = SendJSONtoSCK(json_msg,socket_info); - - assert_return_code(ret,1); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_invalid_socket(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = 0; - socket_info->socket = -1; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_any(__wrap__merror,formatted_msg); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_null(void **state) { - - socket_forwarder* socket_info = NULL; - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_any(__wrap__merror,formatted_msg); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(json_msg); - unlink(SOCKET_PATH); -} - -void test_send_json_message_socket_error(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = fdsock; - - errno=ENOBUFS; - - expect_value(__wrap_OS_SendUnix, socket, fdsock); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, OS_SOCKBUSY); - - expect_string(__wrap__mdebug2, formatted_msg, "Cannot send message to socket 'fluentd_test' due No buffer space available. (Abort)."); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_socket_error_connect(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = 0; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_value(__wrap_OS_SendUnix, socket, 0); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, OS_SOCKTERR); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 1655884); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SOCKET_PATH); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_DGRAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR + 256); - will_return(__wrap_OS_ConnectUnixDomain, fdsock); - - expect_value(__wrap_OS_SendUnix, socket, fdsock); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, OS_SOCKTERR); - - expect_string(__wrap__mdebug1, formatted_msg, "Connected to socket 'fluentd_test' (/tmp/socket-tmp)"); - - expect_string(__wrap__mdebug2, formatted_msg, "Cannot send message to socket 'fluentd_test' due No such file or directory. (Abort)."); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_socket_error_time(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = -1; - socket_info->last_attempt = 208354995; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 1); - expect_string(__wrap__mdebug2, formatted_msg, "Discarding event '{\"info\":\"test\"}' due to connection issue with 'fluentd_test'"); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_socket_error_time_again(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = 0; - socket_info->last_attempt = 208354995; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_value(__wrap_OS_SendUnix, socket, 0); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, OS_SOCKTERR); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 1); - expect_string(__wrap__mdebug2, formatted_msg, "Discarding event from analysisd due to connection issue with 'fluentd_test', No such file or directory. (Abort)."); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_socket_error_unable_connect(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = -1; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SOCKET_PATH); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_DGRAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR + 256); - will_return(__wrap_OS_ConnectUnixDomain, -1); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 1); - expect_any(__wrap__merror,formatted_msg); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -void test_send_json_message_socket_error_unable_connect_again(void **state) { - - socket_forwarder* socket_info; - - os_calloc(1,sizeof(socket_forwarder),socket_info); - - static const int fdsock = 65555; - char* json_msg = strdup("{\"info\":\"test\"}"); - - socket_info->name = "fluentd_test"; - socket_info->location = SOCKET_PATH; - socket_info->mode = IPPROTO_UDP; - socket_info->socket = 0; - - OS_BindUnixDomain(SOCKET_PATH, SOCK_DGRAM, OS_MAXSTR); - - expect_value(__wrap_OS_SendUnix, socket, 0); - expect_string(__wrap_OS_SendUnix, msg, json_msg); - expect_value(__wrap_OS_SendUnix, size, strlen(json_msg)); - will_return(__wrap_OS_SendUnix, OS_SOCKTERR); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, 165884); - - expect_string(__wrap_OS_ConnectUnixDomain, path, SOCKET_PATH); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_DGRAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR + 256); - will_return(__wrap_OS_ConnectUnixDomain, -1); - - expect_any(__wrap__merror,formatted_msg); - - SendJSONtoSCK(json_msg,socket_info); - - os_free(socket_info); - unlink(SOCKET_PATH); -} - -int main(void) { - const struct CMUnitTest tests[] = { - - /* Simple configuration, no tag defined */ - cmocka_unit_test_setup_teardown(test_check_config_no_tag, test_setup, test_teardown), - - /* Simple configuration, no socket_path defined */ - cmocka_unit_test_setup_teardown(test_check_config_no_socket, test_setup, test_teardown), - - /* Simple configuration, no address defined */ - cmocka_unit_test_setup_teardown(test_check_config_no_address, test_setup, test_teardown), - - /* Simple configuration, invalid timeout defined */ - cmocka_unit_test_setup_teardown(test_check_config_invalid_timeout, test_setup, test_teardown), - - /* Simple configuration, no password defined */ - cmocka_unit_test_setup_teardown(test_check_config_no_password, test_setup, test_teardown), - - /* Simple configuration, TLS valid */ - cmocka_unit_test_setup_teardown(test_check_valid_config_tls, test_setup, test_teardown), - - /* Test connection todata->fluentd server, no TLS */ - cmocka_unit_test_setup_teardown(test_check_default_connection, test_setup, test_teardown), - - /* Test handshake todata->fluentd server, no TLS */ - cmocka_unit_test_setup_teardown(test_check_default_handshake, test_setup, test_teardown), - - /* Test send todata->fluentd server, no TLS */ - cmocka_unit_test_setup_teardown(test_check_send, test_setup, test_teardown), - - /* Test configuration dump*/ - cmocka_unit_test_setup_teardown(test_check_config_dump, test_setup, test_teardown), - - /* Test send JSON using unix socket UDP*/ - cmocka_unit_test_setup_teardown(test_send_json_message_success_udp, test_setup, test_teardown), - /* Test send in second try JSON using unix socket UDP*/ - cmocka_unit_test_setup_teardown(test_send_json_message_success_udp_again, test_setup, test_teardown), - /* Test send JSON using unix socket TCP*/ - cmocka_unit_test_setup_teardown(test_send_json_message_success_tcp, test_setup, test_teardown), - /* Test send JSON using NULL socket*/ - cmocka_unit_test_setup_teardown(test_send_json_message_invalid_socket, test_setup, test_teardown), - /* Test send NULL object*/ - cmocka_unit_test_setup_teardown(test_send_json_message_null, test_setup, test_teardown), - /* Test no listener*/ - cmocka_unit_test_setup_teardown(test_send_json_message_socket_error, test_setup, test_teardown), - /* Test wrong socket*/ - cmocka_unit_test_setup_teardown(test_send_json_message_socket_error_connect, test_setup, test_teardown), - /* Test time out */ - cmocka_unit_test_setup_teardown(test_send_json_message_socket_error_time, test_setup, test_teardown), - /* Test time out second time*/ - cmocka_unit_test_setup_teardown(test_send_json_message_socket_error_time_again, test_setup, test_teardown), - /* Test unable to connect with socket */ - cmocka_unit_test_setup_teardown(test_send_json_message_socket_error_unable_connect, test_setup, test_teardown), - /* Test unable to connect with socket in second try */ - cmocka_unit_test_setup_teardown(test_send_json_message_socket_error_unable_connect_again, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/logcollector/CMakeLists.txt b/src/unit_tests/logcollector/CMakeLists.txt deleted file mode 100644 index 89b5878568e..00000000000 --- a/src/unit_tests/logcollector/CMakeLists.txt +++ /dev/null @@ -1,166 +0,0 @@ -# Generate logcollector library -file(GLOB logcollector_files - ${SRC_FOLDER}/logcollector/*.o) -add_library(LOGCOLLECTOR_O STATIC ${logcollector_files}) -set_source_files_properties( - ${logcollector_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) -set_target_properties( - LOGCOLLECTOR_O - PROPERTIES - LINKER_LANGUAGE C -) -target_link_libraries(LOGCOLLECTOR_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate logcollector tests -if(${TARGET} STREQUAL "winagent") - list(APPEND logcollector_names "test_read_win_event_channel") - list(APPEND logcollector_flags "-Wl,--wrap,wstr_split -Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap,convert_windows_string \ - ${DEBUG_OP_WRAPPERS}") -else() - list(APPEND logcollector_names "test_logcollector") - list(APPEND logcollector_flags "-Wl,--wrap,OS_SHA1_Stream -Wl,--wrap,merror_exit \ - -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fread -Wl,--wrap,fseek \ - -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fgetpos \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_AddArrayToObject -Wl,--wrap,cJSON_AddStringToObject \ - -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_AddItemToArray -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,cJSON_PrintUnformatted -Wl,--wrap,cJSON_Delete -Wl,--wrap,fopen -Wl,--wrap,clearerr \ - -Wl,--wrap,cJSON_GetObjectItem -Wl,--wrap,cJSON_GetArraySize -Wl,--wrap,cJSON_GetArrayItem \ - -Wl,--wrap,cJSON_GetStringValue -Wl,--wrap,OS_SHA1_File_Nbytes -Wl,--wrap,fileno -Wl,--wrap,fstat \ - -Wl,--wrap,pthread_rwlock_rdlock -Wl,--wrap,pthread_rwlock_unlock -Wl,--wrap,wfopen \ - -Wl,--wrap,stat -Wl,--wrap=fgetc -Wl,--wrap=w_fseek -Wl,--wrap,w_ftell \ - -Wl,--wrap,OS_SHA1_File_Nbytes_with_fp_check -Wl,--wrap,cJSON_CreateString \ - -Wl,--wrap,cJSON_AddItemToObject -Wl,--wrap,wpclose -Wl,--wrap,kill \ - -Wl,--wrap,so_get_function_sym -Wl,--wrap,so_get_module_handle -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS} \ - ${HASH_OP_WRAPPERS}") - - list(APPEND logcollector_names "test_read_multiline_regex") - list(APPEND logcollector_flags "-Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,popen \ - -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fseek -Wl,--wrap=fgetc\ - -Wl,--wrap,time -Wl,--wrap,can_read -Wl,--wrap,w_ftell -Wl,--wrap,w_expression_match \ - -Wl,--wrap,w_msg_hash_queues_push -Wl,--wrap,fgetpos -Wl,--wrap=w_update_file_status \ - -Wl,--wrap=w_get_hash_context -Wl,--wrap=_fseeki64 -Wl,--wrap=OS_SHA1_Stream \ - -Wl,--wrap=w_fseek -Wl,--wrap,_mdebug2 -Wl,--wrap,wfopen") - - list(APPEND logcollector_names "test_localfile-config") - list(APPEND logcollector_flags "-Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,wfopen \ - -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fseek -Wl,--wrap=fgetc\ - -Wl,--wrap,w_get_attr_val_by_name -Wl,--wrap,fgetpos -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_AddStringToObject \ - -Wl,--wrap,cJSON_AddBoolToObject -Wl,--wrap,cJSON_Delete -Wl,--wrap,cJSON_CreateArray \ - -Wl,--wrap,cJSON_AddItemToArray") - - list(APPEND logcollector_names "test_state") - list(APPEND logcollector_flags "-Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets \ - -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fseek -Wl,--wrap=fgetc \ - -Wl,--wrap,fgetpos -Wl,--wrap,time -Wl,--wrap,wfopen \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_CreateArray \ - -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_AddNumberToObject \ - -Wl,--wrap,cJSON_AddItemToArray -Wl,--wrap,cJSON_AddItemToObject \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,pthread_mutex_lock \ - -Wl,--wrap,cJSON_Delete -Wl,--wrap,cJSON_Print -Wl,--wrap,getDefine_Int \ - -Wl,--wrap,FOREVER -Wl,--wrap,sleep -Wl,--wrap,getpid -Wl,--wrap,cJSON_Duplicate \ - -Wl,--wrap,strftime -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS} ${HASH_OP_WRAPPERS}") - - list(APPEND logcollector_names "test_lccom") - list(APPEND logcollector_flags "-Wl,--wrap,w_logcollector_state_get -Wl,--wrap,cJSON_CreateObject \ - -Wl,--wrap,cJSON_AddNumberToObject \ - -Wl,--wrap,cJSON_AddObjectToObject -Wl,--wrap,cJSON_AddStringToObject \ - -Wl,--wrap,cJSON_AddItemToObject -Wl,--wrap,cJSON_AddFalseToObject -Wl,--wrap,cJSON_PrintUnformatted \ - -Wl,--wrap,cJSON_Delete -Wl,--wrap,_mwarn -Wl,--wrap,stat -Wl,--wrap,_mdebug2 \ - -Wl,--wrap,difftime -Wl,--wrap,strftime ${DEBUG_OP_WRAPPERS}") - - list(APPEND logcollector_names "test_macos_log") - list(APPEND logcollector_flags "-Wl,--wrap,wpopenv -Wl,--wrap,fileno -Wl,--wrap,fcntl -Wl,--wrap,_merror \ - -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fgetpos \ - -Wl,--wrap,fopen -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite \ - -Wl,--wrap,remove -Wl,--wrap,fgetc -Wl,--wrap,wpclose -Wl,--wrap,access \ - -Wl,--wrap,getpid -Wl,--wrap,_minfo -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,pthread_rwlock_unlock -Wl,--wrap,pthread_rwlock_rdlock \ - -Wl,--wrap,so_get_function_sym -Wl,--wrap,so_get_module_handle -Wl,--wrap,wfopen \ - -Wl,--wrap,_mdebug1 -Wl,--wrap,w_get_os_codename -Wl,--wrap,w_get_process_childs -Wl,--wrap,popen") - - list(APPEND logcollector_names "test_read_macos") - list(APPEND logcollector_flags "-Wl,--wrap,w_expression_match -Wl,--wrap,can_read -Wl,--wrap,fgets \ - -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgetpos -Wl,--wrap,_mdebug2\ - -Wl,--wrap,fopen -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,popen \ - -Wl,--wrap,remove -Wl,--wrap,fgetc -Wl,--wrap,_merror -Wl,--wrap,waitpid \ - -Wl,--wrap,w_msg_hash_queues_push -Wl,--wrap,_mdebug1 -Wl,--wrap,_minfo \ - -Wl,--wrap,kill -Wl,--wrap,wpopenv -Wl,--wrap,wpclose -Wl,--wrap,strerror \ - -Wl,--wrap,time -Wl,--wrap,so_get_function_sym -Wl,--wrap,so_get_module_handle \ - -Wl,--wrap,isDebug -Wl,--wrap,w_get_first_child -Wl,--wrap,w_is_macos_sierra \ - -Wl,--wrap,w_macos_set_log_settings -Wl,--wrap,w_macos_set_last_log_timestamp \ - -Wl,--wrap,w_macos_set_is_valid_data -Wl,--wrap,wfopen") - - list(APPEND logcollector_names "test_read_multiline") - list(APPEND logcollector_flags "-Wl,--wrap,fopen -Wl,--wrap,popen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets \ - -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fseek -Wl,--wrap=fgetc \ - -Wl,--wrap,time -Wl,--wrap,can_read -Wl,--wrap,w_ftell -Wl,--wrap,w_expression_match \ - -Wl,--wrap,fgetpos -Wl,--wrap=w_update_file_status -Wl,--wrap,_merror \ - -Wl,--wrap=w_get_hash_context -Wl,--wrap=_fseeki64 -Wl,--wrap=OS_SHA1_Stream \ - -Wl,--wrap=w_fseek -Wl,--wrap,wfopen") - - list(APPEND logcollector_names "test_read_journal") - list(APPEND logcollector_flags "-Wl,--wrap,_mwarn -Wl,--wrap,fgets -Wl,--wrap,remove -Wl,--wrap,fgetc \ - -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgetpos -Wl,--wrap,_mdebug2\ - -Wl,--wrap,fopen -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,popen \ - -Wl,--wrap,w_journal_context_create -Wl,--wrap,w_journal_context_seek_most_recent \ - -Wl,--wrap,w_journal_context_seek_timestamp -Wl,--wrap,w_journal_entry_dump \ - -Wl,--wrap,w_journal_entry_to_string -Wl,--wrap,w_journal_entry_free \ - -Wl,--wrap,w_journal_context_next_newest_filtered -Wl,--wrap,_merror -Wl,--wrap,_minfo \ - -Wl,--wrap,_mdebug1 -Wl,--wrap,_mdebug2 -Wl,--wrap,isDebug -Wl,--wrap,w_msg_hash_queues_push \ - -Wl,--wrap,can_read") - - list(APPEND logcollector_names "test_journal_log") - list(APPEND logcollector_flags "-Wl,--wrap,stat -Wl,--wrap,_mwarn -Wl,--wrap,dlsym -Wl,--wrap,dlerror -Wl,--wrap,gettimeofday \ - -Wl,--wrap,_mdebug1 -Wl,--wrap,_mdebug2 -Wl,--wrap,isDebug \ - -Wl,--wrap,fopen -Wl,--wrap,popen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets \ - -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fseek -Wl,--wrap=fgetc \ - -Wl,--wrap,fgetpos -Wl,--wrap,gmtime_r -Wl,--wrap,getline -Wl,--wrap,dlopen -Wl,--wrap,dlclose \ - -Wl,--wrap,sd_journal_open -Wl,--wrap,sd_journal_close -Wl,--wrap,sd_journal_previous \ - -Wl,--wrap,sd_journal_next -Wl,--wrap,sd_journal_seek_tail \ - -Wl,--wrap,sd_journal_seek_realtime_usec -Wl,--wrap,sd_journal_get_realtime_usec \ - -Wl,--wrap,sd_journal_get_data -Wl,--wrap,sd_journal_restart_data \ - -Wl,--wrap,sd_journal_enumerate_data -Wl,--wrap,sd_journal_get_cutoff_realtime_usec \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_AddArrayToObject -Wl,--wrap,cJSON_AddStringToObject \ - -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_AddItemToArray -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,cJSON_PrintUnformatted -Wl,--wrap,cJSON_Delete") -endif() - -list(LENGTH logcollector_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET logcollector_names ${counter} logcollector_test_name) - list(GET logcollector_flags ${counter} logcollector_test_flags) - add_executable(${logcollector_test_name} ${logcollector_test_name}.c) - target_link_libraries( - ${logcollector_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - LOGCOLLECTOR_O - ${TEST_DEPS} - ) - - if(${TARGET} STREQUAL "winagent") - target_link_libraries(${logcollector_test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - - if(NOT logcollector_test_flags STREQUAL " ") - target_link_libraries( - ${logcollector_test_name} - ${logcollector_test_flags} - ) - endif() - add_test(NAME ${logcollector_test_name} COMMAND ${logcollector_test_name}) -endforeach() diff --git a/src/unit_tests/logcollector/json_data.h b/src/unit_tests/logcollector/json_data.h deleted file mode 100644 index b6c69b99ce1..00000000000 --- a/src/unit_tests/logcollector/json_data.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _JSON_DATA_H -#define _JSON_DATA_H - -//global full json -char *global_outjson = "{\"error\":0,\"remaining\":false,\"json_updated\":false,\"data\":{\"global\":{\"start\":\"2023-06-28 16:31:45\",\"end\":\"2023-06-28 18:57:47\",\"files\":[{\"location\":\"last -n 20\",\"events\":25,\"bytes\":20175,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-1234567-689.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":11,\"bytes\":925,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":5,\"bytes\":495,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-977.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-902.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-875.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-87.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-838.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-800.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-773.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-736.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-671.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-634.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-532.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-468.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-430.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-366.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-329.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-264.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-227.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-162.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-125.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-12.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-968.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-930.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-866.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-829.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-78.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-764.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-727.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-662.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-625.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-598.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-560.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-523.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-496.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-459.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-421.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-40.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-394.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-357.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-292.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-255.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-218.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-190.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-153.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-116.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-959.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-921.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-894.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-857.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-792.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-755.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-718.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-690.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-69.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-653.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-616.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-589.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-551.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-514.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-487.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-412.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-385.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-348.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-310.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-31.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-283.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-246.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-209.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-181.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-144.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-107.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-987.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-97.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-912.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-885.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-848.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-810.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-8.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-783.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-746.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-709.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-681.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-644.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-607.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-542.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-505.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-478.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-440.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-403.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-376.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-339.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-301.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-274.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-237.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-22.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-172.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-135.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-978.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-940.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-903.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-88.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-876.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-839.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-801.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-774.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-737.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-672.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-635.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-570.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-533.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-50.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-469.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-431.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-367.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-265.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-228.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-163.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-13.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-126.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-969.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-931.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-867.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-79.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-765.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-728.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-663.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-626.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-599.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-561.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-524.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-497.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-422.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-41.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-395.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-358.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-320.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-293.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-256.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-219.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-191.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-154.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-117.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-922.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-895.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-858.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-820.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-793.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-756.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-719.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-691.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-654.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-617.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-552.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-515.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-488.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-450.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-413.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-386.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-349.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-32.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-311.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-284.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-247.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-182.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-145.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-108.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-988.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-98.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-950.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-913.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-9.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-886.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-849.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-811.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-784.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-747.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-682.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-645.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-608.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-60.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-580.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-543.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-506.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-479.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-441.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-404.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-377.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-302.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-275.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-238.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-23.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-200.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-173.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-136.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-979.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-941.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-904.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-89.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-877.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-802.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-775.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-738.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-700.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-673.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-636.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-571.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-534.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-51.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-432.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-368.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-330.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-266.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-229.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-164.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-14.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-127.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-932.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-868.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-830.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-766.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-729.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-664.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-627.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-562.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-525.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-498.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-460.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-423.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-42.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-396.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-359.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-321.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-294.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-257.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-192.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-155.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-118.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-960.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-923.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-896.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-859.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-821.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-794.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-757.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-70.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-692.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-655.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-618.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-590.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-553.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-516.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-489.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-451.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-414.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-387.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-33.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-312.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-285.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-248.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-210.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-183.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-146.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-109.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"netstat listening ports\",\"events\":25,\"bytes\":7625,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-99.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-989.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-951.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-914.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-887.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-812.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-785.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-748.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-710.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-683.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-646.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-61.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-609.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-581.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-544.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-507.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-442.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-405.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-378.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-340.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-303.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-276.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-24.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-239.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-201.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-174.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-137.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-942.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-905.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-878.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-840.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-803.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-776.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-739.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-701.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-674.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-637.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-572.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-535.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-52.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-470.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-433.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-369.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-331.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-267.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-165.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-15.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-128.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-0.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-970.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-933.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-869.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-831.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-80.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-767.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-665.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-628.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-563.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-526.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-499.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-461.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-43.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-424.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-397.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-322.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-295.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-258.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-220.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-193.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-156.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-119.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-961.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-924.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-897.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-822.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-795.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-758.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-720.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-71.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-693.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-656.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-619.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-591.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-554.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-517.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-452.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-415.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-388.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-350.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-34.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-313.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-286.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-249.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-211.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-184.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-147.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-952.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-915.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-888.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-850.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-813.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-786.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-749.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-711.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-684.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-647.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-62.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-582.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-545.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-508.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-480.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-443.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-406.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-379.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-341.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-304.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-277.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-25.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-202.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-175.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-138.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-100.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-980.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-943.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-906.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-90.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-879.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-841.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-804.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-777.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-702.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-675.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-638.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-600.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-573.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-536.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-53.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-471.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-434.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-332.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-268.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-230.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-166.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-16.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-129.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-971.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-934.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-832.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-81.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-768.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-730.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-666.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-629.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-564.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-527.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-462.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-44.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-425.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-398.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-360.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-323.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-296.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-259.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-221.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-194.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-157.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"df -P\",\"events\":225,\"bytes\":20025,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-962.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-925.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-898.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-860.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-823.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-796.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-759.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-721.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-72.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-694.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-657.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-592.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-555.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-518.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-490.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-453.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-416.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-389.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-351.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-35.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-314.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-287.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-212.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-185.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-148.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-110.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-990.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-953.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-916.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-889.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-851.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-814.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-787.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-712.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-685.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-648.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-63.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-610.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-583.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-546.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-509.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-481.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-444.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-407.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-342.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-305.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-278.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-26.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-240.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-203.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-176.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-139.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-101.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-981.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-944.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-91.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-907.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-842.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-805.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-778.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-740.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-703.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-676.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-639.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-601.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-574.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-54.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-537.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-472.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-435.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-370.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-333.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-269.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-231.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-2.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-17.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-167.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-972.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-935.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-870.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-833.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-82.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-769.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-731.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-667.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-45.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-963.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-926.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-899.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-861.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-824.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-797.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-73.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-722.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-695.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-658.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-620.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-36.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-991.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-954.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-917.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-852.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-815.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-788.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-750.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-713.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-686.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-649.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-64.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-611.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-27.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-102.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-28 18:56:47\",\"end\":\"2023-06-28 18:57:47\",\"files\":[{\"location\":\"last -n 20\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-1234567-689.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-977.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-902.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-875.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-87.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-838.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-800.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-773.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-736.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-671.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-634.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-532.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-468.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-430.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-366.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-329.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-264.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-227.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-162.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-125.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-12.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-968.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-930.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-866.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-829.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-78.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-764.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-727.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-662.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-625.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-598.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-560.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-523.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-496.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-459.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-421.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-40.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-394.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-357.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-292.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-255.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-218.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-190.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-153.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-116.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-959.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-921.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-894.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-857.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-792.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-755.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-718.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-690.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-69.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-653.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-616.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-589.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-551.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-514.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-487.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-412.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-385.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-348.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-310.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-31.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-283.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-246.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-209.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-181.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-144.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-107.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-987.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-97.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-912.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-885.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-848.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-810.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-8.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-783.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-746.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-709.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-681.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-644.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-607.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-542.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-505.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-478.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-440.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-403.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-376.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-339.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-301.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-274.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-237.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-22.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-172.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-135.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-978.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-940.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-903.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-88.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-876.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-839.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-801.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-774.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-737.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-672.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-635.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-570.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-533.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-50.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-469.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-431.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-367.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-265.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-228.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-163.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-13.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-126.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-969.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-931.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-867.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-79.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-765.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-728.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-663.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-626.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-599.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-561.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-524.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-497.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-422.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-41.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-395.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-358.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-320.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-293.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-256.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-219.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-191.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-154.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-117.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-922.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-895.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-858.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-820.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-793.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-756.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-719.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-691.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-654.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-617.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-552.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-515.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-488.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-450.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-413.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-386.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-349.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-32.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-311.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-284.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-247.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-182.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-145.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-108.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-988.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-98.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-950.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-913.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-9.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-886.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-849.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-811.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-784.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-747.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-682.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-645.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-608.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-60.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-580.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-543.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-506.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-479.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-441.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-404.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-377.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-302.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-275.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-238.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-23.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-200.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-173.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-136.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-979.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-941.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-904.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-89.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-877.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-802.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-775.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-738.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-700.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-673.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-636.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-571.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-534.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-51.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-432.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-368.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-330.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-266.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-229.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-164.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-14.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-127.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-932.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-868.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-830.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-766.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-729.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-664.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-627.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-562.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-525.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-498.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-460.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-423.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-42.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-396.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-359.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-321.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-294.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-257.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-192.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-155.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-118.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-960.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-923.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-896.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-859.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-821.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-794.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-757.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-70.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-692.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-655.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-618.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-590.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-553.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-516.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-489.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-451.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-414.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-387.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-33.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-312.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-285.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-248.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-210.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-183.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-146.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-109.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"netstat listening ports\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-99.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-989.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-951.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-914.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-887.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-812.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-785.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-748.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-710.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-683.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-646.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-61.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-609.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-581.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-544.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-507.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-442.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-405.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-378.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-340.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-303.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-276.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-24.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-239.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-201.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-174.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-137.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-942.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-905.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-878.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-840.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-803.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-776.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-739.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-701.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-674.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-637.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-572.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-535.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-52.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-470.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-433.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-369.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-331.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-267.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-165.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-15.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-128.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-0.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-970.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-933.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-869.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-831.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-80.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-767.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-665.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-628.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-563.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-526.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-499.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-461.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-43.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-424.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-397.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-322.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-295.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-258.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-220.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-193.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-156.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-119.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-961.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-924.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-897.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-822.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-795.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-758.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-720.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-71.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-693.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-656.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-619.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-591.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-554.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-517.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-452.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-415.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-388.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-350.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-34.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-313.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-286.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-249.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-211.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-184.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-147.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-952.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-915.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-888.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-850.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-813.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-786.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-749.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-711.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-684.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-647.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-62.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-582.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-545.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-508.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-480.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-443.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-406.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-379.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-341.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-304.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-277.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-25.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-202.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-175.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-138.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-100.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-980.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-943.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-906.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-90.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-879.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-841.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-804.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-777.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-702.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-675.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-638.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-600.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-573.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-536.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-53.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-471.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-434.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-332.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-268.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-230.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-166.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-16.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-129.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-971.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-934.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-832.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-81.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-768.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-730.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-666.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-629.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-564.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-527.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-462.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-44.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-425.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-398.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-360.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-323.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-296.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-259.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-221.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-194.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-157.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"df -P\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-962.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-925.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-898.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-860.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-823.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-796.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-759.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-721.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-72.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-694.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-657.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-592.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-555.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-518.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-490.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-453.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-416.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-389.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-351.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-35.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-314.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-287.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-212.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-185.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-148.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-110.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-990.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-953.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-916.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-889.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-851.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-814.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-787.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-712.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-685.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-648.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-63.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-610.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-583.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-546.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-509.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-481.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-444.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-407.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-342.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-305.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-278.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-26.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-240.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-203.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-176.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-139.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-101.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-981.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-944.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-91.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-907.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-842.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-805.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-778.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-740.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-703.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-676.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-639.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-601.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-574.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-54.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-537.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-472.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-435.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-370.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-333.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-269.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-231.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-2.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-17.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-167.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-972.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-935.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-870.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-833.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-82.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-769.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-731.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-667.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-45.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-963.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-926.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-899.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-861.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-824.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-797.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-73.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-722.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-695.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-658.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-620.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-36.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-991.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-954.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-917.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-852.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-815.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-788.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-750.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-713.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-686.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-649.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-64.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-611.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-27.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-102.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -//reponse first block -char *outjson_block1 = "{\"error\":0,\"remaining\":true ,\"json_updated\":false,\"data\":{\"global\":{\"start\":\"2023-06-28 16:31:45\",\"end\":\"2023-06-28 18:57:47\",\"files\":[{\"location\":\"last -n 20\",\"events\":25,\"bytes\":20175,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-1234567-689.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":11,\"bytes\":925,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":5,\"bytes\":495,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-977.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-902.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-875.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-87.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-838.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-800.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-773.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-736.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-671.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-634.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-532.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-468.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-430.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-366.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-329.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-264.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-227.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-162.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-125.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-12.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-968.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-930.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-866.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-829.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-78.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-764.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-727.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-662.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-625.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-598.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-560.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-523.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-496.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-459.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-421.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-40.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-394.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-357.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-292.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-255.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-218.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-190.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-153.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-116.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-959.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-921.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-894.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-857.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-792.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-755.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-718.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-690.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-69.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-653.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-616.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-589.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-551.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-514.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-487.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-412.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-385.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-348.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-310.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-31.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-283.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-246.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-209.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-181.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-144.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-107.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-987.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-97.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-912.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-885.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-848.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-810.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-8.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-783.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-746.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-709.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-681.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-644.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-607.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-542.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-505.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-478.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-440.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-403.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-376.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-339.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-301.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-274.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-237.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-22.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-172.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-135.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-978.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-940.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-903.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-88.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-876.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-839.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-801.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-774.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-737.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-672.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-635.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-570.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-533.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-50.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-469.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-431.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-367.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-265.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-228.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-163.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-13.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-126.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-969.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-931.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-867.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-79.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-765.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-728.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-663.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-626.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-599.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-561.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-524.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-497.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-422.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-41.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-395.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-358.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-320.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-293.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-256.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-219.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-191.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-154.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-117.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-922.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-895.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-858.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-820.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-793.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-756.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-719.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-691.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-654.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-617.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-552.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-515.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-488.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-450.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-413.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-386.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-349.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-32.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-311.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-284.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-247.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-182.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-145.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-108.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-988.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-98.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-950.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-913.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-9.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-886.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-849.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-811.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-784.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-747.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-682.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-645.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-608.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-60.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-580.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-543.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-506.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-479.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-441.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-404.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-377.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-302.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-275.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-238.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-23.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-200.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-173.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-136.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-979.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-941.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-904.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-89.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-877.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-802.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-775.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-738.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-700.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-673.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-636.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-571.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-534.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-51.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-432.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-368.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-330.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-266.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-229.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-164.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-14.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-127.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-932.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-868.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-830.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-766.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-729.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-664.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-627.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-562.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-525.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-498.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-460.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-423.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-42.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-396.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-359.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-321.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-294.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-257.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-192.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-155.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-118.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-960.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-923.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-896.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-859.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-821.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -//reponse second block -char *outjson_block2 = "{\"error\":0,\"remaining\":true ,\"json_updated\":false,\"data\":{\"global\":{\"start\":\"2023-06-28 16:31:45\",\"end\":\"2023-06-28 18:57:47\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-794.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-757.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-70.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-692.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-655.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-618.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-590.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-553.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-516.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-489.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-451.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-414.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-387.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-33.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-312.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-285.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-248.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-210.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-183.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-146.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-109.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"netstat listening ports\",\"events\":25,\"bytes\":7625,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-99.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-989.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-951.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-914.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-887.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-812.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-785.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-748.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-710.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-683.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-646.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-61.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-609.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-581.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-544.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-507.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-442.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-405.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-378.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-340.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-303.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-276.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-24.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-239.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-201.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-174.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-137.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-942.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-905.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-878.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-840.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-803.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-776.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-739.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-701.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-674.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-637.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-572.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-535.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-52.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-470.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-433.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-369.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-331.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-267.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-165.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-15.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-128.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-0.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-970.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-933.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-869.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-831.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-80.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-767.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-665.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-628.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-563.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-526.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-499.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-461.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-43.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-424.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-397.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-322.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-295.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-258.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-220.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-193.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-156.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-119.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-961.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-924.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-897.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-822.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-795.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-758.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-720.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-71.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-693.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-656.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-619.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-591.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-554.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-517.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-452.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-415.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-388.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-350.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-34.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-313.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-286.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-249.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-211.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-184.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-147.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-952.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-915.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-888.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-850.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-813.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-786.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-749.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-711.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-684.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-647.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-62.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-582.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-545.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-508.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-480.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-443.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-406.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-379.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-341.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-304.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-277.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-25.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-202.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-175.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-138.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-100.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-980.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-943.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-906.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-90.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-879.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-841.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-804.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-777.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-702.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-675.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-638.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-600.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-573.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-536.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-53.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-471.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-434.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-332.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-268.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-230.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-166.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-16.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-129.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-971.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-934.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-832.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-81.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-768.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-730.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-666.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-629.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-564.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-527.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-462.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-44.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-425.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-398.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-360.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-323.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-296.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-259.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-221.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-194.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-157.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"df -P\",\"events\":225,\"bytes\":20025,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-962.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-925.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-898.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-860.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-823.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-796.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-759.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-721.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-72.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-694.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-657.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-592.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-555.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-518.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-490.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-453.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-416.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-389.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-351.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-35.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-314.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-287.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-212.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-185.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-148.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-110.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-990.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-953.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-916.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-889.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-851.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-814.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-787.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-712.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-685.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-648.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-63.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-610.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-583.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-546.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-509.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-481.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-444.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-407.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-342.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-305.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-278.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-26.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-240.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-203.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-176.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-139.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-101.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-981.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-944.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-91.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-907.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-842.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-805.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-778.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-740.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-703.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-676.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-639.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-601.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-574.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-54.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-537.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-472.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-435.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-370.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-333.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-269.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-231.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-2.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-17.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-167.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-972.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-935.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-870.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-833.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-82.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-769.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-731.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-667.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-45.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-963.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-926.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-899.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-861.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-824.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-797.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-73.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-722.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-695.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-658.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-620.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-36.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-991.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-954.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-917.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-852.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-815.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-788.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-750.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-713.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-686.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-649.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-64.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-611.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-27.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-102.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-28 18:56:47\",\"end\":\"2023-06-28 18:57:47\",\"files\":[{\"location\":\"last -n 20\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-1234567-689.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -//reponse third block -char *outjson_block3 = "{\"error\":0,\"remaining\":true ,\"json_updated\":false,\"data\":{\"interval\":{\"start\":\"2023-06-28 18:56:47\",\"end\":\"2023-06-28 18:57:47\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-977.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-902.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-875.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-87.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-838.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-800.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-773.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-736.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-671.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-634.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-532.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-468.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-430.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-366.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-329.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-264.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-227.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-162.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-125.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-12.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-968.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-930.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-866.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-829.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-78.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-764.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-727.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-662.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-625.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-598.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-560.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-523.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-496.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-459.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-421.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-40.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-394.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-357.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-292.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-255.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-218.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-190.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-153.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-116.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-959.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-921.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-894.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-857.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-792.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-755.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-718.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-690.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-69.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-653.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-616.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-589.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-551.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-514.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-487.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-412.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-385.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-348.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-310.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-31.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-283.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-246.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-209.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-181.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-144.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-107.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-987.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-97.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-912.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-885.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-848.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-810.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-8.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-783.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-746.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-709.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-681.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-644.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-607.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-542.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-505.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-478.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-440.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-403.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-376.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-339.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-301.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-274.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-237.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-22.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-172.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-135.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-978.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-940.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-903.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-88.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-876.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-839.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-801.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-774.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-737.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-672.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-635.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-570.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-533.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-50.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-469.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-431.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-367.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-265.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-228.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-163.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-13.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-126.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-969.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-931.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-867.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-79.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-765.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-728.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-663.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-626.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-599.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-561.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-524.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-497.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-422.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-41.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-395.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-358.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-320.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-293.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-256.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-219.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-191.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-154.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-117.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-922.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-895.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-858.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-820.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-793.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-756.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-719.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-691.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-654.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-617.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-552.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-515.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-488.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-450.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-413.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-386.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-349.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-32.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-311.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-284.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-247.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-182.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-145.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-108.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-988.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-98.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-950.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-913.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-9.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-886.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-849.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-811.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-784.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-747.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-682.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-645.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-608.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-60.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-580.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-543.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-506.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-479.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-441.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-404.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-377.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-302.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-275.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-238.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-23.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-200.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-173.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-136.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-979.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-941.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-904.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-89.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-877.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-802.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-775.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-738.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-700.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-673.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-636.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-571.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-534.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-51.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-432.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-368.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-330.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-266.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-229.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-164.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-14.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-127.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-932.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-868.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-830.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-766.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-729.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-664.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-627.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-562.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-525.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-498.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-460.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-423.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-42.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-396.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-359.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-321.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-294.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-257.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-192.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-155.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-118.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-960.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-923.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-896.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-859.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-821.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-794.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-757.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-70.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-692.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-655.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-618.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-590.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-553.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-516.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-489.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-451.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-414.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-387.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-33.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-312.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-285.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-248.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-210.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-183.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-146.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-109.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"netstat listening ports\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-99.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-989.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-951.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-914.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-887.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-812.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-785.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-748.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-710.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-683.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-646.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-61.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-609.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-581.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-544.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-507.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-442.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-405.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-378.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-340.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-303.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-276.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-24.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-239.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-201.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-174.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-137.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-942.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-905.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-878.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-840.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-803.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-776.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-739.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-701.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-674.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-637.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-572.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-535.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-52.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-470.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-433.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-369.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-331.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-267.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-165.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-15.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-128.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-0.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-970.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-933.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-869.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-831.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-80.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-767.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-665.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-628.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-563.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-526.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-499.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-461.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-43.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-424.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-397.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-322.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-295.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-258.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-220.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-193.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-156.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-119.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-961.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-924.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-897.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-822.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-795.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-758.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-720.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-71.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-693.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-656.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-619.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-591.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-554.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-517.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-452.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-415.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-388.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-350.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-34.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-313.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-286.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-249.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-211.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-184.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-147.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-952.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-915.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-888.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-850.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-813.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-786.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-749.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-711.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-684.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-647.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-62.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-582.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-545.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-508.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-480.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-443.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-406.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-379.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-341.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-304.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-277.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-25.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-202.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-175.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-138.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-100.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-980.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-943.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-906.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-90.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-879.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-841.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-804.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-777.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-702.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-675.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-638.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-600.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-573.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-536.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-53.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-471.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-434.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-332.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-268.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-230.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-166.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-16.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-129.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-971.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-934.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-832.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-81.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-768.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-730.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-666.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-629.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-564.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-527.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-462.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-44.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-425.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-398.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-360.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-323.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-296.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-259.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-221.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-194.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-157.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"df -P\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-962.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-925.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-898.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-860.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-823.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-796.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-759.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-721.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-72.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-694.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-657.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-592.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-555.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-518.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-490.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-453.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-416.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-389.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-351.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-35.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-314.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-287.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-212.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-185.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-148.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-110.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-990.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-953.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-916.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-889.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-851.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-814.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-787.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-712.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-685.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-648.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-63.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-610.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-583.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-546.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-509.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-481.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-444.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-407.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-342.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-305.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-278.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-26.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-240.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-203.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-176.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-139.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-101.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-981.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-944.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-91.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-907.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-842.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-805.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-778.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-740.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-703.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-676.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-639.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-601.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-574.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-54.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-537.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-472.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-435.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-370.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-333.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-269.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-231.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-2.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-17.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-167.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-972.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-935.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-870.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-833.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-82.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-769.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-731.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-667.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-45.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-963.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-926.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-899.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-861.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-824.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-797.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-73.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-722.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-695.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-658.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-620.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-36.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-991.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-954.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-917.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-852.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-815.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-788.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-750.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-713.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-686.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -//reponse fourth block -char *outjson_block4 = "{\"error\":0,\"remaining\":false,\"json_updated\":false,\"data\":{\"interval\":{\"start\":\"2023-06-28 18:56:47\",\"end\":\"2023-06-28 18:57:47\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-649.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-64.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-611.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-27.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-102.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -//json for case 1 -char * outjson1 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.loGG\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.loGG\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.logJULIAN1\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log1\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.logJULIAN2\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log2\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.logJULIAN3\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log3\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.logJULIAN4\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log4\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-982.logJULIAN5\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log5\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -//response block case 1 -char *outjson_block_case_1 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -char * outjson2 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - -//response block case 2 -char *outjson_block_case_2 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - -//json for case 5 -char * outjson5 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.loGG\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.loGG\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -char *outjson_block_case_5 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-171.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1365.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - - -char *outjson_block_case_5_1 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-134.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.loGG\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.loGG\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - -char * outjson6 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - - -char *outjson_block_case_6 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-908.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-880.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-843.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-806.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-779.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-741.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-704.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-677.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-602.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-55.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-3.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-18.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1565.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1528.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1463.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1426.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1399.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1361.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1324.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1297.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1222.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1195.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1158.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1120.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1093.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1056.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1019.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"last -n 20\",\"events\":1,\"bytes\":66,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-973.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-936.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-871.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-834.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-83.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-732.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-668.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-630.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-46.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1593.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1556.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1519.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1491.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1454.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1417.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1352.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1315.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1288.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1250.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1213.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1186.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1149.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1111.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1084.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1047.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/dpkg.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-964.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-927.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-862.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-825.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-798.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-760.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-74.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-723.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-696.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-659.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-621.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-37.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1584.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1547.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1482.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1445.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1408.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1380.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1343.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1306.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1279.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1241.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1204.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1177.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1102.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1075.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1038.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1000.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-992.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-955.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-918.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-890.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-853.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-816.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-789.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-751.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-714.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-687.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-65.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-612.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-28.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1575.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1538.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1500.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1473.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1436.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1371.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1334.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1232.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1168.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1130.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1066.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1029.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-983.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-946.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-93.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-909.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-881.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-844.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-807.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-742.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-705.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-678.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-640.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-603.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-56.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-4.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-19.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1566.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1529.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1464.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1427.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1362.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1325.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1298.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1260.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1223.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1196.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1159.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1121.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1094.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1057.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-974.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-937.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-872.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-84.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-835.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-770.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-733.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-669.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-631.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-47.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1594.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1557.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1492.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1455.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1418.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1390.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1353.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1316.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1289.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1251.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1214.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1187.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1112.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1085.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1048.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1010.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-965.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-928.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-863.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-826.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-799.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-761.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-75.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-724.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-697.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-622.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-38.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1585.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1548.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1510.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1483.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1446.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1409.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1381.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1344.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1307.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1242.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1205.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1178.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1140.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1103.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1076.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1039.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1001.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-993.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-956.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-919.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-891.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-854.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-817.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-752.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-715.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-688.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-66.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-650.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-613.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-29.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1576.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1539.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1501.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1474.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1437.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1372.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1335.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1270.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1233.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1169.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1131.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1067.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/ossec/logs/active-responses.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-984.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-947.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-94.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-882.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-845.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-808.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-780.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-743.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-706.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-679.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-641.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-604.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-57.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-5.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1567.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1465.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1428.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1363.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1326.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1299.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1261.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1224.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1197.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1122.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1095.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1058.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1020.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-975.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-938.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-900.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-873.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-85.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-836.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-771.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-734.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-632.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-48.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1595.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1558.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1520.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1493.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1456.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1419.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1391.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1354.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1317.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1252.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1215.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1188.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1150.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1113.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1086.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1049.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1011.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-10.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-966.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-929.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-864.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-827.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-762.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-76.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-725.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-698.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-660.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-623.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-39.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1586.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1549.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1511.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1484.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1447.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1382.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1345.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1308.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1280.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1243.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1206.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1179.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1141.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1104.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1077.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1002.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/syslog\",\"events\":4,\"bytes\":245,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/var/log/auth.log\",\"events\":1,\"bytes\":87,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-994.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-957.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-892.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-855.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-818.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-790.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-753.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-716.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-689.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-67.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-651.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-614.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1577.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1502.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1475.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1438.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1400.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1373.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1336.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1271.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1234.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1132.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1068.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1030.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-985.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-95.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-948.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-910.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-883.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-846.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-809.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-781.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-744.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-707.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-642.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-605.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-6.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-58.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-20.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1568.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1530.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1466.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1429.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1364.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1327.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1262.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1225.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1198.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1160.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1123.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1096.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1059.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1021.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-976.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-939.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-901.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-874.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-86.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-837.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-772.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-735.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-670.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-633.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-569.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-531.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-49.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-467.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-365.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-328.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-263.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-226.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-199.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-161.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1596.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1559.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1521.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1494.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1457.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1392.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1355.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1318.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1290.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1253.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-124.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1216.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1189.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1151.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1114.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-11.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1087.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1012.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-967.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-865.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-828.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-77.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-763.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-726.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-699.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-661.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-624.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-597.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-522.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-495.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-458.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-420.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-393.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-356.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-319.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-291.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-254.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-217.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1587.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-152.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1512.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1485.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1448.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1410.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1383.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1346.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1309.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1281.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1244.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1207.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-115.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1142.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1105.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1078.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1040.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1003.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/var/log/kern.log\",\"events\":0,\"bytes\":0,\"targets\":[{\"name\":\"agent\",\"drops\":0}]},{\"location\":\"/root/logs/my-log-for-any-thing-example-995.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-958.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-920.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-893.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-856.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-819.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-791.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-754.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-717.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-68.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-652.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-615.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-588.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-550.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-513.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-486.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-449.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-411.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-384.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-347.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-30.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-282.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-245.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-208.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-180.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1578.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1540.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1503.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1476.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1439.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-143.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1401.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1374.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1337.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1272.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1235.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1170.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1133.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-106.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1031.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-986.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-96.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-949.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-911.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-884.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-847.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-782.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-745.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-708.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-7.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-680.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-643.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-606.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-59.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-579.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-541.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-504.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-477.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-402.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-375.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-338.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-300.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-273.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-236.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-21.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - - -char *outjson_block_case_6_1 = "{\"error\":0,\"data\":{\"global\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]}}}"; - - -char *outjson_no_global = "{\"error\":0,\"data\":{\"glob\":{\"start\":\"2023-06-01 19:20:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-982.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-945.log\",\"events\":0,\"bytes\":0,\"targets\":[]},{\"location\":\"/root/logs/my-log-for-any-thing-example-92.log\",\"events\":0,\"bytes\":0,\"targets\":[]}]},\"interval\":{\"start\":\"2023-06-01 19:21:35\",\"end\":\"2023-06-01 19:22:35\",\"files\":[{\"location\":\"/root/logs/my-log-for-any-thing-example-1069.log\",\"events\":0,\"bytes\":0,\"targets\":[]}"; - -#endif /*_JSON_DATA_H*/ diff --git a/src/unit_tests/logcollector/test_journal_log.c b/src/unit_tests/logcollector/test_journal_log.c deleted file mode 100644 index ff19679358d..00000000000 --- a/src/unit_tests/logcollector/test_journal_log.c +++ /dev/null @@ -1,4562 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../logcollector/journal_log.h" - -#include "../wrappers/posix/stat_wrappers.h" -#include "../wrappers/common.h" -#include "../wrappers/externals/pcre2/pcre2_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/linux/dlfcn_wrappers.h" - -#define _XOPEN_SOURCE - -bool is_owned_by_root(const char * library_path); -bool load_and_validate_function(void * handle, const char * name, void ** func); -uint64_t w_get_epoch_time(); -char * w_timestamp_to_string(uint64_t timestamp); -char * w_timestamp_to_journalctl_since(uint64_t timestamp); -char * find_library_path(const char * library_name); -w_journal_lib_t * w_journal_lib_init(); -cJSON * entry_as_json(w_journal_context_t * ctx); -char * get_field_ptr(w_journal_context_t * ctx, const char * field); -char * create_plain_syslog(const char * timestamp, - const char * hostname, - const char * syslog_identifier, - const char * pid, - const char * message); -char * entry_as_syslog(w_journal_context_t * ctx); -w_journal_entry_t * w_journal_entry_dump(w_journal_context_t * ctx, w_journal_entry_dump_type_t type); - -// Mocks - -/* Mock of the sd_journal_* functions */ -int __wrap_sd_journal_open(sd_journal ** journal, int flags) { return mock_type(int); } - -void __wrap_sd_journal_close(sd_journal * j) { function_called(); } - -int __wrap_sd_journal_previous(sd_journal * j) { return mock_type(int); } - -int __wrap_sd_journal_next(sd_journal * j) { return mock_type(int); } - -int __wrap_sd_journal_seek_tail(sd_journal * j) { return mock_type(int); } - -int __wrap_sd_journal_seek_realtime_usec(sd_journal * j, uint64_t usec) { return mock_type(int); } - -// The expected value is returned in the usec parameter -// If the expected value positive, the function returns 0 and the expected value is stored in usec -int __wrap_sd_journal_get_realtime_usec(sd_journal * j, uint64_t * usec) { - int64_t ret = mock_type(int64_t); - if (ret >= 0) { - *usec = (uint64_t) ret; - return 0; - } - return ret; -} - -int __wrap_sd_journal_get_data(sd_journal * j, const char * field, const void ** data, size_t * length) { - check_expected(field); - int retval = mock_type(int); - // If function returns a positive value, return a simulated data - if (retval >= 0) { - *data = mock_ptr_type(char *); - *length = strlen(*data); - } - return retval; -} - -int __wrap_sd_journal_restart_data(sd_journal * j) { return mock_type(int); } - -int __wrap_sd_journal_enumerate_data(sd_journal * j, const void ** data, size_t * length) { - - int retval = mock_type(int); - if (retval > 0) { - *data = mock_ptr_type(char *); - *length = strlen(*data); - } - return retval; -} - -int __wrap_sd_journal_get_cutoff_realtime_usec(sd_journal * j, uint64_t * from, uint64_t * to) { - int64_t ret = mock_type(int64_t); - if (ret >= 0) { - *from = (uint64_t) ret; - return 0; - } - return ret; -} - -extern unsigned int __real_gmtime_r(const time_t * t, struct tm * tm); -unsigned int __wrap_gmtime_r(__attribute__((__unused__)) const time_t * t, __attribute__((__unused__)) struct tm * tm) { - unsigned int mock = mock_type(unsigned int); - if (mock == 0) { - return mock; - } else { - return __real_gmtime_r(t, tm); - } -} - -int __wrap_isDebug() { return mock(); } - -/* setup/teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - w_test_pcre2_wrappers(false); - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - w_test_pcre2_wrappers(true); - return 0; -} - -// Test is_owned_by_root - -// Test is_owned_by_root with root owned -void test_is_owned_by_root_root_owned(void ** state) { - (void) state; - - const char * library_path = "existent_file_root"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_value(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - bool result = is_owned_by_root(library_path); - - // Assert - assert_true(result); -} - -// Test is_owned_by_root with not root owned -void test_is_owned_by_root_not_root_owned(void ** state) { - (void) state; - - const char * library_path = "existent_file_no_root"; - - struct stat mock_stat; - mock_stat.st_uid = 1000; - - expect_value(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - bool result = is_owned_by_root(library_path); - - // Assert - assert_false(result); -} - -// Test is_owned_by_root with stat fails -void test_is_owned_by_root_stat_fails(void ** state) { - (void) state; - - const char * library_path = "nonexistent_file"; - - struct stat mock_stat; - mock_stat.st_uid = 1000; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, -1); - - bool result = is_owned_by_root(library_path); - - // Assert - assert_false(result); -} - -// Test load_and_validate_function - -// Test load_and_validate_function success -static void test_load_and_validate_function_success(void ** state) { - // Arrange - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - const char * function_name = "valid_function"; - void * function_pointer; - - expect_any(__wrap_dlsym, handle); - expect_string(__wrap_dlsym, symbol, "valid_function"); - will_return(__wrap_dlsym, mock_function); - - // Act - bool result = load_and_validate_function(handle, function_name, &function_pointer); - - // Assert - assert_true(result); - assert_non_null(function_pointer); -} - -// Test load_and_validate_function failure -static void test_load_and_validate_function_failure(void ** state) { - // Arrange - void * handle = NULL; // Simulate invalid handle - void * mock_function = NULL; - const char * function_name = "invalid_function"; - void * function_pointer = (void *) 1; - - expect_any(__wrap_dlsym, handle); - expect_string(__wrap_dlsym, symbol, "invalid_function"); - will_return(__wrap_dlsym, mock_function); - - will_return(__wrap_dlerror, "ERROR"); - - expect_string(__wrap__mwarn, formatted_msg, "(8008): Failed to load 'invalid_function': 'ERROR'."); - - // Act - bool result = load_and_validate_function(handle, function_name, &function_pointer); - - // Assert - assert_false(result); - assert_null(function_pointer); -} - -// Test w_get_epoch_time - -static void test_w_get_epoch_time(void ** state) { - // Arrange - will_return(__wrap_gettimeofday, 0); - - // Act - uint64_t result = w_get_epoch_time(); - - // Cant assert the result because it is a time value and the wrapper is not set in the test - -} - -// Test w_timestamp_to_string - -static void test_w_timestamp_to_string(void ** state) { - // Arrange - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds - will_return(__wrap_gmtime_r, 1); - - // Act - char * result = w_timestamp_to_string(timestamp); - - // Assert - free(result); -} - -// Test w_timestamp_to_journalctl_since - -static void test_w_timestamp_to_journalctl_since_success(void ** state) { - // Arrange - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - - will_return(__wrap_gmtime_r, 1618849174000000); - - // Act - char * result = w_timestamp_to_journalctl_since(timestamp); - - // Assert - assert_non_null(result); - - // Verify the result is the expected format - assert_int_equal(strlen(result), strlen("1900-01-00 00:00:00")); - assert_string_equal(result, "2021-04-19 16:19:34"); - free(result); -} - -static void test_w_timestamp_to_journalctl_since_failure(void ** state) { - // Arrange - uint64_t timestamp = 0; // Timestamp que provocará el error - - will_return(__wrap_gmtime_r, 0); - - // Act - char * result = w_timestamp_to_journalctl_since(timestamp); - - // Assert - assert_null(result); -} - -// Test find_library_path - -static void test_find_library_path_success(void ** state) { - // Arrange - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /path/to/libtest.so\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // Act - char * result = find_library_path("libtest.so"); - - // Assert - assert_non_null(result); - assert_string_equal(result, "/path/to/libtest.so"); - - // Clean - free(result); -} - -static void test_find_library_path_failure(void ** state) { - // Arrange - - // Set expectations for fopen - const char * library_name = "libtest.so"; - const char * expected_mode = "r"; - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Setting the return value for fopen - FILE * maps_file = NULL; // Simulate fopen error - will_return(__wrap_fopen, maps_file); - - // Act - char * result = find_library_path(library_name); - - // Assert - assert_null(result); - - // Clean - free(result); -} - -#define W_LIB_SYSTEMD "libsystemd.so.0" -#define RTLD_LAZY 1 - -// Test w_journal_lib_init - -// Define a test case for the scenario where dlopen fails -static void test_w_journal_lib_init_dlopen_fail(void ** state) { - // Arrange - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, NULL); - - will_return(__wrap_dlerror, "Library load failed"); - - expect_string(__wrap__mwarn, formatted_msg, "(8008): Failed to load 'libsystemd.so.0': 'Library load failed'."); - - // Act - w_journal_lib_t * result = w_journal_lib_init(); - - // Assert - assert_null(result); -} - -// Define a test case for the scenario where find_library_path fails -static void test_w_journal_lib_init_find_library_path_fail(void ** state) { - // Arrange - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_failure - // Set expectations for fopen - const char * library_name = "libtest.so"; - const char * expected_mode = "r"; - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Setting the return value for fopen - FILE * maps_file = NULL; // Simulate fopen error - will_return(__wrap_fopen, maps_file); - - // expect_any(__wrap_mwarn, id); - expect_string(__wrap__mwarn, formatted_msg, "(8009): The library 'libsystemd.so.0' is not owned by the root user."); - - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - - // Act - w_journal_lib_t * result = w_journal_lib_init(); - - // Assert - assert_null(result); -} - -// Define a test case for the scenario where is_owned_by_root fails -static void test_w_journal_lib_init_is_owned_by_root_fail(void ** state) { - // Arrange - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_stat_fails - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 1000; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, -1); - - // expect_any(__wrap_mwarn, id); - expect_string(__wrap__mwarn, formatted_msg, "(8009): The library 'libsystemd.so.0' is not owned by the root user."); - - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - - // Act - w_journal_lib_t * result = w_journal_lib_init(); - - // Assert - assert_null(result); -} - -// Define a test case for the scenario where load_and_validate_function fails -static void test_w_journal_lib_init_load_and_validate_function_fail(void ** state) { - // Arrange - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - // test_load_and_validate_function_failure - void * handle = NULL; // Simulate invalid handle - void * mock_function = NULL; - const char * function_name = "sd_journal_open"; - void * function_pointer = (void *) 1; - - expect_any(__wrap_dlsym, handle); - expect_string(__wrap_dlsym, symbol, function_name); - will_return(__wrap_dlsym, mock_function); - - will_return(__wrap_dlerror, "ERROR"); - - expect_string(__wrap__mwarn, formatted_msg, "(8008): Failed to load 'sd_journal_open': 'ERROR'."); - - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); - - // Act - w_journal_lib_t * result = w_journal_lib_init(); - - // Assert - assert_null(result); -} - -// Define a test case for the scenario where everything succeeds - -// Auxiliary function for setting dlsym wrap expectations -static void setup_dlsym_expectations(const char * symbol) { - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0x1; - - if (strcmp(symbol, "sd_journal_open") == 0) { - mock_function = (void *) __wrap_sd_journal_open; - } else if (strcmp(symbol, "sd_journal_close") == 0) { - mock_function = (void *) __wrap_sd_journal_close; - } else if (strcmp(symbol, "sd_journal_previous") == 0) { - mock_function = (void *) __wrap_sd_journal_previous; - } else if (strcmp(symbol, "sd_journal_next") == 0) { - mock_function = (void *) __wrap_sd_journal_next; - } else if (strcmp(symbol, "sd_journal_seek_tail") == 0) { - mock_function = (void *) __wrap_sd_journal_seek_tail; - } else if (strcmp(symbol, "sd_journal_seek_realtime_usec") == 0) { - mock_function = (void *) __wrap_sd_journal_seek_realtime_usec; - } else if (strcmp(symbol, "sd_journal_get_realtime_usec") == 0) { - mock_function = (void *) __wrap_sd_journal_get_realtime_usec; - } else if (strcmp(symbol, "sd_journal_get_data") == 0) { - mock_function = (void *) __wrap_sd_journal_get_data; - } else if (strcmp(symbol, "sd_journal_restart_data") == 0) { - mock_function = (void *) __wrap_sd_journal_restart_data; - } else if (strcmp(symbol, "sd_journal_enumerate_data") == 0) { - mock_function = (void *) __wrap_sd_journal_enumerate_data; - } else if (strcmp(symbol, "sd_journal_get_cutoff_realtime_usec") == 0) { - mock_function = (void *) __wrap_sd_journal_get_cutoff_realtime_usec; - } else { - // Invalid symbol - assert_true(false); - } - - expect_any(__wrap_dlsym, handle); - expect_string(__wrap_dlsym, symbol, symbol); - will_return(__wrap_dlsym, mock_function); -} - -static void test_w_journal_lib_init_success(void ** state) { - // Arrange - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - // Act - w_journal_lib_t * result = w_journal_lib_init(); - - // Assert - assert_non_null(result); - free(result); -} - -// Test w_journal_context_create - -// Test case for a successful context creation -static void test_w_journal_context_create_success(void ** state) { - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expect to call w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - // Open the journal - will_return(__wrap_sd_journal_open, 0); - - // Call the function under test - int ret = w_journal_context_create(&ctx); - - // Check the result - assert_int_equal(ret, 0); // Success - assert_non_null(ctx); // ctx non null - - // Clear dynamically allocated memory - os_free(ctx->journal); - os_free(ctx->lib); - os_free(ctx); -} - -// Test case for a failure due to NULL context pointer -static void test_w_journal_context_create_null_pointer(void ** state) { - // Call the function with a NULL context pointer - int ret = w_journal_context_create(NULL); - - // Check the result - assert_int_equal(ret, -1); -} - -// Test case for a failure in library initialization -static void test_w_journal_context_create_lib_init_fail(void ** state) { - // Allocate memory for the context - w_journal_context_t * ctx = NULL; - - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, NULL); - - will_return(__wrap_dlerror, "Library load failed"); - - expect_string(__wrap__mwarn, formatted_msg, "(8008): Failed to load 'libsystemd.so.0': 'Library load failed'."); - - // Call the function under test - int ret = w_journal_context_create(&ctx); - - // Check the result - assert_int_equal(ret, -1); - assert_null(ctx); -} - -// Test case for a failure in journal opening -static void test_w_journal_context_create_journal_open_fail(void ** state) { - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, -1); // Fail w_journal_lib_open - expect_string(__wrap__mwarn, formatted_msg, "(8010): Failed open journal log: 'Operation not permitted'."); - - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - - // Call the function under test - int ret = w_journal_context_create(&ctx); - - // Check the result - assert_int_equal(ret, -1); - assert_null(ctx); -} - -// Test w_journal_context_free - -// Test case for freeing a NULL context -static void test_w_journal_context_free_null(void ** state) { - w_journal_context_t * ctx = NULL; - w_journal_context_free(ctx); // Should not cause any issues - - // Assert - assert_null(ctx); -} - -// Test case for freeing a valid context -static void test_w_journal_context_free_valid(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - - // Perform the function under test - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - - // No need to check the memory deallocation of ctx since it's freed -} - -// Test w_journal_context_update_timestamp - -// Test for w_journal_context_update_timestamp succeeds -static void test_w_journal_context_update_timestamp_success(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - w_journal_context_update_timestamp(ctx); - - // Verify that the timestamp has been updated correctly. - assert_int_equal(ctx->timestamp, 123456); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_update_timestamp with null ctx -static void test_w_journal_context_update_timestamp_ctx_null(void ** state) { - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Perform the function under test - w_journal_context_update_timestamp(ctx); -} - -// Test for w_journal_context_update_timestamp with error when getting the timestamp -static void test_w_journal_context_update_timestamp_fail(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_get_realtime_usec, -EACCES); // Fail to get the timestamp value and return an error - will_return(__wrap_gettimeofday, NULL); - expect_string(__wrap__mwarn, - formatted_msg, - "(8011): Failed to read timestamp from journal log: 'Permission denied'. Using current time."); - w_journal_context_update_timestamp(ctx); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test w_journal_context_seek_most_recent - -// Test for w_journal_context_seek_most_recent update timestamp -static void test_w_journal_context_seek_most_recent_update_tamestamp(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_seek_tail, 0); // Mocked return value - will_return(__wrap_sd_journal_previous, 1); // Mocked return value - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - int ret = w_journal_context_seek_most_recent(ctx); - - // Check the result - assert_int_equal(ret, 1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_most_recent with error when seeking tail -static void test_w_journal_context_seek_most_recent_seek_tail_fail(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_seek_tail, -1); // Mocked return value - int ret = w_journal_context_seek_most_recent(ctx); - - // Check the result - assert_int_equal(ret, -1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_most_recent success -static void test_w_journal_context_seek_most_recent_success(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_seek_tail, 0); // Mocked return value - will_return(__wrap_sd_journal_previous, 0); // Mocked return value - int ret = w_journal_context_seek_most_recent(ctx); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_most_recent with null ctx -static void test_w_journal_context_seek_most_recent_ctx_null(void ** state) { - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Perform the function under test - int ret = w_journal_context_seek_most_recent(ctx); - - // Check the result - assert_int_equal(ret, -1); -} - -// Test w_journal_context_seek_timestamp - -// Test for w_journal_context_seek_timestamp with null params -static void test_w_journal_context_seek_timestamp_null_params(void ** state) { - assert_int_equal(w_journal_context_seek_timestamp(NULL, 0), -1); -} - -// Test for w_journal_context_seek_timestamp with future timestamp -static void test_w_journal_context_seek_timestamp_future_timestamp(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_gettimeofday, NULL); - expect_string(__wrap__mwarn, - formatted_msg, - "(8012): The timestamp '1234567' is in the future or invalid. Using the most recent entry."); - will_return(__wrap_sd_journal_seek_tail, 0); // Mocked return value - will_return(__wrap_sd_journal_previous, 0); // Mocked return value - int ret = w_journal_context_seek_timestamp(ctx, 1234567); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_timestamp error when getting oldest timestamp -static void test_w_journal_context_seek_timestamp_fail_read_old_ts(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - struct timeval expected_time = {.tv_sec = 1234, .tv_usec = 5678}; - struct timeval actual_time; - will_return(__wrap_gettimeofday, &expected_time); - will_return(__wrap_sd_journal_get_cutoff_realtime_usec, -1); // Mocked oldest timestamp - expect_string(__wrap__mwarn, - formatted_msg, - "(8013): Failed to read oldest timestamp from journal log: 'Operation not permitted'."); - will_return(__wrap_sd_journal_seek_realtime_usec, 0); - will_return(__wrap_sd_journal_next, 0); - - int ret = w_journal_context_seek_timestamp(ctx, 1234567); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_timestamp with timestamp older than oldest available -static void test_w_journal_context_seek_timestamp_change_ts(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - struct timeval expected_time = {.tv_sec = 1233, .tv_usec = 5678}; - struct timeval actual_time; - will_return(__wrap_gettimeofday, &expected_time); - will_return(__wrap_sd_journal_get_cutoff_realtime_usec, 22345678); // Mocked oldest timestamp - expect_string( - __wrap__mwarn, - formatted_msg, - "(8014): The timestamp '1234567' is older than the oldest available in journal. Using the oldest entry."); - will_return(__wrap_sd_journal_seek_realtime_usec, 0); - will_return(__wrap_sd_journal_next, 0); - - int ret = w_journal_context_seek_timestamp(ctx, 1234567); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_timestamp with error when seeking timestamp -static void test_w_journal_context_seek_timestamp_seek_timestamp_fail(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - struct timeval expected_time = {.tv_sec = 1234, .tv_usec = 5678}; - struct timeval actual_time; - will_return(__wrap_gettimeofday, &expected_time); - will_return(__wrap_sd_journal_get_cutoff_realtime_usec, 0); // Mocked oldest timestamp - will_return(__wrap_sd_journal_seek_realtime_usec, -1); - - int ret = w_journal_context_seek_timestamp(ctx, 1234567); - - // Check the result - assert_int_equal(ret, -1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_timestamp with error when seek the timestamp -static void test_w_journal_context_seek_timestamp_fail_seek(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - struct timeval expected_time = {.tv_sec = 1234, .tv_usec = 5678}; - struct timeval actual_time; - will_return(__wrap_gettimeofday, &expected_time); - will_return(__wrap_sd_journal_get_cutoff_realtime_usec, 0); // Mocked oldest timestamp - will_return(__wrap_sd_journal_seek_realtime_usec, -1); - - int ret = w_journal_context_seek_timestamp(ctx, 1234567); - - // Check the result - assert_int_equal(ret, -1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_timestamp with error when getting next entry -static void test_w_journal_context_seek_timestamp_next_fail(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - struct timeval expected_time = {.tv_sec = 1234, .tv_usec = 5678}; - struct timeval actual_time; - will_return(__wrap_gettimeofday, &expected_time); - will_return(__wrap_sd_journal_get_cutoff_realtime_usec, 0); // Mocked oldest timestamp - will_return(__wrap_sd_journal_seek_realtime_usec, 0); - will_return(__wrap_sd_journal_next, -1); - - int ret = w_journal_context_seek_timestamp(ctx, 1234567); - - // Check the result - assert_int_equal(ret, -1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_seek_timestamp success -static void test_w_journal_context_seek_timestamp_success(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - struct timeval expected_time = {.tv_sec = 1234, .tv_usec = 5678}; - struct timeval actual_time; - will_return(__wrap_gettimeofday, &expected_time); - will_return(__wrap_sd_journal_get_cutoff_realtime_usec, 0); // Mocked oldest timestamp - will_return(__wrap_sd_journal_seek_realtime_usec, 0); - will_return(__wrap_sd_journal_next, 0); - - int ret = w_journal_context_seek_timestamp(ctx, 123457); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -static void test_w_journal_context_seek_timestamp_success_new_entry(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - struct timeval expected_time = {.tv_sec = 1234, .tv_usec = 5678}; - struct timeval actual_time; - will_return(__wrap_gettimeofday, &expected_time); - will_return(__wrap_sd_journal_get_cutoff_realtime_usec, 0); // Mocked oldest timestamp - will_return(__wrap_sd_journal_seek_realtime_usec, 0); - will_return(__wrap_sd_journal_next, 1); - - // update timestamp - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - - int ret = w_journal_context_seek_timestamp(ctx, 123457); - - // Check the result - assert_int_equal(ret, 1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test w_journal_context_next_newest - -// Test for w_journal_context_next_newest with null ctx -static void test_w_journal_context_next_newest_ctx_null(void ** state) { - // Perform the function under test - int ret = w_journal_context_next_newest(NULL); - - // Check the result - assert_int_equal(ret, -1); -} - -// Test for w_journal_context_next_newest updating timestamp -static void test_w_journal_context_next_newest_update_timestamp(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 1); // Mocked return value - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - - int ret = w_journal_context_next_newest(ctx); - - // Check the result - assert_int_equal(ret, 1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_next_newest success -static void test_w_journal_context_next_newest_success(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 0); // Mocked return value - - int ret = w_journal_context_next_newest(ctx); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test w_journal_filter_apply - -// Test for w_journal_filter_apply with null params -void test_w_journal_filter_apply_null_params(void ** state) { - - assert_int_equal(w_journal_filter_apply(NULL, (w_journal_filter_t *) 0x1), -1); - assert_int_equal(w_journal_filter_apply((w_journal_context_t *) 0x1, NULL), -1); -} - -// Test for w_journal_filter_apply with fail to get data -void test_w_journal_filter_apply_fail_get_data_ignore_test(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Set timestamp - ctx->timestamp = 123456; - - // Create filter for arg, ignore if missing data = false - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field_to_ignore", ".", true)); - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field_no_ignore", ".", false)); - - // Apply filter expected - expect_string(__wrap_sd_journal_get_data, field, "field_to_ignore"); - will_return(__wrap_sd_journal_get_data, -1); // Fail get data, ignore - - expect_string(__wrap_sd_journal_get_data, field, "field_no_ignore"); - will_return(__wrap_sd_journal_get_data, -1); // Fail get data, not ignore - - // Expect err message and return error - expect_string(__wrap__mdebug2, - formatted_msg, - "(9003): Failed to get data field 'field_no_ignore' from entry with timestamp '123456'. Error: " - "Operation not permitted"); - - // Apply filter - assert_int_equal(-1, w_journal_filter_apply(ctx, ufilters)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free - // Free filter - w_journal_filter_free(ufilters); -} - -// Test for w_journal_filter_apply with fail parse data -void test_w_journal_filter_apply_fail_parse(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Set timestamp - ctx->timestamp = 123456; - - // Create filter for arg, ignore if missing data = false - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", ".", true)); - - // Apply filter expected - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); // get data ok, the load data - will_return(__wrap_sd_journal_get_data, "f="); // Should be a valid data, 'field=' - - // Apply filter - assert_int_equal(-1, w_journal_filter_apply(ctx, ufilters)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free - // Free filter - w_journal_filter_free(ufilters); -} - -// Test for w_journal_filter_apply with empty field -void test_w_journal_filter_apply_empty_field(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Set timestamp - ctx->timestamp = 123456; - - // Create filter for arg, ignore if missing data = false - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", ".", true)); - - // Apply filter expected - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); // get data ok, the load data - will_return(__wrap_sd_journal_get_data, "field="); // Empty field - - // Apply filter - assert_int_equal(0, w_journal_filter_apply(ctx, ufilters)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free - // Free filter - w_journal_filter_free(ufilters); -} - -// Test for w_journal_filter_apply with match fail -void test_w_journal_filter_apply_match_fail(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Set timestamp - ctx->timestamp = 123456; - - // Create filter for arg, match with number fail - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", "^\\d", false)); - - // Apply filter expected - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); // get data ok, the load data - will_return(__wrap_sd_journal_get_data, "field=test text"); // Empty field - - // Apply filter - assert_int_equal(0, w_journal_filter_apply(ctx, ufilters)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free - // Free filter - w_journal_filter_free(ufilters); -} - -// Test for w_journal_filter_apply with match success -void test_w_journal_filter_apply_match_success(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Set timestamp - ctx->timestamp = 123456; - - // Create filter for arg, match with number ok - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", "^\\d", false)); - - // Apply filter expected - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); // get data ok, the load data - will_return(__wrap_sd_journal_get_data, "field=123123"); // Empty field - - // Apply filter - assert_int_equal(1, w_journal_filter_apply(ctx, ufilters)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free - // Free filter - w_journal_filter_free(ufilters); -} - -// Test w_journal_context_next_newest_filtered - -// Test for w_journal_context_next_newest_filtered with null filters -static void test_w_journal_context_next_newest_filtered_null_filters(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 0); // Mocked return value - int ret = w_journal_context_next_newest_filtered(ctx, NULL); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_next_newest_filtered with no filters -static void test_w_journal_context_next_newest_filtered_no_filters(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 0); // Mocked return value - int ret = w_journal_context_next_newest_filtered(ctx, (w_journal_filters_list_t) NULL); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); -} - -// Test for w_journal_context_next_newest_filtered with one filter -static void test_w_journal_context_next_newest_filtered_one_filter(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 0); // Mocked return value - - // Create filter for arg, ignore if missing data = false - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", ".", true)); - - int ret = w_journal_context_next_newest_filtered(ctx, (w_journal_filters_list_t) ufilters); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); - // Free filter - w_journal_filter_free(ufilters); -} - -// Test for w_journal_context_next_newest_filtered is debug -static void test_w_journal_context_next_newest_filtered_is_debug(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 1); // Mocked return value - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - - // Create filter for arg, ignore if missing data = false - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", ".", true)); - - // Set debug - will_return(__wrap_isDebug, 1); - - will_return(__wrap_gmtime_r, 0); // Mocked time - // mock mdebug2 - expect_string(__wrap__mdebug2, formatted_msg, "(9004): Checking filters for timestamp 'unknown'"); - - int ret = w_journal_context_next_newest_filtered(ctx, (w_journal_filters_list_t) ufilters); - - // Check the result - assert_int_equal(ret, 1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); - // Free filter - w_journal_filter_free(ufilters); -} - -// Test for w_journal_context_next_newest_filtered is debug false -static void test_w_journal_context_next_newest_filtered_is_debug_false(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 1); // Mocked return value - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - - // Create filter for arg, ignore if missing data = false - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", ".", true)); - - // Set debug - will_return(__wrap_isDebug, 0); - - int ret = w_journal_context_next_newest_filtered(ctx, (w_journal_filters_list_t) ufilters); - - // Check the result - assert_int_equal(ret, 1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); - // Free filter - w_journal_filter_free(ufilters); -} - -// Test for w_journal_context_next_newest_filtered with filter apply -static void test_w_journal_context_next_newest_filtered_filter_apply(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 1); // Mocked return value - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - - // Set debug - will_return(__wrap_isDebug, 0); - - // Create filter for arg, ignore if missing data = false - w_journal_filters_list_t filter_list = NULL; - - // Prepare the filter - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", ".", true)); - // Add filter to the list - assert_true(w_journal_add_filter_to_list(&filter_list, ufilters)); - - // Apply filter expected - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); // get data ok, the load data - will_return(__wrap_sd_journal_get_data, "field=123123"); // Empty field - - int ret = w_journal_context_next_newest_filtered(ctx, filter_list); - - // Check the result - assert_int_equal(ret, 1); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); - // Free filter list - w_journal_filters_list_free(filter_list); -} - -// Test for w_journal_context_next_newest_filtered with filter apply fail -static void test_w_journal_context_next_newest_filtered_filter_apply_fail(void ** state) { - // test_w_journal_context_create_success - // Define a pointer to w_journal_context_t - w_journal_context_t * ctx = NULL; - - // Expectativas de llamada a w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); // Mocked handle - - // test_find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - - // Simulate the successful opening of a file - FILE * maps_file = (FILE *) 0x123456; // Simulated address - will_return(__wrap_fopen, maps_file); - - // Simulate a line containing the searched library - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - - // test_is_owned_by_root_root_owned - - const char * library_path = "/libsystemd.so.0"; - - struct stat mock_stat; - mock_stat.st_uid = 0; - - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - - void * handle = (void *) 1; // Simulate handle - void * mock_function = (void *) 0xabcdef; - - // Set expectations for dlsym wrap - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - - // Perform the function under test - will_return(__wrap_sd_journal_next, 1); // Mocked return value - will_return(__wrap_sd_journal_get_realtime_usec, 123456); // Mocked timestamp - - // Set debug - will_return(__wrap_isDebug, 0); - - // Create filter for arg, ignore if missing data = false - w_journal_filters_list_t filter_list = NULL; - - // Prepare the filter - w_journal_filter_t * ufilters = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&ufilters, "field", "^\\d", true)); - // Add filter to the list - assert_true(w_journal_add_filter_to_list(&filter_list, ufilters)); - - // Apply filter expected - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); // get data ok, the load data - will_return(__wrap_sd_journal_get_data, "field=test"); // Empty field - - will_return(__wrap_sd_journal_next, 0); - - int ret = w_journal_context_next_newest_filtered(ctx, filter_list); - - // Check the result - assert_int_equal(ret, 0); - - // Memory release - expect_function_call(__wrap_sd_journal_close); - expect_value(__wrap_dlclose, handle, (void *) 0x123456); // Mocked handle - will_return(__wrap_dlclose, 0); // Simulate dlclose success - w_journal_context_free(ctx); - // Free filter list - w_journal_filters_list_free(filter_list); -} - -// Test entry_as_json -void test_entry_as_json_empty(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Expect - will_return(__wrap_cJSON_CreateObject, (cJSON *) 0x123456); - will_return(__wrap_sd_journal_restart_data, 0); - // Empty entry - will_return(__wrap_sd_journal_enumerate_data, 0); - expect_function_call(__wrap_cJSON_Delete); - - assert_null(entry_as_json(ctx)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_json_fail_parse_field(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Expect - will_return(__wrap_cJSON_CreateObject, (cJSON *) 0x123456); - will_return(__wrap_sd_journal_restart_data, 0); - // Empty entry - will_return(__wrap_sd_journal_enumerate_data, 1); - will_return(__wrap_sd_journal_enumerate_data, "field >> no equal sign"); - will_return(__wrap_sd_journal_enumerate_data, 0); - expect_function_call(__wrap_cJSON_Delete); - - assert_null(entry_as_json(ctx)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_json_success(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Expect - will_return(__wrap_cJSON_CreateObject, (cJSON *) 0x123456); - will_return(__wrap_sd_journal_restart_data, 0); - // 3 entryes - will_return(__wrap_sd_journal_enumerate_data, 1); - will_return(__wrap_sd_journal_enumerate_data, "field=value"); - expect_string(__wrap_cJSON_AddStringToObject, name, "field"); - expect_string(__wrap_cJSON_AddStringToObject, string, "value"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_sd_journal_enumerate_data, 1); - will_return(__wrap_sd_journal_enumerate_data, "field2=123"); - expect_string(__wrap_cJSON_AddStringToObject, name, "field2"); - expect_string(__wrap_cJSON_AddStringToObject, string, "123"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_sd_journal_enumerate_data, 1); - will_return(__wrap_sd_journal_enumerate_data, "field3="); - expect_string(__wrap_cJSON_AddStringToObject, name, "field3"); - expect_string(__wrap_cJSON_AddStringToObject, string, ""); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_sd_journal_enumerate_data, 0); - - assert_non_null(entry_as_json(ctx)); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -// Test get_field_ptr -void test_get_field_ptr_fail_get_data(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Expect - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, -1); - - assert_null(get_field_ptr(ctx, "field")); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_get_field_ptr_fail_parse(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Expect - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "field >> no equal sign"); - - assert_null(get_field_ptr(ctx, "field")); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_get_field_ptr_empty_field(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Expect - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "field="); - - char * value = get_field_ptr(ctx, "field"); - assert_non_null(value); - assert_string_equal(value, ""); - os_free(value); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_get_field_ptr_success(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - - // Expect - expect_string(__wrap_sd_journal_get_data, field, "field"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "field=value"); - - char * val = get_field_ptr(ctx, "field"); - assert_non_null(val); - assert_string_equal(val, "value"); - os_free(val); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -// Test create_plain_syslog -void test_create_plain_syslog_with_pid(void ** state) { - - char * retval = create_plain_syslog("", "hosname", "tag", "pid", "message"); - assert_non_null(retval); - assert_string_equal(retval, " hosname tag[pid]: message"); - os_free(retval); -} - -void test_create_plain_syslog_without_pid(void ** state) { - - char * retval = create_plain_syslog("", "hosname", "tag", NULL, "message"); - assert_non_null(retval); - assert_string_equal(retval, " hosname tag: message"); - os_free(retval); -} - -// Test entry_as_syslog -void test_entry_as_syslog_success(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_PID="); - - // Get timestamp - - will_return(__wrap_gmtime_r, timestamp); - - // Check the result - char * retval = entry_as_syslog(ctx); - assert_non_null(retval); - assert_string_equal(retval, "Apr 19 16:19:34 []: "); - os_free(retval); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_syslog_success_system_pid(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_PID="); - - // Get timestamp - - will_return(__wrap_gmtime_r, timestamp); - - // Check the result - char * retval = entry_as_syslog(ctx); - assert_non_null(retval); - assert_string_equal(retval, "Apr 19 16:19:34 []: "); - os_free(retval); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_syslog_success_no_pid(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "_PID"); - will_return(__wrap_sd_journal_get_data, -1); - - // Get timestamp - - will_return(__wrap_gmtime_r, timestamp); - - // Check the result - char * retval = entry_as_syslog(ctx); - assert_non_null(retval); - assert_string_equal(retval, "Apr 19 16:19:34 : "); - os_free(retval); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_syslog_missing_hostname(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_PID="); - - // Get timestamp - will_return(__wrap_gmtime_r, timestamp); - - // Debug msg - expect_string(__wrap__mdebug2, - formatted_msg, - "(9002): Failed to get the required fields, discarted log with timestamp '1618849174000000'"); - - // Check the result - char * retval = entry_as_syslog(ctx); - assert_null(retval); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_syslog_missing_tag(void ** state) { - - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_PID="); - - // Get timestamp - will_return(__wrap_gmtime_r, timestamp); - - // Debug msg - expect_string(__wrap__mdebug2, - formatted_msg, - "(9002): Failed to get the required fields, discarted log with timestamp '1618849174000000'"); - - // Check the result - char * retval = entry_as_syslog(ctx); - assert_null(retval); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_syslog_missing_message(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_PID="); - - // Get timestamp - will_return(__wrap_gmtime_r, timestamp); - - // Debug msg - expect_string(__wrap__mdebug2, - formatted_msg, - "(9002): Failed to get the required fields, discarted log with timestamp '1618849174000000'"); - - // Check the result - char * retval = entry_as_syslog(ctx); - assert_null(retval); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_entry_as_syslog_missing_timestamp(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_PID="); - - // Get timestamp - will_return(__wrap_gmtime_r, 0); - - // Debug msg - expect_string(__wrap__mdebug2, - formatted_msg, - "(9002): Failed to get the required fields, discarted log with timestamp '1618849174000000'"); - - // Check the result - char * retval = entry_as_syslog(ctx); - assert_null(retval); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -// Test w_journal_entry_dump -void test_w_journal_entry_dump_null_params(void ** state) { - assert_null(w_journal_entry_dump(NULL, W_JOURNAL_ENTRY_DUMP_TYPE_SYSLOG)); - assert_null(w_journal_entry_dump(NULL, W_JOURNAL_ENTRY_DUMP_TYPE_JSON)); -} - -void test_w_journal_entry_dump_invalid_type(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - ctx->timestamp = 123456; - ctx->journal = (void *) 0x123456; - - assert_null(w_journal_entry_dump(ctx, W_JOURNAL_ENTRY_DUMP_TYPE_INVALID)); - - // Test Free invalid - w_journal_entry_t * entry = calloc(1, sizeof(w_journal_entry_t)); - entry->type = W_JOURNAL_ENTRY_DUMP_TYPE_INVALID; - entry->timestamp = ctx->timestamp; - assert_null(w_journal_entry_dump(ctx, W_JOURNAL_ENTRY_DUMP_TYPE_INVALID)); - w_journal_entry_free(entry); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_w_journal_entry_dump_json_success(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - ctx->timestamp = 123456; - ctx->journal = (void *) 0x123456; - - // Expect - will_return(__wrap_cJSON_CreateObject, (cJSON *) 0x123456); - will_return(__wrap_sd_journal_restart_data, 0); - // 3 entryes - will_return(__wrap_sd_journal_enumerate_data, 1); - will_return(__wrap_sd_journal_enumerate_data, "field=value"); - expect_string(__wrap_cJSON_AddStringToObject, name, "field"); - expect_string(__wrap_cJSON_AddStringToObject, string, "value"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_sd_journal_enumerate_data, 1); - will_return(__wrap_sd_journal_enumerate_data, "field2=123"); - expect_string(__wrap_cJSON_AddStringToObject, name, "field2"); - expect_string(__wrap_cJSON_AddStringToObject, string, "123"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_sd_journal_enumerate_data, 1); - will_return(__wrap_sd_journal_enumerate_data, "field3="); - expect_string(__wrap_cJSON_AddStringToObject, name, "field3"); - expect_string(__wrap_cJSON_AddStringToObject, string, ""); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_sd_journal_enumerate_data, 0); - - w_journal_entry_t * entry = w_journal_entry_dump(ctx, W_JOURNAL_ENTRY_DUMP_TYPE_JSON); - assert_non_null(entry); - assert_non_null(entry->data.json); - assert_int_equal(entry->type, W_JOURNAL_ENTRY_DUMP_TYPE_JSON); - assert_int_equal(entry->timestamp, ctx->timestamp); - - // Free entry (test) - expect_function_call(__wrap_cJSON_Delete); - w_journal_entry_free(entry); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_w_journal_entry_dump_syslog_fail_json(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - ctx->timestamp = 123456; - ctx->journal = (void *) 0x123456; - - // Expect - will_return(__wrap_cJSON_CreateObject, (cJSON *) 0x123456); - will_return(__wrap_sd_journal_restart_data, 0); - // Empty entry - will_return(__wrap_sd_journal_enumerate_data, 0); - expect_function_call(__wrap_cJSON_Delete); - - w_journal_entry_t * entry = w_journal_entry_dump(ctx, W_JOURNAL_ENTRY_DUMP_TYPE_JSON); - assert_null(entry); - - // Free entry (test) - w_journal_entry_free(entry); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_w_journal_entry_dump_syslog_success(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - ctx->journal = (void *) 0x123456; - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Expect - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_PID="); - - // Get timestamp - will_return(__wrap_gmtime_r, timestamp); - - w_journal_entry_t * entry = w_journal_entry_dump(ctx, W_JOURNAL_ENTRY_DUMP_TYPE_SYSLOG); - assert_non_null(entry); - assert_non_null(entry->data.syslog); - assert_int_equal(entry->type, W_JOURNAL_ENTRY_DUMP_TYPE_SYSLOG); - assert_int_equal(entry->timestamp, ctx->timestamp); - - // Free entry (test) - w_journal_entry_free(entry); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_w_journal_entry_dump_syslog_fail(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - ctx->journal = (void *) 0x123456; - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Extract fail - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, -1); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_PID="); - - // Get timestamp - will_return(__wrap_gmtime_r, timestamp); - - // Debug msg - expect_string(__wrap__mdebug2, - formatted_msg, - "(9002): Failed to get the required fields, discarted log with timestamp '1618849174000000'"); - - // Get timestamp - - w_journal_entry_t * entry = w_journal_entry_dump(ctx, W_JOURNAL_ENTRY_DUMP_TYPE_SYSLOG); - assert_null(entry); - // Free entry (test) - w_journal_entry_free(entry); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -// Test w_journal_entry_to_string -void test_w_journal_entry_to_string_null_params(void ** state) { assert_null(w_journal_entry_to_string(NULL)); } - -void test_w_journal_entry_to_string_syslog(void ** state) { - // init ctx - w_journal_context_t * ctx = NULL; - // >>>> Start Init conext - // w_journal_lib_init - expect_string(__wrap_dlopen, filename, W_LIB_SYSTEMD); - expect_value(__wrap_dlopen, flags, RTLD_LAZY); - will_return(__wrap_dlopen, (void *) 0x123456); - // find_library_path_success - expect_string(__wrap_fopen, path, "/proc/self/maps"); - expect_string(__wrap_fopen, mode, "r"); - FILE * maps_file = (FILE *) 0x123456; - will_return(__wrap_fopen, maps_file); - char * simulated_line = strdup("00400000-0040b000 r-xp 00000000 08:01 6711792 /libsystemd.so.0\n"); - will_return(__wrap_getline, simulated_line); - expect_value(__wrap_fclose, _File, 0x123456); - will_return(__wrap_fclose, 1); - // is_owned_by_root_root_owned - const char * library_path = "/libsystemd.so.0"; - struct stat mock_stat; - mock_stat.st_uid = 0; - expect_string(__wrap_stat, __file, library_path); - will_return(__wrap_stat, &mock_stat); - will_return(__wrap_stat, 0); - void * handle = (void *) 1; - void * mock_function = (void *) 0xabcdef; - // dlsym - setup_dlsym_expectations("sd_journal_open"); - setup_dlsym_expectations("sd_journal_close"); - setup_dlsym_expectations("sd_journal_previous"); - setup_dlsym_expectations("sd_journal_next"); - setup_dlsym_expectations("sd_journal_seek_tail"); - setup_dlsym_expectations("sd_journal_seek_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_realtime_usec"); - setup_dlsym_expectations("sd_journal_get_data"); - setup_dlsym_expectations("sd_journal_restart_data"); - setup_dlsym_expectations("sd_journal_enumerate_data"); - setup_dlsym_expectations("sd_journal_get_cutoff_realtime_usec"); - will_return(__wrap_sd_journal_open, 0); - w_journal_context_create(&ctx); - // <<<< End init conetxt - ctx->journal = (void *) 0x123456; - uint64_t timestamp = 1618849174000000; // Timestamp in microseconds (2021-04-19 16:19:34) - ctx->timestamp = timestamp; - - // Expect - - // Extract - expect_string(__wrap_sd_journal_get_data, field, "_HOSTNAME"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "_HOSTNAME="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_IDENTIFIER"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_IDENTIFIER="); - - expect_string(__wrap_sd_journal_get_data, field, "MESSAGE"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "MESSAGE="); - - expect_string(__wrap_sd_journal_get_data, field, "SYSLOG_PID"); - will_return(__wrap_sd_journal_get_data, 0); - will_return(__wrap_sd_journal_get_data, "SYSLOG_PID="); - - // Get timestamp - will_return(__wrap_gmtime_r, timestamp); - - w_journal_entry_t * entry = w_journal_entry_dump(ctx, W_JOURNAL_ENTRY_DUMP_TYPE_SYSLOG); - assert_non_null(entry); - assert_non_null(entry->data.syslog); - assert_int_equal(entry->type, W_JOURNAL_ENTRY_DUMP_TYPE_SYSLOG); - assert_int_equal(entry->timestamp, ctx->timestamp); - - char * str = w_journal_entry_to_string(entry); - assert_non_null(str); - assert_string_equal(str, "Apr 19 16:19:34 []: "); - - // Free entry (test) - os_free(str); - w_journal_entry_free(entry); - - // >>>> Start context free - expect_value(__wrap_dlclose, handle, (void *) 0x123456); - will_return(__wrap_dlclose, 0); - expect_function_call(__wrap_sd_journal_close); - w_journal_context_free(ctx); - // <<<< End Context free -} - -void test_w_journal_entry_to_string_json(void ** state) { - w_journal_entry_t * entry = calloc(1, sizeof(w_journal_entry_t)); - entry->type = W_JOURNAL_ENTRY_DUMP_TYPE_JSON; - entry->timestamp = 123456; - entry->data.json = (cJSON *) 0x123456; - - will_return(__wrap_cJSON_PrintUnformatted, strdup("json_string")); - char * str = w_journal_entry_to_string(entry); - - assert_non_null(str); - assert_string_equal(str, "json_string"); - - os_free(str); - os_free(entry); -} - -void test_w_journal_entry_to_string_invalid_type(void ** state) { - - w_journal_entry_t * entry = calloc(1, sizeof(w_journal_entry_t)); - entry->type = W_JOURNAL_ENTRY_DUMP_TYPE_INVALID; - entry->timestamp = 123456; - entry->data.json = (cJSON *) 0x123456; - - char * str = w_journal_entry_to_string(entry); - - assert_null(str); - - os_free(entry); -} - -int main(void) { - - const struct CMUnitTest tests[] = { - // Test is_owned_by_root - cmocka_unit_test(test_is_owned_by_root_root_owned), - cmocka_unit_test(test_is_owned_by_root_not_root_owned), - cmocka_unit_test(test_is_owned_by_root_stat_fails), - // Test load_and_validate_function - cmocka_unit_test(test_load_and_validate_function_success), - cmocka_unit_test(test_load_and_validate_function_failure), - // Test w_get_epoch_time - cmocka_unit_test(test_w_get_epoch_time), - // Test w_timestamp_to_string - cmocka_unit_test(test_w_timestamp_to_string), - cmocka_unit_test(test_w_timestamp_to_journalctl_since_success), - cmocka_unit_test(test_w_timestamp_to_journalctl_since_failure), - // Test find_library_path - cmocka_unit_test(test_find_library_path_success), - cmocka_unit_test(test_find_library_path_failure), - // Test w_journal_context_create - cmocka_unit_test(test_w_journal_lib_init_dlopen_fail), - cmocka_unit_test(test_w_journal_lib_init_find_library_path_fail), - cmocka_unit_test(test_w_journal_lib_init_is_owned_by_root_fail), - cmocka_unit_test(test_w_journal_lib_init_load_and_validate_function_fail), - cmocka_unit_test(test_w_journal_lib_init_success), - // Test w_journal_context_create - cmocka_unit_test(test_w_journal_context_create_success), - cmocka_unit_test(test_w_journal_context_create_null_pointer), - cmocka_unit_test(test_w_journal_context_create_lib_init_fail), - cmocka_unit_test(test_w_journal_context_create_journal_open_fail), - // Test w_journal_context_free - cmocka_unit_test(test_w_journal_context_free_null), - cmocka_unit_test(test_w_journal_context_free_valid), - // Test w_journal_context_update_timestamp - cmocka_unit_test(test_w_journal_context_update_timestamp_success), - cmocka_unit_test(test_w_journal_context_update_timestamp_ctx_null), - cmocka_unit_test(test_w_journal_context_update_timestamp_fail), - // Test w_journal_context_seek_timestamp - cmocka_unit_test(test_w_journal_context_seek_most_recent_update_tamestamp), - cmocka_unit_test(test_w_journal_context_seek_most_recent_seek_tail_fail), - cmocka_unit_test(test_w_journal_context_seek_most_recent_success), - cmocka_unit_test(test_w_journal_context_seek_most_recent_ctx_null), - // Test w_journal_context_seek_timestamp - cmocka_unit_test(test_w_journal_context_seek_timestamp_null_params), - cmocka_unit_test(test_w_journal_context_seek_timestamp_future_timestamp), - cmocka_unit_test(test_w_journal_context_seek_timestamp_fail_read_old_ts), - cmocka_unit_test(test_w_journal_context_seek_timestamp_change_ts), - cmocka_unit_test(test_w_journal_context_seek_timestamp_fail_seek), - cmocka_unit_test(test_w_journal_context_seek_timestamp_seek_timestamp_fail), - cmocka_unit_test(test_w_journal_context_seek_timestamp_next_fail), - cmocka_unit_test(test_w_journal_context_seek_timestamp_success), - cmocka_unit_test(test_w_journal_context_seek_timestamp_success_new_entry), - // Test w_journal_context_next_newest - cmocka_unit_test(test_w_journal_context_next_newest_ctx_null), - cmocka_unit_test(test_w_journal_context_next_newest_update_timestamp), - cmocka_unit_test(test_w_journal_context_next_newest_success), - // Test w_journal_filter_apply - cmocka_unit_test(test_w_journal_filter_apply_null_params), - cmocka_unit_test(test_w_journal_filter_apply_fail_get_data_ignore_test), - cmocka_unit_test(test_w_journal_filter_apply_fail_parse), - cmocka_unit_test(test_w_journal_filter_apply_empty_field), - cmocka_unit_test(test_w_journal_filter_apply_match_fail), - cmocka_unit_test(test_w_journal_filter_apply_match_success), - // Test w_journal_context_next_newest_filtered - cmocka_unit_test(test_w_journal_context_next_newest_filtered_null_filters), - cmocka_unit_test(test_w_journal_context_next_newest_filtered_no_filters), - cmocka_unit_test(test_w_journal_context_next_newest_filtered_one_filter), - cmocka_unit_test(test_w_journal_context_next_newest_filtered_is_debug), - cmocka_unit_test(test_w_journal_context_next_newest_filtered_is_debug_false), - cmocka_unit_test(test_w_journal_context_next_newest_filtered_filter_apply), - cmocka_unit_test(test_w_journal_context_next_newest_filtered_filter_apply_fail), - // Test entry_as_json - cmocka_unit_test(test_entry_as_json_empty), - cmocka_unit_test(test_entry_as_json_fail_parse_field), - cmocka_unit_test(test_entry_as_json_success), - // Test get_field_ptr - cmocka_unit_test(test_get_field_ptr_fail_get_data), - cmocka_unit_test(test_get_field_ptr_fail_parse), - cmocka_unit_test(test_get_field_ptr_empty_field), - cmocka_unit_test(test_get_field_ptr_success), - // Test create_plain_syslog - cmocka_unit_test(test_create_plain_syslog_with_pid), - cmocka_unit_test(test_create_plain_syslog_without_pid), - // Test entry_as_syslog - cmocka_unit_test(test_entry_as_syslog_success), - cmocka_unit_test(test_entry_as_syslog_success_system_pid), - cmocka_unit_test(test_entry_as_syslog_success_no_pid), - cmocka_unit_test(test_entry_as_syslog_missing_hostname), - cmocka_unit_test(test_entry_as_syslog_missing_tag), - cmocka_unit_test(test_entry_as_syslog_missing_message), - cmocka_unit_test(test_entry_as_syslog_missing_timestamp), - // Test w_journal_entry_dump - cmocka_unit_test(test_w_journal_entry_dump_null_params), - cmocka_unit_test(test_w_journal_entry_dump_invalid_type), - cmocka_unit_test(test_w_journal_entry_dump_json_success), - cmocka_unit_test(test_w_journal_entry_dump_syslog_fail_json), - cmocka_unit_test(test_w_journal_entry_dump_syslog_success), - cmocka_unit_test(test_w_journal_entry_dump_syslog_fail), - // Test w_journal_entry_to_string - cmocka_unit_test(test_w_journal_entry_to_string_null_params), - cmocka_unit_test(test_w_journal_entry_to_string_syslog), - cmocka_unit_test(test_w_journal_entry_to_string_json), - cmocka_unit_test(test_w_journal_entry_to_string_invalid_type), - - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/logcollector/test_lccom.c b/src/unit_tests/logcollector/test_lccom.c deleted file mode 100644 index 3670719d360..00000000000 --- a/src/unit_tests/logcollector/test_lccom.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../logcollector/state.h" -#include "../../logcollector/logcollector.h" -#include "../../wazuh_modules/wmodules.h" -#include "../../os_net/os_net.h" - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" - -#include "json_data.h" - -size_t lccom_getstate(char ** output, bool getNextPage); -uint16_t getJsonStr64kBlockFromLatestIndex(char **output, bool getNextPage); -void addStartandEndTagsToJsonStrBlock(char *buffJson, char *headerGlobal, char *headerInterval, char *headerData, size_t LenHeaderInterval, size_t LenHeaderData, size_t LenHeaderGlobal, size_t counter, bool getNextPage); -bool isJsonUpdated(void); - -/* setup/teardown */ - -static int setup_group(void ** state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void ** state) { - test_mode = 0; - return 0; -} - -/* wraps */ - -cJSON * __wrap_w_logcollector_state_get() { - return mock_type(cJSON *); -} - -double __wrap_difftime (time_t __time1, time_t __time0) { - return mock(); -} - -/* tests */ - -/* lccom_getstate */ - -void test_lccom_getstate_ok(void ** state) { - - char * output = NULL; - char json[] = "test json"; - state_interval = true; - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 2); - will_return(__wrap_w_logcollector_state_get, (cJSON *) 3); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "remaining"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "json_updated"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, 0); - - will_return(__wrap_cJSON_PrintUnformatted, json); - expect_function_call(__wrap_cJSON_Delete); - - size_t retval = lccom_getstate(&output, false); - - assert_int_equal(strlen(json), retval); - assert_string_equal(json, output); -} - -void test_lccom_getstate_null(void ** state) { - - char * output = NULL; - char json[] = "test json"; - state_interval = true; - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 2); - will_return(__wrap_w_logcollector_state_get, NULL); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddObjectToObject, name, "data"); - expect_value(__wrap_cJSON_AddObjectToObject, object, (cJSON *) 2); - will_return(__wrap_cJSON_AddObjectToObject, NULL); - - expect_string(__wrap_cJSON_AddStringToObject, name, "message"); - expect_string(__wrap_cJSON_AddStringToObject, string, "Statistics unavailable"); - will_return(__wrap_cJSON_AddStringToObject, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "At LCCOM getstate: Statistics unavailable"); - - will_return(__wrap_cJSON_PrintUnformatted, json); - expect_function_call(__wrap_cJSON_Delete); - - size_t retval = lccom_getstate(&output, false); - - assert_int_equal(strlen(json), retval); - assert_string_equal(json, output); -} - - -void _test_lccom_getstate_tmp (char *fullJson, char *ExpectedBlock, bool getNextPage){ - char * output = NULL; - char *json = NULL; - os_strdup(fullJson, json); - state_interval = true; - struct stat stat_buf = { .st_mode = 0040000 }; - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 2); - will_return(__wrap_w_logcollector_state_get, (cJSON *) 3); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "remaining"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "json_updated"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, 0); - - will_return(__wrap_cJSON_PrintUnformatted, json); - expect_function_call(__wrap_cJSON_Delete); - - if (strstr(fullJson, outjson2) == NULL) { - expect_string(__wrap_stat, __file, "var/run/wazuh-logcollector.state"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - will_return(__wrap_difftime, 10); - will_return(__wrap_strftime,"Wed Dec 31 19:00:00 1969"); - will_return(__wrap_strftime, 20); - expect_string(__wrap__mdebug2, formatted_msg, " Wed Dec 31 19:00:00 1969 var/run/wazuh-logcollector.state"); - } - - size_t retval = lccom_getstate(&output, getNextPage); - assert_int_equal(strlen(output), retval); - assert_string_equal(ExpectedBlock, output); - os_free(output); -} - - -void test_lccom_getstate_first_json_block_greather_than_64k(void ** state) { - _test_lccom_getstate_tmp (global_outjson, outjson_block1, false); -} - -void test_lccom_getstate_second_json_block_greather_than_64k(void ** state) { - _test_lccom_getstate_tmp (global_outjson, outjson_block2, true); -} - -void test_lccom_getstate_third_json_block_greather_than_64k(void ** state) { - _test_lccom_getstate_tmp (global_outjson, outjson_block3, true); -} - -void test_lccom_getstate_end_json_block_lower_than_64k(void ** state) { - _test_lccom_getstate_tmp (global_outjson, outjson_block4, true); -} - -void test_lccom_getstate_first_json_block_greather_than_64k_case1(void ** state) { - _test_lccom_getstate_tmp (outjson1, outjson_block_case_1, false); -} - -void test_lccom_getstate_first_json_block_lower_than_64k_case2(void ** state) { - _test_lccom_getstate_tmp (outjson2, outjson_block_case_2, false); -} - -void test_lccom_getstate_first_json_block_lower_than_64k_case5(void ** state) { - _test_lccom_getstate_tmp (outjson5, outjson_block_case_5, false); -} - -void test_lccom_getstate_first_json_block_lower_than_64k_case5_block1(void ** state) { - _test_lccom_getstate_tmp (outjson5, outjson_block_case_5_1, true); -} - -void test_lccom_getstate_first_json_block_lower_than_64k_case6(void ** state) { - _test_lccom_getstate_tmp (outjson6, outjson_block_case_6, false); -} - -void test_lccom_getstate_first_json_block_lower_than_64k_case6_block1(void ** state) { - _test_lccom_getstate_tmp (outjson6, outjson_block_case_6_1, true); -} - -void test_lccom_getstate_first_json_block_no_global(void ** state) { - expect_string(__wrap__mwarn, formatted_msg, "'global' tag no found in logcollector JSON stats"); - addStartandEndTagsToJsonStrBlock(outjson_no_global, "{\"global\":{\"start\":", "\"interval\":{\"start\":", "{\"error\":0,\"data\":{\"global\":{\"start\":", 0, 0, 0, 0, false); - assert_string_equal(outjson_no_global, outjson_no_global); -} - -void test_lccom_getJsonStr64kBlockFromLatestIndex(void ** state) { - char * output = NULL; - char *json = NULL; - os_strdup(outjson2, json); - - size_t retval = getJsonStr64kBlockFromLatestIndex(&json, false); - assert_int_equal(strlen(json), retval); - assert_string_equal(outjson2, json); - os_free(json); -} - -void test_lccom_isJsonUpdated(void ** state) { - struct stat stat_buf = { .st_mode = 0040000 }; - expect_string(__wrap_stat, __file, "var/run/wazuh-logcollector.state"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - will_return(__wrap_difftime, 10); - will_return(__wrap_strftime,"Wed Dec 31 19:00:00 1969"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mdebug2, formatted_msg, " Wed Dec 31 19:00:00 1969 var/run/wazuh-logcollector.state"); - size_t retval = isJsonUpdated(); -} - -void test_lccom_dispatch_getconfig_ok() { - char * command = NULL; - char * output = NULL; - - os_strdup("getconfig test", command); - - expect_string(__wrap__mdebug1, formatted_msg, "At LCCOM getconfig: Could not get 'test' section"); - - size_t retval = lccom_dispatch(command, &output); - - assert_int_equal(retval, 35); - assert_string_equal(output, "err Could not get requested section"); - - os_free(command); - os_free(output); -} - -void test_lccom_dispatch_getconfig_err() { - char * command = NULL; - char * output = NULL; - - os_strdup("getconfig", command); - - expect_string(__wrap__mdebug1, formatted_msg, "LCCOM getconfig needs arguments."); - - size_t retval = lccom_dispatch(command, &output); - - assert_int_equal(retval, 35); - assert_string_equal(output, "err LCCOM getconfig needs arguments"); - - os_free(command); - os_free(output); -} - -void test_lccom_dispatch_getstate() { - char * command = NULL; - char * output = NULL; - char json[] = "test json"; - state_interval = true; - - os_strdup("getstate", command); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 2); - will_return(__wrap_w_logcollector_state_get, (cJSON *) 3); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "remaining"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "json_updated"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, 0); - - will_return(__wrap_cJSON_PrintUnformatted, strdup(json)); - expect_function_call(__wrap_cJSON_Delete); - - size_t retval = lccom_dispatch(command, &output); - - assert_int_equal(retval, 9); - assert_string_equal(output, "test json"); - - os_free(command); - os_free(output); -} - -void test_lccom_dispatch_getstate_next() { - char * command = NULL; - char * output = NULL; - char json[] = "test json"; - state_interval = true; - - os_strdup("getstate next", command); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 2); - will_return(__wrap_w_logcollector_state_get, (cJSON *) 3); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "error"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - will_return(__wrap_cJSON_AddNumberToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "remaining"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_string(__wrap_cJSON_AddFalseToObject, name, "json_updated"); - will_return(__wrap_cJSON_AddFalseToObject, NULL); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, 0); - - will_return(__wrap_cJSON_PrintUnformatted, strdup(json)); - expect_function_call(__wrap_cJSON_Delete); - - size_t retval = lccom_dispatch(command, &output); - - assert_int_equal(retval, 9); - assert_string_equal(output, "test json"); - - os_free(command); - os_free(output); -} - -void test_lccom_dispatch_err() { - char * command = NULL; - char * output = NULL; - - os_strdup("test", command); - - expect_string(__wrap__mdebug1, formatted_msg, "LCCOM Unrecognized command 'test'."); - - size_t retval = lccom_dispatch(command, &output); - - assert_int_equal(retval, 24); - assert_string_equal(output, "err Unrecognized command"); - - os_free(command); - os_free(output); -} - -int main(void) { - const struct CMUnitTest tests[] = { - - // Tests lccom_getstate - cmocka_unit_test(test_lccom_getstate_ok), - cmocka_unit_test(test_lccom_getstate_null), - cmocka_unit_test(test_lccom_getstate_first_json_block_greather_than_64k), - cmocka_unit_test(test_lccom_getstate_second_json_block_greather_than_64k), - cmocka_unit_test(test_lccom_getstate_third_json_block_greather_than_64k), - cmocka_unit_test(test_lccom_getstate_end_json_block_lower_than_64k), - cmocka_unit_test(test_lccom_getstate_first_json_block_greather_than_64k_case1), - cmocka_unit_test(test_lccom_getstate_first_json_block_lower_than_64k_case2), - cmocka_unit_test(test_lccom_getstate_first_json_block_lower_than_64k_case5), - cmocka_unit_test(test_lccom_getstate_first_json_block_lower_than_64k_case5_block1), - cmocka_unit_test(test_lccom_getstate_first_json_block_lower_than_64k_case6), - cmocka_unit_test(test_lccom_getstate_first_json_block_lower_than_64k_case6_block1), - cmocka_unit_test(test_lccom_getstate_first_json_block_no_global), - cmocka_unit_test(test_lccom_getJsonStr64kBlockFromLatestIndex), - cmocka_unit_test(test_lccom_isJsonUpdated), - cmocka_unit_test(test_lccom_dispatch_getconfig_ok), - cmocka_unit_test(test_lccom_dispatch_getconfig_err), - cmocka_unit_test(test_lccom_dispatch_getstate), - cmocka_unit_test(test_lccom_dispatch_getstate_next), - cmocka_unit_test(test_lccom_dispatch_err), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/logcollector/test_localfile-config.c b/src/unit_tests/logcollector/test_localfile-config.c deleted file mode 100644 index f570ab73066..00000000000 --- a/src/unit_tests/logcollector/test_localfile-config.c +++ /dev/null @@ -1,1106 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../config/localfile-config.h" -#include "../config/config.h" -#include "../wrappers/wazuh/os_xml/os_xml_wrappers.h" -#include "../wrappers/externals/pcre2/pcre2_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" - -const char * multiline_attr_match_str(w_multiline_match_type_t match_type); -const char * multiline_attr_replace_str(w_multiline_replace_type_t replace_type); -unsigned int w_get_attr_timeout(xml_node * node); -w_multiline_replace_type_t w_get_attr_replace(xml_node * node); -w_multiline_match_type_t w_get_attr_match(xml_node * node); -int w_logcollector_get_macos_log_type(const char * content); - -// Journal -#define VALID_PCRE2_REGEX "valid regex \\w+" -#define INVALID_PCRE2_REGEX "invalid regex [a \\w+{-1" - -_w_journal_filter_unit_t * create_unit_filter(const char * field, char * expression, bool ignore_if_missing); -void free_unit_filter(_w_journal_filter_unit_t * unit); -cJSON * unit_filter_as_json(_w_journal_filter_unit_t * unit); -cJSON * filter_as_json(w_journal_filter_t * filter); - -/* setup/teardown */ -static int setup_group(void **state) { - test_mode = 1; - w_test_pcre2_wrappers(false); - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - w_test_pcre2_wrappers(true); - return 0; -} - -/* wraps */ - -/* tests */ - -/* multiline_attr_replace_str */ -void test_multiline_attr_replace_str_no_replace(void ** state) { - w_multiline_replace_type_t replace_type = ML_REPLACE_NO_REPLACE; - const char expected_retval[] = "no-replace"; - const char * retval = multiline_attr_replace_str(replace_type); - assert_string_equal(retval, expected_retval); -} - -void test_multiline_attr_replace_str_none(void ** state) { - w_multiline_replace_type_t replace_type = ML_REPLACE_NONE; - const char expected_retval[] = "none"; - const char * retval = multiline_attr_replace_str(replace_type); - assert_string_equal(retval, expected_retval); -} - -void test_multiline_attr_replace_str_ws(void ** state) { - w_multiline_replace_type_t replace_type = ML_REPLACE_WSPACE; - const char expected_retval[] = "wspace"; - const char * retval = multiline_attr_replace_str(replace_type); - assert_string_equal(retval, expected_retval); -} - -void test_multiline_attr_replace_str_tab(void ** state) { - w_multiline_replace_type_t replace_type = ML_REPLACE_TAB; - const char expected_retval[] = "tab"; - const char * retval = multiline_attr_replace_str(replace_type); - assert_string_equal(retval, expected_retval); -} - -/* multiline_attr_match_str */ -void test_multiline_attr_match_str_start(void ** state) { - w_multiline_match_type_t match_type = ML_MATCH_START; - const char expected_retval[] = "start"; - const char * retval = multiline_attr_match_str(match_type); - assert_string_equal(retval, expected_retval); -} - -void test_multiline_attr_match_str_all(void ** state) { - w_multiline_match_type_t match_type = ML_MATCH_ALL; - const char expected_retval[] = "all"; - const char * retval = multiline_attr_match_str(match_type); - assert_string_equal(retval, expected_retval); -} - -void test_multiline_attr_match_str_end(void ** state) { - w_multiline_match_type_t match_type = ML_MATCH_END; - const char expected_retval[] = "end"; - const char * retval = multiline_attr_match_str(match_type); - assert_string_equal(retval, expected_retval); -} - -/* w_get_attr_timeout */ -void test_w_get_attr_timeout_missing(void ** state) { - - unsigned int expect_retval = MULTI_LINE_REGEX_TIMEOUT; - unsigned int retval; - - will_return(__wrap_w_get_attr_val_by_name, NULL); - retval = w_get_attr_timeout(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_timeout_empty(void ** state) { - - unsigned int expect_retval = MULTI_LINE_REGEX_TIMEOUT; - unsigned int retval; - - will_return(__wrap_w_get_attr_val_by_name, ""); - expect_string(__wrap__mwarn, formatted_msg, - "(8000): Invalid value '' for attribute 'timeout' in " - "'multiline_regex' option. Default value will be used."); - retval = w_get_attr_timeout(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_timeout_not_number(void ** state) { - - unsigned int expect_retval = MULTI_LINE_REGEX_TIMEOUT; - unsigned int retval; - - will_return(__wrap_w_get_attr_val_by_name, "test"); - expect_string(__wrap__mwarn, formatted_msg, - "(8000): Invalid value 'test' for attribute 'timeout' in " - "'multiline_regex' option. Default value will be used."); - retval = w_get_attr_timeout(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_timeout_mixed(void ** state) { - - unsigned int expect_retval = MULTI_LINE_REGEX_TIMEOUT; - unsigned int retval; - - will_return(__wrap_w_get_attr_val_by_name, "11test11"); - expect_string(__wrap__mwarn, formatted_msg, - "(8000): Invalid value '11test11' for attribute 'timeout' in " - "'multiline_regex' option. Default value will be used."); - retval = w_get_attr_timeout(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_timeout_zero(void ** state) { - - unsigned int expect_retval = MULTI_LINE_REGEX_TIMEOUT; - unsigned int retval; - - will_return(__wrap_w_get_attr_val_by_name, "0"); - expect_string(__wrap__mwarn, formatted_msg, - "(8000): Invalid value '0' for attribute 'timeout' in " - "'multiline_regex' option. Default value will be used."); - retval = w_get_attr_timeout(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_timeout_out_range(void ** state) { - - unsigned int expect_retval = MULTI_LINE_REGEX_TIMEOUT; - unsigned int retval; - char str_timeout[10] = {0}; - char str_msg[300] = {0}; - - sprintf(str_timeout, "%i", MULTI_LINE_REGEX_MAX_TIMEOUT + 4); - sprintf(str_msg, "(8000): Invalid value '%s' for attribute 'timeout' in " - "'multiline_regex' option. Default value will be used.", str_timeout); - - will_return(__wrap_w_get_attr_val_by_name, str_timeout); - expect_string(__wrap__mwarn, formatted_msg, str_msg); - - retval = w_get_attr_timeout(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_timeout_out_ok(void ** state) { - - unsigned int expect_retval = 30; - unsigned int retval; - - will_return(__wrap_w_get_attr_val_by_name, "30"); - retval = w_get_attr_timeout(NULL); - - assert_int_equal(expect_retval, retval); -} - -// Test w_get_attr_replace -void test_w_get_attr_replace_missing(void ** state) { - - w_multiline_replace_type_t expect_retval = ML_REPLACE_NO_REPLACE; - w_multiline_replace_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, NULL); - retval = w_get_attr_replace(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_replace_no_replace(void ** state) { - - w_multiline_replace_type_t expect_retval = ML_REPLACE_NO_REPLACE; - w_multiline_replace_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "no-replace"); - retval = w_get_attr_replace(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_replace_ws(void ** state) { - - w_multiline_replace_type_t expect_retval = ML_REPLACE_WSPACE; - w_multiline_replace_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "wspace"); - retval = w_get_attr_replace(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_replace_tab(void ** state) { - - w_multiline_replace_type_t expect_retval = ML_REPLACE_TAB; - w_multiline_replace_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "tab"); - retval = w_get_attr_replace(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_replace_none(void ** state) { - - w_multiline_replace_type_t expect_retval = ML_REPLACE_NONE; - w_multiline_replace_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "none"); - retval = w_get_attr_replace(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_replace_invalid(void ** state) { - - w_multiline_replace_type_t expect_retval = ML_REPLACE_NO_REPLACE; - w_multiline_replace_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "invalid_attr"); - expect_string(__wrap__mwarn, formatted_msg, - "(8000): Invalid value 'invalid_attr' for attribute 'replace' in " - "'multiline_regex' option. Default value will be used."); - retval = w_get_attr_replace(NULL); - - assert_int_equal(expect_retval, retval); -} - -/* w_get_attr_match */ -void test_w_get_attr_match_invalid(void ** state) { - - w_multiline_match_type_t expect_retval = ML_MATCH_START; - w_multiline_match_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "invalid_attr"); - expect_string(__wrap__mwarn, formatted_msg, - "(8000): Invalid value 'invalid_attr' for attribute 'match' in " - "'multiline_regex' option. Default value will be used."); - retval = w_get_attr_match(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_match_missing(void ** state) { - - w_multiline_match_type_t expect_retval = ML_MATCH_START; - w_multiline_match_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, NULL); - retval = w_get_attr_match(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_match_start(void ** state) { - - w_multiline_match_type_t expect_retval = ML_MATCH_START; - w_multiline_match_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "start"); - retval = w_get_attr_match(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_match_all(void ** state) { - - w_multiline_match_type_t expect_retval = ML_MATCH_ALL; - w_multiline_match_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "all"); - retval = w_get_attr_match(NULL); - - assert_int_equal(expect_retval, retval); -} - -void test_w_get_attr_match_end(void ** state) { - - w_multiline_match_type_t expect_retval = ML_MATCH_END; - w_multiline_match_type_t retval; - - will_return(__wrap_w_get_attr_val_by_name, "end"); - retval = w_get_attr_match(NULL); - - assert_int_equal(expect_retval, retval); -} - -/* w_logcollector_get_macos_log_type */ -void test_w_logcollector_get_macos_log_type_content_NULL(void ** state) { - const char * content = NULL; - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, 0); -} - -void test_w_logcollector_get_macos_log_type_content_empty(void ** state) { - const char * content = ""; - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, 0); -} - -void test_w_logcollector_get_macos_log_type_content_ignore_values(void ** state) { - const char * content = " hello, ,world "; - - expect_string(__wrap__mwarn, formatted_msg, "(8003): Invalid value 'hello' for attribute 'type' in 'query' option."\ - " Attribute will be ignored."); - - expect_string(__wrap__mwarn, formatted_msg, "(8003): Invalid value 'world' for attribute 'type' in 'query' option."\ - " Attribute will be ignored."); - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, 0); -} - -void test_w_logcollector_get_macos_log_type_content_activity(void ** state) { - const char * content = " activity "; - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, MACOS_LOG_TYPE_ACTIVITY); -} - -void test_w_logcollector_get_macos_log_type_content_log(void ** state) { - const char * content = "log "; - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, MACOS_LOG_TYPE_LOG); -} - -void test_w_logcollector_get_macos_log_type_content_trace(void ** state) { - const char * content = " trace, "; - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, MACOS_LOG_TYPE_TRACE); -} - -void test_w_logcollector_get_macos_log_type_content_trace_activity(void ** state) { - const char * content = " trace, activity,,"; - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, MACOS_LOG_TYPE_TRACE | MACOS_LOG_TYPE_ACTIVITY); -} - -void test_w_logcollector_get_macos_log_type_content_trace_log_activity(void ** state) { - const char * content = " trace, ,activity,,log "; - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, MACOS_LOG_TYPE_TRACE | MACOS_LOG_TYPE_ACTIVITY | MACOS_LOG_TYPE_LOG); -} - -void test_w_logcollector_get_macos_log_type_content_log_multiword_invalid(void ** state) { - const char * content = "log, trace activity"; - - expect_string(__wrap__mwarn, formatted_msg, - "(8003): Invalid value 'trace activity' for attribute 'type' in 'query' option." - " Attribute will be ignored."); - - int ret = w_logcollector_get_macos_log_type(content); - assert_int_equal(ret, MACOS_LOG_TYPE_LOG); -} - -/* init_w_journal_log_config_t */ -void test_init_w_journal_log_config_t_ok(void ** state) { - w_journal_log_config_t * config = NULL; - bool ret = init_w_journal_log_config_t(&config); - assert_true(ret); - assert_non_null(config); - assert_false(config->disable_filters); - assert_null(config->filters); - os_free(config); -} - -void test_init_w_journal_log_config_t_fail(void ** state) { - w_journal_log_config_t * config = (w_journal_log_config_t *) 0x1; - bool ret = init_w_journal_log_config_t(&config); - assert_false(ret); - assert_non_null(config); -} - -/* w_journal_log_config_free */ -void test_w_journal_log_config_free_null(void ** state) { - w_journal_log_config_t * config = NULL; - - w_journal_log_config_free(NULL); - w_journal_log_config_free(&config); -} - -void test_w_journal_log_config_free_ok(void ** state) { - - w_journal_log_config_t * config = NULL; - - assert_true(init_w_journal_log_config_t(&config)); - w_journal_log_config_free(&config); -} - -/* free_unit_filter */ -void test_free_unit_filter_null(void ** state) { - _w_journal_filter_unit_t * ufilter = NULL; - free_unit_filter(ufilter); -} - -void test_free_unit_filter_ok(void ** state) { - _w_journal_filter_unit_t * ufilter = calloc(1, sizeof(_w_journal_filter_unit_t)); - ufilter->field = strdup("test"); - w_calloc_expression_t(&ufilter->exp, EXP_TYPE_PCRE2); - w_expression_compile(ufilter->exp, VALID_PCRE2_REGEX, 0); - - free_unit_filter(ufilter); -} - -/* create_unit_filter */ -void test_create_unit_filter_null_param(void ** state) { - - assert_null(create_unit_filter("field", NULL, false)); - assert_null(create_unit_filter(NULL, VALID_PCRE2_REGEX, false)); -} - -void test_create_unit_filter_inv_expresion(void ** state) { - - assert_null(create_unit_filter("fied", INVALID_PCRE2_REGEX, false)); -} - -void test_create_unit_filter_ok(void ** state) { - _w_journal_filter_unit_t * ufilter = create_unit_filter("fied_test", VALID_PCRE2_REGEX, true); - - assert_non_null(ufilter); - assert_true(ufilter->ignore_if_missing); - assert_string_equal(ufilter->exp->pcre2->raw_pattern, VALID_PCRE2_REGEX); - assert_string_equal(ufilter->field, "fied_test"); - - free_unit_filter(ufilter); -} - -/* unit_filter_as_json */ -void test_unit_filter_as_json_null_params(void ** state) { - - _w_journal_filter_unit_t unit = {.exp = NULL, .field = NULL, .ignore_if_missing = false}; - - assert_null(unit_filter_as_json(NULL)); - - assert_null(unit_filter_as_json(&unit)); - - unit.field = "test field"; - assert_null(unit_filter_as_json(&unit)); -} - -void test_unit_filter_as_json_ok(void ** state) { - - _w_journal_filter_unit_t unit = {.exp = NULL, .field = "test field", .ignore_if_missing = true}; - - w_calloc_expression_t(&unit.exp, EXP_TYPE_PCRE2); - w_expression_compile(unit.exp, VALID_PCRE2_REGEX, 0); - - will_return(__wrap_cJSON_CreateObject, (void *) 0x1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "field"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test field"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "expression"); - expect_string(__wrap_cJSON_AddStringToObject, string, VALID_PCRE2_REGEX); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *) 1); - - assert_non_null(unit_filter_as_json(&unit)); - - w_free_expression(unit.exp); -} - -/* w_journal_filter_add_condition */ -void test_w_journal_filter_add_condition_null_params(void ** state) { - w_journal_filter_t * filters = NULL; - assert_int_not_equal(0, w_journal_filter_add_condition(&filters, "field", NULL, false)); - assert_int_not_equal(0, w_journal_filter_add_condition(&filters, NULL, VALID_PCRE2_REGEX, false)); - assert_int_not_equal(0, w_journal_filter_add_condition(NULL, "field", VALID_PCRE2_REGEX, false)); -} - -void test_w_journal_filter_add_condition_bad_exp(void ** state) { - w_journal_filter_t * filters = NULL; - assert_int_not_equal(0, w_journal_filter_add_condition(&filters, "field", INVALID_PCRE2_REGEX, false)); -} - -void test_w_journal_filter_add_condition_ok_first_cond(void ** state) { - w_journal_filter_t * filters = NULL; - - assert_int_equal(0, w_journal_filter_add_condition(&filters, "field", VALID_PCRE2_REGEX, false)); - - assert_non_null(filters); - assert_int_equal(1, filters->units_size); - assert_non_null(filters->units); - assert_non_null(filters->units[0]); - assert_non_null(filters->units[0]->exp->pcre2->code); - assert_null(filters->units[1]); - - w_journal_filter_free(filters); // test w_journal_filter_free -} - -void test_w_journal_filter_add_condition_ok_other_cond(void ** state) { - - w_journal_filter_t * filters = NULL; - - assert_int_equal(0, w_journal_filter_add_condition(&filters, "field", VALID_PCRE2_REGEX, false)); - - assert_non_null(filters); - assert_int_equal(1, filters->units_size); - assert_non_null(filters->units); - assert_non_null(filters->units[0]); - assert_non_null(filters->units[0]->exp->pcre2->code); - assert_int_equal(filters->units[0]->ignore_if_missing, false); - assert_null(filters->units[1]); - - // Add second filter - assert_int_equal(0, w_journal_filter_add_condition(&filters, "field2", VALID_PCRE2_REGEX, true)); - - assert_int_equal(2, filters->units_size); - assert_non_null(filters->units); - assert_non_null(filters->units[0]); - assert_non_null(filters->units[0]->exp->pcre2->code); - assert_string_equal(filters->units[0]->field, "field"); - assert_non_null(filters->units[1]); - assert_non_null(filters->units[1]->exp->pcre2->code); - assert_int_equal(filters->units[1]->ignore_if_missing, true); - assert_string_equal(filters->units[1]->field, "field2"); - - assert_null(filters->units[2]); - - w_journal_filter_free(filters); // test w_journal_filter_free -} - -/* w_journal_filter_free */ -void test_w_journal_filter_free_null(void ** state) { w_journal_filter_free(NULL); } - -/* Test filter_as_json */ -void test_filter_as_json_null_params(void ** state) { - - w_journal_filter_t filter = {0}; - - assert_null(filter_as_json(NULL)); - assert_null(filter_as_json(&filter)); -} - -void test_filter_as_json_fail_array(void ** state) { - - w_journal_filter_t * filter = NULL; - - assert_int_equal(0, w_journal_filter_add_condition(&filter, "test field", VALID_PCRE2_REGEX, false)); - - will_return(__wrap_cJSON_CreateArray, (cJSON *) NULL); - - assert_null(filter_as_json(filter)); - - w_journal_filter_free(filter); -} - -void test_filter_as_json_one_unit(void ** state) { - - w_journal_filter_t * filter = NULL; - - assert_int_equal(0, w_journal_filter_add_condition(&filter, "test field", VALID_PCRE2_REGEX, false)); - - will_return(__wrap_cJSON_CreateArray, (cJSON *) 0x1); - - // start: unit filter as json - will_return(__wrap_cJSON_CreateObject, (void *) 0x1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "field"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test field"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "expression"); - expect_string(__wrap_cJSON_AddStringToObject, string, VALID_PCRE2_REGEX); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *) 1); - // end: unit filter as json - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - assert_non_null(filter_as_json(filter)); - - w_journal_filter_free(filter); -} - -/* w_journal_add_filter_to_list */ -void test_w_journal_add_filter_to_list_null_params(void ** state) { - - w_journal_filters_list_t list = NULL; - w_journal_filter_t filter; - assert_false(w_journal_add_filter_to_list(&list, NULL)); - assert_false(w_journal_add_filter_to_list(NULL, &filter)); -} - -void test_w_journal_add_filter_to_list_new_list(void ** state) { - - w_journal_filters_list_t list = NULL; - w_journal_filter_t filter = {0}; - - assert_true(w_journal_add_filter_to_list(&list, &filter)); - - assert_non_null(list); - assert_non_null(list[0]); - assert_ptr_equal(list[0], &filter); - assert_null(list[1]); - - os_free(list); -} - -void test_w_journal_add_filter_to_list_exist_list(void ** state) { - - w_journal_filters_list_t list = NULL; - w_journal_filter_t filter = {0}; - - assert_true(w_journal_add_filter_to_list(&list, &filter)); - - assert_non_null(list); - assert_non_null(list[0]); - assert_ptr_equal(list[0], &filter); - assert_null(list[1]); - - // Add second item - w_journal_filter_t filter2 = {0}; - assert_true(w_journal_add_filter_to_list(&list, &filter2)); - - assert_non_null(list[0]); - assert_ptr_equal(list[0], &filter); - assert_non_null(list[1]); - assert_ptr_equal(list[1], &filter2); - assert_null(list[2]); - - os_free(list); -} - -// Test w_journal_filter_list_as_json -void test_w_journal_filter_list_as_json_null_params(void ** state) { assert_null(w_journal_filter_list_as_json(NULL)); } - -void test_w_journal_filter_list_as_json_fail_array(void ** state) { - - w_journal_filters_list_t list = NULL; - - // Prepare the filter - w_journal_filter_t * filter = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&filter, "test field", VALID_PCRE2_REGEX, false)); - // Add filter to the list - assert_true(w_journal_add_filter_to_list(&list, filter)); - - // Print the list - // start: Print as json - will_return(__wrap_cJSON_CreateArray, (cJSON *) NULL); - assert_null(w_journal_filter_list_as_json(list)); - - w_journal_filters_list_free(list); // Test w_journal_filters_list_free -} - -void test_w_journal_filter_list_as_json_success(void ** state) { - - w_journal_filters_list_t list = NULL; - - // Prepare the filter - w_journal_filter_t * filter = NULL; - assert_int_equal(0, w_journal_filter_add_condition(&filter, "test field", VALID_PCRE2_REGEX, false)); - // Add filter to the list - assert_true(w_journal_add_filter_to_list(&list, filter)); - - // Print the list - - // start: Print as json - will_return(__wrap_cJSON_CreateArray, (cJSON *) 0x1); - - // - filter_as_json - will_return(__wrap_cJSON_CreateArray, (cJSON *) 0x1); - // - - unit_filter_as_json - will_return(__wrap_cJSON_CreateObject, (void *) 0x1); - expect_string(__wrap_cJSON_AddStringToObject, name, "field"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test field"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "expression"); - expect_string(__wrap_cJSON_AddStringToObject, string, VALID_PCRE2_REGEX); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 1); - will_return(__wrap_cJSON_AddBoolToObject, (cJSON *) 1); - // - end: filter_as_json - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - assert_non_null(w_journal_filter_list_as_json(list)); - - w_journal_filters_list_free(list); // Test w_journal_filters_list_free -} - -// ------------------------------------------------ -/* journald_add_condition_to_filter */ -void test_journald_add_condition_to_filter_invalid_params(void ** state) { - - assert_false(journald_add_condition_to_filter(NULL, NULL)); - assert_false(journald_add_condition_to_filter(NULL, (w_journal_filter_t **) 0x1)); - assert_false(journald_add_condition_to_filter((xml_node *) 0x1, NULL)); -} - -void test_journald_add_condition_to_filter_non_field(void ** state) { - - xml_node node = {0}; - char * node_content = "regex xml content"; - node.content = node_content; - - w_journal_filter_t * filter = NULL; - - // Null field - will_return(__wrap_w_get_attr_val_by_name, NULL); - expect_string(__wrap__mwarn, formatted_msg, "(8019): The field for the journal filter cannot be empty."); - - assert_false(journald_add_condition_to_filter(&node, &filter)); -} - -void test_journald_add_condition_to_filter_empty_field(void ** state) { - - xml_node node = {0}; - char * node_content = "regex xml content"; - node.content = node_content; - - w_journal_filter_t * filter = NULL; - - // Null field - will_return(__wrap_w_get_attr_val_by_name, ""); - expect_string(__wrap__mwarn, formatted_msg, "(8019): The field for the journal filter cannot be empty."); - - assert_false(journald_add_condition_to_filter(&node, &filter)); -} - -void test_journald_add_condition_to_filter_empty_regex(void ** state) { - - xml_node node = {0}; - char * node_content = ""; - node.content = node_content; - - w_journal_filter_t * filter = NULL; - - // Null field - will_return(__wrap_w_get_attr_val_by_name, "field"); - expect_string(__wrap__mwarn, formatted_msg, "(8020): The expression for the journal filter cannot be empty."); - - assert_false(journald_add_condition_to_filter(&node, &filter)); -} - -void test_journald_add_condition_to_filter_null_regex(void ** state) { - - xml_node node = {0}; - node.content = NULL; - - w_journal_filter_t * filter = NULL; - - // Null field - will_return(__wrap_w_get_attr_val_by_name, "field"); - expect_string(__wrap__mwarn, formatted_msg, "(8020): The expression for the journal filter cannot be empty."); - - assert_false(journald_add_condition_to_filter(&node, &filter)); -} - -void test_journald_add_condition_to_filter_ingore_no(void ** state) { - - xml_node node = {0}; - node.content = VALID_PCRE2_REGEX; - - w_journal_filter_t * filter = NULL; - - will_return(__wrap_w_get_attr_val_by_name, "field"); - will_return(__wrap_w_get_attr_val_by_name, "no"); - - // w_journal_filter_add_condition ok - assert_true(journald_add_condition_to_filter(&node, &filter)); - - assert_non_null(filter); - assert_int_equal(filter->units_size, 1); - assert_non_null(filter->units); - assert_non_null(filter->units[0]); - assert_string_equal(filter->units[0]->exp->pcre2->raw_pattern, VALID_PCRE2_REGEX); - assert_string_equal(filter->units[0]->field, "field"); - assert_false(filter->units[0]->ignore_if_missing); - assert_null(filter->units[1]); - - w_journal_filter_free(filter); -} - -void test_journald_add_condition_to_filter_ingore_missing(void ** state) { - - xml_node node = {0}; - node.content = VALID_PCRE2_REGEX; - - w_journal_filter_t * filter = NULL; - - will_return(__wrap_w_get_attr_val_by_name, "field"); - will_return(__wrap_w_get_attr_val_by_name, NULL); - - // w_journal_filter_add_condition ok - assert_true(journald_add_condition_to_filter(&node, &filter)); - - assert_non_null(filter); - assert_int_equal(filter->units_size, 1); - assert_non_null(filter->units); - assert_non_null(filter->units[0]); - assert_string_equal(filter->units[0]->exp->pcre2->raw_pattern, VALID_PCRE2_REGEX); - assert_string_equal(filter->units[0]->field, "field"); - assert_false(filter->units[0]->ignore_if_missing); - assert_null(filter->units[1]); - - w_journal_filter_free(filter); -} - -void test_journald_add_condition_to_filter_ingore_wrong(void ** state) { - - xml_node node = {0}; - node.content = VALID_PCRE2_REGEX; - - w_journal_filter_t * filter = NULL; - - will_return(__wrap_w_get_attr_val_by_name, "field"); - will_return(__wrap_w_get_attr_val_by_name, "bad attribute"); - expect_string(__wrap__mwarn, - formatted_msg, - "(8000): Invalid value 'bad attribute' for attribute 'ignore_if_missing' in 'journal' option. " - "Default value will be used."); - - // w_journal_filter_add_condition ok - assert_true(journald_add_condition_to_filter(&node, &filter)); - - assert_non_null(filter); - assert_int_equal(filter->units_size, 1); - assert_non_null(filter->units); - assert_non_null(filter->units[0]); - assert_string_equal(filter->units[0]->exp->pcre2->raw_pattern, VALID_PCRE2_REGEX); - assert_string_equal(filter->units[0]->field, "field"); - assert_false(filter->units[0]->ignore_if_missing); - assert_null(filter->units[1]); - - w_journal_filter_free(filter); -} - -void test_journald_add_condition_to_filter_ingore_yes(void ** state) { - - xml_node node = {0}; - node.content = VALID_PCRE2_REGEX; - - w_journal_filter_t * filter = NULL; - - will_return(__wrap_w_get_attr_val_by_name, "field"); - will_return(__wrap_w_get_attr_val_by_name, "yes"); - - // w_journal_filter_add_condition ok - assert_true(journald_add_condition_to_filter(&node, &filter)); - - assert_non_null(filter); - assert_int_equal(filter->units_size, 1); - assert_non_null(filter->units); - assert_non_null(filter->units[0]); - assert_string_equal(filter->units[0]->exp->pcre2->raw_pattern, VALID_PCRE2_REGEX); - assert_string_equal(filter->units[0]->field, "field"); - assert_true(filter->units[0]->ignore_if_missing); - assert_null(filter->units[1]); - - w_journal_filter_free(filter); -} - -void test_journald_add_condition_to_filter_fail_regex(void ** state) { - - xml_node node = {0}; - node.content = INVALID_PCRE2_REGEX; - - w_journal_filter_t * filter = NULL; - - will_return(__wrap_w_get_attr_val_by_name, "field"); - will_return(__wrap_w_get_attr_val_by_name, "no"); - - expect_string( - __wrap__mwarn, - formatted_msg, - "(8021): Error compiling the PCRE2 expression 'invalid regex [a \\w+{-1' for field 'field' in journal filter."); - // w_journal_filter_add_condition fail - assert_false(journald_add_condition_to_filter(&node, &filter)); -} - -/* w_multiline_log_config_free */ -void test_w_multiline_log_config_free_null(void **state) -{ - w_multiline_log_config_free(NULL); - - w_multiline_config_t *config = NULL; - w_multiline_log_config_free(&config); -} - -void test_w_multiline_log_config_free_success(void ** state) { - w_multiline_config_t * config = NULL; - os_calloc(1, sizeof(w_multiline_config_t), config); - - // Set a valid config - - // Regex config - w_calloc_expression_t(&config->regex, EXP_TYPE_PCRE2); - assert_true(w_expression_compile(config->regex, "valid regex .*", 0)); - - // collector config - config->match_type = ML_MATCH_START; - config->replace_type = ML_REPLACE_NO_REPLACE; - config->timeout = 10; - - // Simulate non-empty ctxt - os_calloc(1, sizeof(w_multiline_ctxt_t), config->ctxt); - os_calloc(100, sizeof(char), config->ctxt->buffer); - - w_multiline_log_config_free(&config); - assert_null(config); -} - -// Test w_multiline_log_config_clone -void test_w_multiline_log_config_clone_null(void ** state) { - assert_null(w_multiline_log_config_clone(NULL)); -} - -void test_w_multiline_log_config_clone_success(void ** state) { - - - w_multiline_config_t * config = NULL; - os_calloc(1, sizeof(w_multiline_config_t), config); - - // Set a valid config - w_calloc_expression_t(&config->regex, EXP_TYPE_PCRE2); - assert_true(w_expression_compile(config->regex, "valid regex .*", 0)); - - // collector config - config->match_type = ML_MATCH_END; - config->replace_type = ML_REPLACE_NONE; - config->timeout = 10; - - // Simulate non-empty ctxt - os_calloc(1, sizeof(w_multiline_ctxt_t), config->ctxt); - os_calloc(100, sizeof(char), config->ctxt->buffer); - - - // Test clone - w_multiline_config_t * cloned_config = w_multiline_log_config_clone(config); - w_multiline_log_config_free(&config); - - // Checks - assert_non_null(cloned_config); - assert_non_null(cloned_config->regex); - assert_string_equal(w_expression_get_regex_pattern(cloned_config->regex), "valid regex .*"); - - assert_int_equal(cloned_config->match_type, ML_MATCH_END); - assert_int_equal(cloned_config->replace_type, ML_REPLACE_NONE); - assert_int_equal(cloned_config->timeout, 10); - - assert_null(cloned_config->ctxt); // Should be a empty context - - w_multiline_log_config_free(&cloned_config); - -} - -/* main */ - -int main(void) { - const struct CMUnitTest tests[] = { - // Tests replace_char - cmocka_unit_test(test_multiline_attr_match_str_start), - cmocka_unit_test(test_multiline_attr_match_str_all), - cmocka_unit_test(test_multiline_attr_match_str_end), - // Tests multiline_attr_replace_str - cmocka_unit_test(test_multiline_attr_replace_str_no_replace), - cmocka_unit_test(test_multiline_attr_replace_str_none), - cmocka_unit_test(test_multiline_attr_replace_str_ws), - cmocka_unit_test(test_multiline_attr_replace_str_tab), - // Tests w_get_attr_timeout - cmocka_unit_test(test_w_get_attr_timeout_missing), - cmocka_unit_test(test_w_get_attr_timeout_empty), - cmocka_unit_test(test_w_get_attr_timeout_zero), - cmocka_unit_test(test_w_get_attr_timeout_not_number), - cmocka_unit_test(test_w_get_attr_timeout_mixed), - cmocka_unit_test(test_w_get_attr_timeout_out_range), - cmocka_unit_test(test_w_get_attr_timeout_out_ok), - // Tests w_get_attr_replace - cmocka_unit_test(test_w_get_attr_replace_missing), - cmocka_unit_test(test_w_get_attr_replace_no_replace), - cmocka_unit_test(test_w_get_attr_replace_ws), - cmocka_unit_test(test_w_get_attr_replace_tab), - cmocka_unit_test(test_w_get_attr_replace_none), - cmocka_unit_test(test_w_get_attr_replace_invalid), - // Tests w_get_attr_match - cmocka_unit_test(test_w_get_attr_match_missing), - cmocka_unit_test(test_w_get_attr_match_start), - cmocka_unit_test(test_w_get_attr_match_all), - cmocka_unit_test(test_w_get_attr_match_end), - cmocka_unit_test(test_w_get_attr_match_invalid), - // Tests w_logcollector_get_macos_log_type - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_NULL), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_empty), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_ignore_values), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_activity), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_log), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_trace), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_trace_activity), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_trace_log_activity), - cmocka_unit_test(test_w_logcollector_get_macos_log_type_content_log_multiword_invalid), - // Test init_w_journal_log_config_t - cmocka_unit_test(test_init_w_journal_log_config_t_fail), - cmocka_unit_test(test_init_w_journal_log_config_t_ok), - // Test w_journal_log_config_free - cmocka_unit_test(test_w_journal_log_config_free_null), - cmocka_unit_test(test_w_journal_log_config_free_ok), - // Test free_unit_filter - cmocka_unit_test(test_free_unit_filter_null), - cmocka_unit_test(test_free_unit_filter_ok), - // Test create_unit_filter - cmocka_unit_test(test_create_unit_filter_null_param), - cmocka_unit_test(test_create_unit_filter_inv_expresion), - cmocka_unit_test(test_create_unit_filter_ok), - // Test unit_filter_as_json - cmocka_unit_test(test_unit_filter_as_json_null_params), - cmocka_unit_test(test_unit_filter_as_json_ok), - // Test w_journal_filter_add_condition - cmocka_unit_test(test_w_journal_filter_add_condition_null_params), - cmocka_unit_test(test_w_journal_filter_add_condition_bad_exp), - cmocka_unit_test(test_w_journal_filter_add_condition_ok_first_cond), - cmocka_unit_test(test_w_journal_filter_add_condition_ok_other_cond), - // Test w_journal_filter_add_condition w_journal_filter_free - cmocka_unit_test(test_w_journal_filter_free_null), - // Test filter_as_json - cmocka_unit_test(test_filter_as_json_null_params), - cmocka_unit_test(test_filter_as_json_fail_array), - cmocka_unit_test(test_filter_as_json_one_unit), - // Test w_journal_add_filter_to_list - cmocka_unit_test(test_w_journal_add_filter_to_list_null_params), - cmocka_unit_test(test_w_journal_add_filter_to_list_new_list), - cmocka_unit_test(test_w_journal_add_filter_to_list_exist_list), - // Test w_journal_filter_list_as_json - cmocka_unit_test(test_w_journal_filter_list_as_json_null_params), - cmocka_unit_test(test_w_journal_filter_list_as_json_fail_array), - cmocka_unit_test(test_w_journal_filter_list_as_json_success), - // Test journald_add_condition_to_filter - cmocka_unit_test(test_journald_add_condition_to_filter_invalid_params), - cmocka_unit_test(test_journald_add_condition_to_filter_non_field), - cmocka_unit_test(test_journald_add_condition_to_filter_empty_field), - cmocka_unit_test(test_journald_add_condition_to_filter_empty_regex), - cmocka_unit_test(test_journald_add_condition_to_filter_null_regex), - cmocka_unit_test(test_journald_add_condition_to_filter_ingore_no), - cmocka_unit_test(test_journald_add_condition_to_filter_ingore_missing), - cmocka_unit_test(test_journald_add_condition_to_filter_ingore_wrong), - cmocka_unit_test(test_journald_add_condition_to_filter_ingore_yes), - cmocka_unit_test(test_journald_add_condition_to_filter_fail_regex), - // Test w_multiline_log_config_free - cmocka_unit_test(test_w_multiline_log_config_free_null), - cmocka_unit_test(test_w_multiline_log_config_free_success), - // Test w_multiline_log_config_clone - cmocka_unit_test(test_w_multiline_log_config_clone_null), - cmocka_unit_test(test_w_multiline_log_config_clone_success), - - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); - //return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/logcollector/test_logcollector.c b/src/unit_tests/logcollector/test_logcollector.c deleted file mode 100644 index b0de0c08682..00000000000 --- a/src/unit_tests/logcollector/test_logcollector.c +++ /dev/null @@ -1,2786 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../logcollector/logcollector.h" -#include -#include -#include "../../os_crypto/sha1/sha1_op.h" - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/wazuh/os_crypto/sha1_op_wrappers.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/posix/signal_wrappers.h" - - -extern OSHash *files_status; - -bool w_get_hash_context(logreader *lf, EVP_MD_CTX **context, int64_t position); -ssize_t w_set_to_pos(logreader *lf, long pos, int mode); -char * w_save_files_status_to_cJSON(); -void w_save_file_status(); -void w_load_files_status(cJSON *global_json); -void w_initialize_file_status(); -int w_update_hash_node(char * path, int64_t pos); -int w_set_to_last_line_read(logreader *lf); -void free_files_status_data(os_file_status_t *data); - -// Auxiliar structs -typedef struct test_logcollector_s { - logreader *log_reader; - EVP_MD_CTX *context; - os_file_status_t *status; - OSHashNode *node; -} test_logcollector_t; - -extern w_macos_log_vault_t macos_log_vault; -extern w_macos_log_procceses_t * macos_processes; -static wfd_t * stream_backup; -static wfd_t * show_backup; - -// Aux functions -void set_gs_journald_ofe(bool exist, bool ofe, uint64_t timestamp); - -/* setup/teardown */ - -static int setup_group(void **state) { - test_mode = 1; - macos_log_vault.is_valid_data = true; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - -void free_os_file_status_t_struct(os_file_status_t *data) { - EVP_MD_CTX_free(data->context); - os_free(data); -} - -static int setup_local_hashmap(void **state) { - if (setup_hashmap(state) != 0) { - return 1; - } - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))free_os_file_status_t_struct); - files_status = mock_hashmap; - return 0; -} - -static int teardown_local_hashmap(void **state) { - if (teardown_hashmap(state) != 0) { - return 1; - } - return 0; -} - -static int setup_log_context(void **state) { - if (setup_local_hashmap(state) != 0) { - return 1; - } - - test_logcollector_t *test_struct = calloc(1, sizeof(test_logcollector_t)); - if (test_struct == NULL) { - return 1; - } - - test_struct->log_reader = calloc(1, sizeof(logreader)); - test_struct->context = EVP_MD_CTX_new(); - test_struct->status = calloc(1, sizeof(os_file_status_t)); - test_struct->node = calloc(1, sizeof(OSHashNode)); - - if (test_struct->log_reader == NULL || test_struct->context == NULL || test_struct->status == NULL || - test_struct->node == NULL) { - return 1; - } - - test_struct->log_reader->fp = (FILE *) 1; - *state = test_struct; - return 0; -} - -static int teardown_log_context(void **state) { - if (teardown_local_hashmap(state) != 0) { - return 1; - } - test_logcollector_t * test_struct = *state; - - expect_any(__wrap_fclose, _File); - will_return_always(__wrap_fclose, 0); - Free_Logreader(test_struct->log_reader); - - free(test_struct->log_reader); - EVP_MD_CTX_free(test_struct->context); - free(test_struct->status); - free(test_struct->node); - free(test_struct); - - return 0; -} - -static int setup_process(void **state) { - w_macos_log_procceses_t * local_macos_processes = calloc(1, sizeof(w_macos_log_procceses_t)); - os_calloc(1, sizeof(wfd_t), local_macos_processes->show.wfd); - os_calloc(1, sizeof(wfd_t), local_macos_processes->stream.wfd); - stream_backup = local_macos_processes->stream.wfd; - show_backup = local_macos_processes->show.wfd; - *state = local_macos_processes; - - return 0; -} - -static int teardown_process(void **state) { - w_macos_log_procceses_t * local_macos_processes = *state; - - os_free(stream_backup); - os_free(show_backup); - os_free(local_macos_processes); - - return 0; -} - -static int setup_regex(void **state) { - logreader *regex_config = calloc(1, sizeof(logreader)); - regex_config->regex_ignore = NULL; - regex_config->regex_restrict = NULL; - - regex_config->regex_ignore = OSList_Create(); - if (regex_config->regex_ignore == NULL) { - merror(MEM_ERROR, errno, strerror(errno)); - return -1; - } - OSList_SetFreeDataPointer(regex_config->regex_ignore, (void (*)(void *))w_free_expression); - - regex_config->regex_restrict = OSList_Create(); - if (regex_config->regex_restrict == NULL) { - merror(MEM_ERROR, errno, strerror(errno)); - return -1; - } - OSList_SetFreeDataPointer(regex_config->regex_restrict, (void (*)(void *))w_free_expression); - - *state = regex_config; - - return 0; -} - -static int teardown_regex(void **state) { - logreader *regex_config = *state; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - if (regex_config->regex_ignore) { - OSList_Destroy(regex_config->regex_ignore); - regex_config->regex_ignore = NULL; - } - if (regex_config->regex_restrict) { - OSList_Destroy(regex_config->regex_restrict); - regex_config->regex_restrict = NULL; - } - - os_free(regex_config); - - return 0; -} - -/* wraps */ - -/* tests */ - -/* w_get_hash_context */ - -void test_w_get_hash_context_NULL_file_exist(void ** state) { - EVP_MD_CTX *context = NULL; - int64_t position = 10; - test_logcollector_t *test_struct = *state; - - logreader *lf = test_struct->log_reader; - - lf->file = strdup("/test_path"); - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, lf->file); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_string(__wrap_OS_SHA1_File_Nbytes_with_fp_check, fname, lf->file); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, mode, OS_BINARY); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, nbytes, position); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, fd_check, 0); - will_return(__wrap_OS_SHA1_File_Nbytes_with_fp_check, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes_with_fp_check, 0); - - bool ret = w_get_hash_context(lf, &context, position); - - assert_true(ret); -} - -void test_w_get_hash_context_NULL_file_not_exist(void ** state) { - EVP_MD_CTX *context = EVP_MD_CTX_new(); - int64_t position = 10; - test_logcollector_t *test_struct = *state; - logreader *lf = test_struct->log_reader; - - lf->file = strdup("/test_path"); - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, lf->file); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_string(__wrap_OS_SHA1_File_Nbytes_with_fp_check, fname, lf->file); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, mode, OS_BINARY); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, nbytes, position); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, fd_check, 0); - will_return(__wrap_OS_SHA1_File_Nbytes_with_fp_check, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes_with_fp_check, -1); - - bool ret = w_get_hash_context (lf, &context, position); - EVP_MD_CTX_free(context); - assert_false(ret); -} - -void test_w_get_hash_context_done(void ** state) { - int64_t position = 10; - test_logcollector_t *test_struct = *state; - - logreader *lf = test_struct->log_reader; - EVP_MD_CTX *context = test_struct->context; - os_file_status_t *data = test_struct->status; - - lf->file = strdup("/test_path"); - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, lf->file); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_string(__wrap_OS_SHA1_File_Nbytes_with_fp_check, fname, lf->file); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, mode, OS_BINARY); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, nbytes, position); - expect_value(__wrap_OS_SHA1_File_Nbytes_with_fp_check, fd_check, 0); - will_return(__wrap_OS_SHA1_File_Nbytes_with_fp_check, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes_with_fp_check, -1); - - bool ret = w_get_hash_context (lf, &context, position); - - assert_false(ret); -} - -/* w_update_file_status */ -void test_w_update_file_status_fail_update_add_table_hash(void ** state) { - char * path = "test/test.log"; - long pos = 0; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - - expect_value(__wrap_OS_SHA1_Stream, buf, NULL); - will_return(__wrap_OS_SHA1_Stream, "a7a899f25aeda32989d1029839ef2e594835c211"); - - will_return(__wrap_OSHash_Update_ex, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, files_status); - expect_string(__wrap_OSHash_Add_ex, key, path); - will_return(__wrap_OSHash_Add_ex, 0); - - int retval = w_update_file_status(path, pos, context); - - assert_int_equal(retval,-1); -} - -void test_w_update_file_status_update_fail_add_OK(void ** state) { - - char * path = "test/test.log"; - long pos = 0; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - - expect_value(__wrap_OS_SHA1_Stream, buf, NULL); - will_return(__wrap_OS_SHA1_Stream, "a7a899f25aeda32989d1029839ef2e594835c211"); - - will_return(__wrap_OSHash_Update_ex, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, files_status); - expect_string(__wrap_OSHash_Add_ex, key, path); - will_return(__wrap_OSHash_Add_ex, 2); - - int retval = w_update_file_status(path, pos, context); - - assert_int_equal(retval,0); - -} - -void test_w_update_file_status_update_OK(void ** state) { - char * path = "test/test.log"; - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - os_file_status_t * data; - os_malloc(sizeof(os_file_status_t), data); - data->context = EVP_MD_CTX_new(); - - __real_OSHash_Add_ex(mock_hashmap, path, data); - - long pos = 0; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - - expect_value(__wrap_OS_SHA1_Stream, buf, NULL); - will_return(__wrap_OS_SHA1_Stream, "a7a899f25aeda32989d1029839ef2e594835c211"); - - will_return(__wrap_OSHash_Update_ex, 1); - - int retval = w_update_file_status(path, pos, context); - - assert_int_equal(retval,0);; -} - -/* w_set_to_pos */ - -void test_w_set_to_pos_localfile_NULL(void ** state) { - logreader *lf = NULL; - long pos = 0; - int mode = OS_BINARY; - - int retval = w_set_to_pos(lf, pos, mode); - - assert_int_equal(retval, -1); - -} - -void test_w_set_to_pos_fseek_error(void ** state) { - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - lf->fp = (FILE*)1; - os_strdup("test", lf->file); - long pos = 0; - int mode = OS_BINARY; - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, -1); - - expect_string(__wrap__merror, formatted_msg, "(1116): Could not set position in file 'test' due to [(0)-(Success)]."); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 1); - - int retval = w_set_to_pos(lf, pos, mode); - - assert_int_equal(retval, -1); - - os_free(lf->file); - os_free(lf->fp); - os_free(lf); -} - -void test_w_set_to_pos_OK(void ** state) { - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - lf->fp = (FILE*)1; - os_strdup("test", lf->file); - long pos = 0; - int mode = OS_BINARY; - fpos_t position_stack = {.__pos = 1}; - test_position = &position_stack; - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, 0); - - expect_value(__wrap_w_ftell, x, 1); - will_return(__wrap_w_ftell, 1); - - ssize_t retval = w_set_to_pos(lf, pos, mode); - - assert_int_equal(retval, 1); - - os_free(lf->file); - os_free(lf); -} - -/* w_save_files_status_to_cJSON */ - -void test_w_save_files_status_to_cJSON_begin_NULL(void ** state) { - OSHashNode *hash_node = NULL; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - char * ret = w_save_files_status_to_cJSON(); - assert_null(ret); -} - -void test_w_save_files_status_to_cJSON_OK(void ** state) { - test_logcollector_t *test_data = *state; - - os_file_status_t * data = test_data->status; - OSHashNode *hash_node = test_data->node; - - strcpy(data->hash,"test1234"); - data->offset = 5; - - hash_node->key = "test"; - hash_node->data = data; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddArrayToObject, name, "files"); - will_return(__wrap_cJSON_AddArrayToObject, (cJSON *) 1); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "path"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "hash"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test1234"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "offset"); - expect_string(__wrap_cJSON_AddStringToObject, string, "5"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - expect_value(__wrap_OSHash_Next, self, files_status); - will_return(__wrap_OSHash_Next, NULL); - - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_cJSON_PrintUnformatted, "test_1234"); - - expect_function_call(__wrap_cJSON_Delete); - - char * ret = w_save_files_status_to_cJSON(); - - assert_string_equal(ret, "test_1234"); -} - -void test_w_save_files_status_to_cJSON_macos_invalid_vault(void ** state) { - test_mode = 1; - - OSHashNode *hash_node = NULL; - - strcpy(macos_log_vault.timestamp,"any timestamp"); - macos_log_vault.settings = "my settings"; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - char * ret = w_save_files_status_to_cJSON(); - assert_null(ret); - -} - -void test_w_save_files_status_to_cJSON_macos_valid_vault(void ** state) { - test_mode = 1; - - OSHashNode *hash_node = NULL; - w_macos_log_procceses_t * bak_macos_processes = macos_processes; - macos_processes = (w_macos_log_procceses_t *) 1; - - strcpy(macos_log_vault.timestamp,"2021-04-27 08:07:20-0700"); - macos_log_vault.settings = "/usr/bin/log stream --style syslog"; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_CreateString, string, "2021-04-27 08:07:20-0700"); - will_return(__wrap_cJSON_CreateString, (cJSON *) 1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_CreateString, string, "/usr/bin/log stream --style syslog"); - will_return(__wrap_cJSON_CreateString, (cJSON *) 1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - will_return(__wrap_cJSON_PrintUnformatted, "test_1234"); - - expect_function_call(__wrap_cJSON_Delete); - - char * ret = w_save_files_status_to_cJSON(); - - assert_string_equal(ret, "test_1234"); - macos_processes = bak_macos_processes; - -} - -void test_w_save_files_status_to_cJSON_journal_valid(void ** state) { - test_mode = 1; - - OSHashNode * hash_node = NULL; - - strcpy(macos_log_vault.timestamp, "any timestamp"); - macos_log_vault.settings = "my settings"; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - // Set journald - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "timestamp"); - expect_string(__wrap_cJSON_AddStringToObject, string, "123456"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *) 2); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 3); - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - will_return(__wrap_cJSON_PrintUnformatted, "test_1234"); - expect_function_call(__wrap_cJSON_Delete); - - set_gs_journald_ofe(true, false, 123456); - - assert_non_null(w_save_files_status_to_cJSON()); - - set_gs_journald_ofe(false, true, 0); -} - -void test_w_save_files_status_invalid_vault(void ** state) { - - test_mode = 1; - bool back_valid_json = macos_log_vault.is_valid_data; - macos_log_vault.is_valid_data = false; - - OSHashNode *hash_node = NULL; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - char * ret = w_save_files_status_to_cJSON(); - assert_null(ret); - assert_false(macos_log_vault.is_valid_data); - macos_log_vault.is_valid_data = back_valid_json; - -} - -void test_w_save_files_status_to_cJSON_data(void ** state) { - test_mode = 1; - - w_macos_log_procceses_t * bak_macos_processes = macos_processes; - macos_processes = (w_macos_log_procceses_t *) 1; - os_file_status_t * data; - os_calloc(1, sizeof(os_file_status_t), data); - strcpy(data->hash,"test1234"); - data->offset = 5; - - OSHashNode *hash_node = NULL; - os_calloc(1, sizeof(OSHashNode), hash_node); - hash_node->key = "test"; - hash_node->data = data; - - strcpy(macos_log_vault.timestamp,"2021-04-27 08:07:20-0700"); - macos_log_vault.settings = "/usr/bin/log stream --style syslog"; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddArrayToObject, name, "files"); - will_return(__wrap_cJSON_AddArrayToObject, (cJSON *) 1); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "path"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "hash"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test1234"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "offset"); - expect_string(__wrap_cJSON_AddStringToObject, string, "5"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - expect_value(__wrap_OSHash_Next, self, files_status); - will_return(__wrap_OSHash_Next, NULL); - - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_CreateString, string, "2021-04-27 08:07:20-0700"); - will_return(__wrap_cJSON_CreateString, (cJSON *) 1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_string(__wrap_cJSON_CreateString, string, "/usr/bin/log stream --style syslog"); - will_return(__wrap_cJSON_CreateString, (cJSON *) 1); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_cJSON_AddItemToObject, true); - - will_return(__wrap_cJSON_PrintUnformatted, "test_1234"); - - expect_function_call(__wrap_cJSON_Delete); - - char * ret = w_save_files_status_to_cJSON(); - - assert_string_equal(ret, "test_1234"); - macos_processes = bak_macos_processes; - os_free(data); - os_free(hash_node); - -} - -/* w_save_file_status */ - -void test_w_save_file_status_str_NULL(void ** state) { - OSHashNode *hash_node = NULL; - strcpy(macos_log_vault.timestamp,"any timestamp"); - macos_log_vault.settings = "my settings"; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - w_save_file_status(); - -} - - -void test_w_save_file_status_wfopen_error(void ** state) { - test_logcollector_t *test_data = *state; - - os_file_status_t * data = test_data->status; - OSHashNode *hash_node = test_data->node; - - strcpy(data->hash,"test1234"); - data->offset = 5; - - hash_node->key = "test"; - hash_node->data = data; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddArrayToObject, name, "files"); - will_return(__wrap_cJSON_AddArrayToObject, (cJSON *) 1); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "path"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "hash"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test1234"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "offset"); - expect_string(__wrap_cJSON_AddStringToObject, string, "5"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - expect_value(__wrap_OSHash_Next, self, files_status); - will_return(__wrap_OSHash_Next, NULL); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_cJSON_PrintUnformatted, "test_1234"); - - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap_wfopen, path, "queue/logcollector/file_status.json"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 0); - - expect_string(__wrap__merror_exit, formatted_msg, "(1103): Could not open file 'queue/logcollector/file_status.json' due to [(0)-(Success)]."); - expect_assert_failure(w_save_file_status()); -} - -void test_w_save_file_status_fwrite_error(void ** state) { - test_logcollector_t *test_data = *state; - - os_file_status_t * data = test_data->status; - OSHashNode *hash_node = test_data->node; - - strcpy(data->hash,"test1234"); - data->offset = 5; - - hash_node->key = "test"; - hash_node->data = data; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddArrayToObject, name, "files"); - will_return(__wrap_cJSON_AddArrayToObject, (cJSON *) 1); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "path"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "hash"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test1234"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "offset"); - expect_string(__wrap_cJSON_AddStringToObject, string, "5"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - expect_value(__wrap_OSHash_Next, self, files_status); - will_return(__wrap_OSHash_Next, NULL); - - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_cJSON_PrintUnformatted, strdup("test_1234")); - - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap_wfopen, path, "queue/logcollector/file_status.json"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, "test"); - - will_return(__wrap_fwrite, 0); - - expect_string(__wrap__merror, formatted_msg, "(1110): Could not write file 'queue/logcollector/file_status.json' due to [(0)-(Success)]."); - - expect_function_call(__wrap_clearerr); - expect_string(__wrap_clearerr, __stream, "test"); - - expect_value(__wrap_fclose, _File, "test"); - will_return(__wrap_fclose, 1); - - w_save_file_status(); -} - -void test_w_save_file_status_OK(void ** state) { - test_logcollector_t *test_data = *state; - - os_file_status_t * data = test_data->status; - OSHashNode *hash_node = test_data->node; - - strcpy(data->hash,"test1234"); - data->offset = 5; - - hash_node->key = "test"; - hash_node->data = data; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - expect_value(__wrap_OSHash_Begin, self, files_status); - will_return(__wrap_OSHash_Begin, hash_node); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddArrayToObject, name, "files"); - will_return(__wrap_cJSON_AddArrayToObject, (cJSON *) 1); - - will_return(__wrap_cJSON_CreateObject, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "path"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "hash"); - expect_string(__wrap_cJSON_AddStringToObject, string, "test1234"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "offset"); - expect_string(__wrap_cJSON_AddStringToObject, string, "5"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - expect_value(__wrap_OSHash_Next, self, files_status); - will_return(__wrap_OSHash_Next, NULL); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_cJSON_PrintUnformatted, strdup("test_1234")); - - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap_wfopen, path, "queue/logcollector/file_status.json"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, "test"); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, "test"); - will_return(__wrap_fclose, 1); - - w_save_file_status(); -} - -/* w_load_files_status */ - -void test_w_load_files_status_empty_array(void ** state) { - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - // >> w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - - // >> w_journald_set_status_from_JSON// << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // << w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_path_NULL(void ** state) { - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_path_str_NULL(void ** state) { - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_no_file(void ** state) { - cJSON *global_json = (cJSON*)1; - - char * file = "test"; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, -1); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_hash_NULL(void ** state) { - cJSON *global_json = (cJSON*)1; - - char * file = "test"; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_hash_str_NULL(void ** state) { - cJSON *global_json = (cJSON*)1; - - char * file = "test"; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_offset_NULL(void ** state) { - cJSON *global_json = (cJSON*)1; - - char * file = "test"; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_offset_str_NULL(void ** state) { - cJSON *global_json = (cJSON*)1; - - char * file = "test"; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); -} - -void test_w_load_files_status_invalid_offset(void ** state) { - cJSON *global_json = (cJSON*)1; - - char * file = "test"; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "-1"); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_update_add_fail(void ** state) { - char * file = "test"; - - cJSON *global_json = (cJSON*)1; - - int mode = OS_BINARY; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "32bb98743e298dee0a654a654765c765d765ae80"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, file); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 0); - - expect_value(__wrap_OSHash_Add_ex, self, files_status); - expect_string(__wrap_OSHash_Add_ex, key, file); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, "(1298): Failure to add 'test' to 'file_status' hash table"); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); -} - -void test_w_load_files_status_update_hash_fail (void ** state) { - char * file = "test"; - - cJSON *global_json = (cJSON*)1; - - int mode = OS_BINARY; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "32bb98743e298dee0a654a654765c765d765ae80"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, file); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "(9000): File 'test' no longer exists."); - - w_load_files_status(global_json); -} - -void test_w_load_files_status_update_fail(void ** state) { - char * file = "test"; - - cJSON *global_json = (cJSON*)1; - - int mode = OS_BINARY; - struct stat stat_buf = { .st_mode = 0040000 }; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "32bb98743e298dee0a654a654765c765d765ae80"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, file); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 0); - - expect_value(__wrap_OSHash_Add_ex, self, files_status); - expect_string(__wrap_OSHash_Add_ex, key, file); - will_return(__wrap_OSHash_Add_ex, 2); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - w_load_files_status(global_json); - -} - -void test_w_load_files_status_OK(void ** state) { - char * file = "test"; - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - os_file_status_t * data; - os_malloc(sizeof(os_file_status_t), data); - data->context = EVP_MD_CTX_new(); - - __real_OSHash_Add_ex(mock_hashmap, file, data); - cJSON *global_json = (cJSON*)1; - - int mode = OS_BINARY; - struct stat stat_buf = { .st_mode = 0040000 }; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "32bb98743e298dee0a654a654765c765d765ae80"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, file); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 1); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - -} - -void test_w_load_files_status_valid_timestamp_only(void ** state) { - test_mode = 1; - - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "2021-04-27 08:07:20-0700"); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - - assert_string_equal(macos_log_vault.settings, "my settings"); - assert_string_equal(macos_log_vault.timestamp, "hi 123"); -} - -void test_w_load_files_status_valid_settings_only(void ** state) { - test_mode = 1; - - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "/usr/bin/log stream --style syslog"); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - - assert_string_equal(macos_log_vault.settings, "my settings"); - assert_string_equal(macos_log_vault.timestamp, "hi 123"); - -} - -void test_w_load_files_status_valid_vault(void ** state) { - test_mode = 1; - - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - os_strdup("my settings", macos_log_vault.settings); - macos_log_vault.is_valid_data = false; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "2021-04-27 08:07:20-0700"); - - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "/usr/bin/log stream --style syslog"); - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - // << w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // >> w_journald_set_status_from_JSON - - w_load_files_status(global_json); - - assert_string_equal(macos_log_vault.timestamp, "2021-04-27 08:07:20-0700"); - assert_string_equal(macos_log_vault.settings, "/usr/bin/log stream --style syslog"); - assert_true(macos_log_vault.is_valid_data); - - os_free(macos_log_vault.settings); -} - -// Related only to journal -void test_w_load_files_status_jorunal_no_journal_obj(void ** state) { - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - // >> w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // << w_macos_set_status_from_JSON - - // >> w_journald_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // << w_journald_set_status_from_JSON - - w_load_files_status(global_json); -} -void test_w_load_files_status_jorunal_no_journal_timestmap(void ** state) { - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - // >> w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // << w_macos_set_status_from_JSON - - // >> w_journald_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, 0x1); - will_return(__wrap_cJSON_GetObjectItem, 0x0); - will_return(__wrap_cJSON_GetStringValue, NULL); - // << w_journald_set_status_from_JSON - - w_load_files_status(global_json); -} -void test_w_load_files_status_jorunal_invalid_timestamp(void ** state) { - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - // >> w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // << w_macos_set_status_from_JSON - - // >> w_journald_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "invalid timestamp"); - // << w_journald_set_status_from_JSON - - w_load_files_status(global_json); -} -void test_w_load_files_status_jorunal_success(void ** state) { - cJSON *global_json = (cJSON*)1; - strcpy(macos_log_vault.timestamp,"hi 123"); - macos_log_vault.settings = "my settings"; - - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 0); - // >> w_macos_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, NULL); - // << w_macos_set_status_from_JSON - - // >> w_journald_set_status_from_JSON - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "123456"); - expect_string(__wrap__mdebug2, formatted_msg, "(9009): Setting last read timestamp to '123456'"); - // << w_journald_set_status_from_JSON - - w_load_files_status(global_json); -} - -/* w_initialize_file_status */ - -void test_w_initialize_file_status_OSHash_Create_fail(void ** state) { - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, NULL); - - expect_string(__wrap__merror_exit, formatted_msg, "(1296): Unable to create a 'file_status' hash table"); - - expect_assert_failure(w_initialize_file_status()); -} - -void test_w_initialize_file_status_OSHash_setSize_fail(void ** state) { - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - - will_return(__wrap_OSHash_setSize, NULL); - - expect_string(__wrap__merror_exit, formatted_msg, "(1297): Unable to set size of 'file_status' hash table"); - - expect_assert_failure(w_initialize_file_status()); - -} - -void test_w_initialize_file_status_fopen_fail(void ** state) { - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - - will_return(__wrap_OSHash_setSize, 1); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - expect_string(__wrap_wfopen, path, LOCALFILE_STATUS); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1103): Could not open file 'queue/logcollector/file_status.json' due to [(0)-(Success)]."); - - w_initialize_file_status(); -} - -void test_w_initialize_file_status_fread_fail(void ** state) { - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - - will_return(__wrap_OSHash_setSize, 1); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - expect_string(__wrap_wfopen, path, LOCALFILE_STATUS); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, "test"); - - will_return(__wrap_fread, "test"); - will_return(__wrap_fread, 0); - - expect_string(__wrap__merror, formatted_msg, "(1115): Could not read from file 'queue/logcollector/file_status.json' due to [(0)-(Success)]."); - - expect_function_call(__wrap_clearerr); - expect_string(__wrap_clearerr, __stream, "test"); - - expect_value(__wrap_fclose, _File, "test"); - will_return(__wrap_fclose, 1); - - w_initialize_file_status(); -} - -void test_w_initialize_file_status_OK(void ** state) { - int mode = OS_BINARY; - char * file = "test"; - struct stat stat_buf = { .st_mode = 0040000 }; - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - os_file_status_t * data; - os_malloc(sizeof(os_file_status_t), data); - data->context = EVP_MD_CTX_new(); - - __real_OSHash_Add_ex(mock_hashmap, file, data); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - - will_return(__wrap_OSHash_setSize, 1); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 1); - - expect_string(__wrap_wfopen, path, LOCALFILE_STATUS); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, "test"); - - will_return(__wrap_fread, "test"); - will_return(__wrap_fread, 1); - - //w_load_files_status - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetArraySize, 1); - - will_return(__wrap_cJSON_GetArrayItem, NULL); - - //Path - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "test"); - - expect_string(__wrap_stat, __file, file); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - //Hash - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "32bb98743e298dee0a654a654765c765d765ae80"); - - //Offset - will_return(__wrap_cJSON_GetObjectItem, 1); - - will_return(__wrap_cJSON_GetStringValue, "1"); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, file); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 1); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, NULL); - - expect_function_call(__wrap_cJSON_Delete); - - expect_value(__wrap_fclose, _File, "test"); - will_return(__wrap_fclose, 1); - - w_initialize_file_status(); -} - -/* w_update_hash_node */ - -void test_w_update_hash_node_path_NULL(void ** state) { - char * path = NULL; - - int ret = w_update_hash_node(path, 0); - - assert_int_equal(ret, -1); - -} - -void test_w_update_hash_node_update_fail(void ** state) { - int mode = OS_BINARY; - char * path = "test"; - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, path); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 0); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 0); - - expect_value(__wrap_OSHash_Add_ex, self, files_status); - expect_string(__wrap_OSHash_Add_ex, key, path); - will_return(__wrap_OSHash_Add_ex, 2); - - int ret = w_update_hash_node(path, 0); - - assert_int_equal(ret, 0); -} - -void test_w_update_hash_node_sha_fail(void ** state) { - int mode = OS_BINARY; - - char * path = "test"; - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, path); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 0); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, -1); - - expect_string(__wrap__merror, formatted_msg, "(1969): Failure to generate the SHA1 hash from file 'test'"); - - int ret = w_update_hash_node(path, 0); - - assert_int_equal(ret, -1); - -} - -void test_w_update_hash_node_add_fail(void ** state) { - int mode = OS_BINARY; - - char * path = "test"; - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, path); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 0); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 0); - - expect_value(__wrap_OSHash_Add_ex, self, files_status); - expect_string(__wrap_OSHash_Add_ex, key, path); - will_return(__wrap_OSHash_Add_ex, 0); - - int ret = w_update_hash_node(path, 0); - - assert_int_equal(ret, -1); - -} - -void test_w_update_hash_node_OK(void ** state) { - int mode = OS_BINARY; - char * path = "test"; - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - os_file_status_t * data; - os_malloc(sizeof(os_file_status_t), data); - data->context = EVP_MD_CTX_new(); - - __real_OSHash_Add_ex(mock_hashmap, path, data); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, path); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 0); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 1); - - int ret = w_update_hash_node(path, 0); - - assert_int_equal(ret, 0); -} - -/* w_set_to_last_line_read */ -void test_w_set_to_last_line_read_null_reader(void ** state) { - logreader lf = {0}; - int ret = w_set_to_last_line_read(&lf); - assert_int_equal(ret, 0); - -} - -void test_w_set_to_last_line_read_OSHash_Get_ex_fail(void ** state) { - fpos_t position_stack = {.__pos = 1}; - logreader log_reader = {.fp = (FILE *)1, .file = "test"}; - - test_position = &position_stack; - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - os_file_status_t * data; - os_malloc(sizeof(os_file_status_t), data); - data->context = EVP_MD_CTX_new(); - - __real_OSHash_Add_ex(mock_hashmap, log_reader.file, data); - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, NULL); - - //w_set_pos - long pos = 0; - int mode = OS_BINARY; - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, 0); - - expect_value(__wrap_w_ftell, x, 1); - will_return(__wrap_w_ftell, 1); - - expect_value(__wrap_w_ftell, x, 1); - will_return(__wrap_w_ftell, 1); - - - //w_update_hash_node - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, log_reader.file); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 1); - - int ret = w_set_to_last_line_read(&log_reader); - - assert_int_equal(ret, 0); -} - -void test_w_set_to_last_line_read_fstat_fail(void ** state) { - os_file_status_t *data = *state; - - logreader log_reader = {.fp = (FILE *)1, .file = "test"}; - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, 1); - - expect_value(__wrap_fileno, __stream, log_reader.fp); - will_return(__wrap_fileno, 1); - - expect_value(__wrap_fstat, __fd, 1); - will_return(__wrap_fstat, 0040000); - will_return(__wrap_fstat, 0); - will_return(__wrap_fstat, -1); - - expect_string(__wrap__merror, formatted_msg, "(1118): Could not retrieve information of file 'test' due to [(0)-(Success)]."); - - - int ret = w_set_to_last_line_read(&log_reader); - - assert_int_equal(ret, -1); -} - -void test_w_set_to_last_line_read_OS_SHA1_File_Nbytes_fail(void ** state) { - int mode = OS_BINARY; - - os_file_status_t data = {0}; - fpos_t position_stack = {.__pos = 1}; - logreader log_reader = {.fp = (FILE *)1, .file= "test"}; - test_position = &position_stack; - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, &data); - - expect_value(__wrap_fileno, __stream, log_reader.fp); - will_return(__wrap_fileno, 1); - - expect_value(__wrap_fstat, __fd, 1); - will_return(__wrap_fstat, 0040000); - will_return(__wrap_fstat, 0); - will_return(__wrap_fstat, 1); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, "test"); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 0); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, -1); - - expect_string(__wrap__merror, formatted_msg, "(1969): Failure to generate the SHA1 hash from file 'test'"); - int ret = w_set_to_last_line_read(&log_reader); - - assert_int_equal(ret, -1); -} - -void test_w_set_to_last_line_read_diferent_file(void ** state) { - int mode = OS_BINARY; - os_file_status_t data = {.hash = "1234", .offset = 1}; - logreader log_reader = {.fp = (FILE *)1, .file= "test"}; - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, &data); - - expect_value(__wrap_fileno, __stream, log_reader.fp); - will_return(__wrap_fileno, 1); - - expect_value(__wrap_fstat, __fd, 1); - will_return(__wrap_fstat, 0040000); - will_return(__wrap_fstat, 0); - will_return(__wrap_fstat, 1); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, "test"); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - //w_set_pos - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, -1); - - expect_string(__wrap__merror, formatted_msg, "(1116): Could not set position in file 'test' due to [(0)-(Success)]."); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 1); - - int ret = w_set_to_last_line_read(&log_reader); - - assert_int_equal(ret, -1); -} - -void test_w_set_to_last_line_read_same_file(void ** state) { - int mode = OS_BINARY; - - os_file_status_t data = {.hash = "1234", .offset = 1}; - logreader log_reader = {.fp = (FILE *)1, .file= "test", .diff_max_size = 0}; - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, &data); - - expect_value(__wrap_fileno, __stream, log_reader.fp); - will_return(__wrap_fileno, 1); - - expect_value(__wrap_fstat, __fd, 1); - will_return(__wrap_fstat, 0040000); - will_return(__wrap_fstat, 1); - will_return(__wrap_fstat, 1); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, "test"); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "1234"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - //w_set_pos - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 1); - will_return(__wrap_w_fseek, -1); - - expect_string(__wrap__merror, formatted_msg, "(1116): Could not set position in file 'test' due to [(0)-(Success)]."); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 1); - - int ret = w_set_to_last_line_read(&log_reader); - - assert_int_equal(ret, -1); -} - -void test_w_set_to_last_line_read_same_file_rotate(void ** state) { - int mode = OS_BINARY; - logreader log_reader = {.fp = (FILE *)1, .file= "test", .diff_max_size = 0}; - os_file_status_t data = {.hash = "1234", .offset = 1}; - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, &data); - - expect_value(__wrap_fileno, __stream, log_reader.fp); - will_return(__wrap_fileno, 1); - - expect_value(__wrap_fstat, __fd, 1); - will_return(__wrap_fstat, 0040000); - will_return(__wrap_fstat, 10); - will_return(__wrap_fstat, 1); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, "test"); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "1234"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, -1); - - expect_string(__wrap__merror, formatted_msg, "(1116): Could not set position in file 'test' due to [(0)-(Success)]."); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 1); - - int ret = w_set_to_last_line_read(&log_reader); - - assert_int_equal(ret, -1); -} - -void test_w_set_to_last_line_read_update_hash_node_error(void ** state) { - int mode = OS_BINARY; - logreader log_reader = {.fp = (FILE *)1, .file= "test", .diff_max_size = 0}; - os_file_status_t data = {.hash = "1234", .offset = 1}; - - - expect_any(__wrap_OSHash_Get_ex, self); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, &data); - - expect_value(__wrap_fileno, __stream, log_reader.fp); - will_return(__wrap_fileno, 1); - - expect_value(__wrap_fstat, __fd, 1); - will_return(__wrap_fstat, 0040000); - will_return(__wrap_fstat, 10); - will_return(__wrap_fstat, 1); - - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, "test"); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "1234"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - //w_set_pos - - os_calloc(1, sizeof(fpos_t), test_position); - test_position->__pos = 1; - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, 0); - - expect_value(__wrap_w_ftell, x, 1); - will_return(__wrap_w_ftell, 1); - - //w_update_hash_node - expect_string(__wrap_OS_SHA1_File_Nbytes, fname, "test"); - expect_value(__wrap_OS_SHA1_File_Nbytes, mode, mode); - expect_value(__wrap_OS_SHA1_File_Nbytes, nbytes, 1); - will_return(__wrap_OS_SHA1_File_Nbytes, "1234"); - will_return(__wrap_OS_SHA1_File_Nbytes, 1); - - will_return(__wrap_OSHash_Update_ex, 0); - - expect_value(__wrap_OSHash_Add_ex, self, files_status); - expect_string(__wrap_OSHash_Add_ex, key, log_reader.file); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, "(1299): Failure to update 'test' to 'file_status' hash table"); - - int ret = w_set_to_last_line_read(&log_reader); - - assert_int_equal(ret, 1); -} - -/* _macos_release_log_show */ - -void test_w_macos_release_log_show_not_launched(void ** state) { - macos_processes = *state; - macos_processes->show.wfd = NULL; - - w_macos_release_log_show(); - -} - -void test_w_macos_release_log_show_launched_and_running(void ** state) { - - macos_processes = *state; - macos_processes->show.wfd->pid = 10; - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_show(); - - assert_null(macos_processes->show.wfd); - -} - -void test_w_macos_release_log_show_launched_and_running_with_child(void ** state) { - - macos_processes = *state; - macos_processes->show.wfd->pid = 10; - macos_processes->show.child = 11; - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 11); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_show(); - - assert_null(macos_processes->show.wfd); - -} - -void test_w_macos_release_log_show_launched_and_not_running(void ** state) { - - macos_processes = *state; - macos_processes->show.wfd->pid = 0; - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_show(); - - assert_null(macos_processes->show.wfd); - -} - -/* w_macos_release_log_stream */ - -void test_w_macos_release_log_stream_not_launched(void ** state) { - - macos_processes = *state; - macos_processes->stream.wfd = NULL; - - w_macos_release_log_stream(); - -} - -void test_w_macos_release_log_stream_launched_and_running(void ** state) { - - macos_processes = *state; - macos_processes->stream.wfd->pid = 10; - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log stream` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_stream(); - - assert_null(macos_processes->stream.wfd); - -} - -void test_w_macos_release_log_stream_launched_and_running_with_child(void ** state) { - - macos_processes = *state; - macos_processes->stream.wfd->pid = 10; - macos_processes->stream.child = 11; - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log stream` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 11); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_stream(); - - assert_null(macos_processes->stream.wfd); - -} - -void test_w_macos_release_log_stream_launched_and_not_running(void ** state) { - - macos_processes = *state; - macos_processes->stream.wfd->pid = 0; - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log stream` resources."); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_stream(); - - assert_null(macos_processes->stream.wfd); - -} - -/* w_macos_release_log_execution */ - -void test_w_macos_release_log_execution_log_stream_and_show_not_launched(void ** state) { - - macos_processes = *state; - macos_processes->show.wfd = NULL; - macos_processes->stream.wfd = NULL; - - w_macos_release_log_execution(); - -} - -void test_w_macos_release_log_execution_log_stream_and_show_launched_and_running(void ** state) { - - macos_processes = *state; - macos_processes->show.wfd->pid =10; - macos_processes->stream.wfd->pid = 11; - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log stream` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 11); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_execution(); - - assert_null(macos_processes->stream.wfd); - assert_null(macos_processes->show.wfd); - -} - -void test_w_macos_release_log_execution_log_stream_launched_and_show_not_launched(void ** state) { - - macos_processes = *state; - macos_processes->show.wfd = NULL; - macos_processes->stream.wfd->pid = 10; - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log stream` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_execution(); - - assert_null(macos_processes->stream.wfd); - -} - -void test_w_macos_release_log_execution_log_stream_not_launched_and_show_launched(void ** state) { - - macos_processes = *state; - macos_processes->show.wfd->pid = 10; - macos_processes->stream.wfd = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, 0); - - w_macos_release_log_execution(); - - assert_null(macos_processes->show.wfd); - -} - -void check_ignore_and_restrict_null_config(void ** state) { - logreader *regex_config = *state; - - int ret = check_ignore_and_restrict(NULL, NULL, "testing log line"); - assert_false(ret); -} - -void check_ignore_and_restrict_not_ignored(void ** state) { - logreader *regex_config = *state; - w_expression_t * expression_ignore; - char *str_test = "testing log not match"; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - w_calloc_expression_t(&expression_ignore, EXP_TYPE_PCRE2); - w_expression_compile(expression_ignore, "ignore.*", 0); - OSList_InsertData(regex_config->regex_ignore, NULL, expression_ignore); - - will_return(wrap_pcre2_match_data_create_from_pattern, 1); - will_return(wrap_pcre2_match, 0); - - int ret = check_ignore_and_restrict(regex_config->regex_ignore, NULL, str_test); - - assert_false(ret); -} - -void check_ignore_and_restrict_ignored(void ** state) { - logreader *regex_config = *state; - w_expression_t * expression_ignore; - char *str_test = "testing log with ignore word"; - char *aux[2]; - aux[0] = str_test; - aux[1] = str_test+1; - char log_str[PATH_MAX + 1] = {0}; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - w_calloc_expression_t(&expression_ignore, EXP_TYPE_PCRE2); - w_expression_compile(expression_ignore, "ignore.*", 0); - OSList_InsertData(regex_config->regex_ignore, NULL, expression_ignore); - - will_return(wrap_pcre2_match_data_create_from_pattern, 1); - will_return(wrap_pcre2_match, 1); - will_return(wrap_pcre2_get_ovector_pointer, aux); - - snprintf(log_str, PATH_MAX, LF_MATCH_REGEX, "testing log with ignore word", "ignore", "ignore.*"); - expect_string(__wrap__mdebug2, formatted_msg, log_str); - - int ret = check_ignore_and_restrict(regex_config->regex_ignore, NULL, str_test); - - assert_true(ret); -} - -void check_ignore_and_restrict_not_restricted(void ** state) { - logreader *regex_config = *state; - w_expression_t * expression_restrict; - char *str_test = "testing log with restrict word"; - char *aux[2]; - aux[0] = str_test; - aux[1] = str_test+1; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - w_calloc_expression_t(&expression_restrict, EXP_TYPE_PCRE2); - w_expression_compile(expression_restrict, "restrict.*", 0); - OSList_InsertData(regex_config->regex_restrict, NULL, expression_restrict); - - will_return(wrap_pcre2_match_data_create_from_pattern, 1); - will_return(wrap_pcre2_match, 1); - will_return(wrap_pcre2_get_ovector_pointer, aux); - - int ret = check_ignore_and_restrict(NULL, regex_config->regex_restrict, str_test); - - assert_false(ret); -} - -void check_ignore_and_restrict_restricted(void ** state) { - logreader *regex_config = *state; - w_expression_t * expression_restrict; - char *str_test = "testing log not match"; - char log_str[PATH_MAX + 1] = {0}; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - w_calloc_expression_t(&expression_restrict, EXP_TYPE_PCRE2); - w_expression_compile(expression_restrict, "restrict.*", 0); - OSList_InsertData(regex_config->regex_restrict, NULL, expression_restrict); - - will_return(wrap_pcre2_match_data_create_from_pattern, 1); - will_return(wrap_pcre2_match, 0); - - snprintf(log_str, PATH_MAX, LF_MATCH_REGEX, "testing log not match", "restrict", "restrict.*"); - expect_string(__wrap__mdebug2, formatted_msg, log_str); - - int ret = check_ignore_and_restrict(NULL, regex_config->regex_restrict, str_test); - - assert_true(ret); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test w_get_hash_context - cmocka_unit_test_setup_teardown(test_w_get_hash_context_NULL_file_exist, setup_log_context, teardown_log_context), - cmocka_unit_test_setup_teardown(test_w_get_hash_context_NULL_file_not_exist, setup_log_context, teardown_log_context), - cmocka_unit_test_setup_teardown(test_w_get_hash_context_done, setup_log_context, teardown_log_context), - - // Test w_update_file_status - cmocka_unit_test_setup_teardown(test_w_update_file_status_fail_update_add_table_hash, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_update_file_status_update_fail_add_OK, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_update_file_status_update_OK, setup_local_hashmap, teardown_local_hashmap), - - // Test w_set_to_pos - cmocka_unit_test_setup_teardown(test_w_set_to_pos_localfile_NULL, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_set_to_pos_fseek_error, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_set_to_pos_OK, setup_local_hashmap, teardown_local_hashmap), - - // Test w_save_files_status_to_cJSON - // Related only to files - cmocka_unit_test_setup_teardown(test_w_save_files_status_to_cJSON_begin_NULL, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_save_files_status_to_cJSON_OK, setup_log_context, teardown_log_context), - // Related only to macos - cmocka_unit_test(test_w_save_files_status_to_cJSON_macos_invalid_vault), - cmocka_unit_test(test_w_save_files_status_to_cJSON_macos_valid_vault), - // Related only to journal - cmocka_unit_test(test_w_save_files_status_to_cJSON_journal_valid), - // Related to files and macos - cmocka_unit_test(test_w_save_files_status_to_cJSON_data), - - // Test w_save_file_status - cmocka_unit_test_setup_teardown(test_w_save_file_status_str_NULL, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_save_file_status_wfopen_error, setup_log_context, teardown_log_context), - cmocka_unit_test_setup_teardown(test_w_save_file_status_fwrite_error, setup_log_context, teardown_log_context), - cmocka_unit_test_setup_teardown(test_w_save_file_status_OK, setup_log_context, teardown_log_context), - - // Test w_load_files_status - cmocka_unit_test(test_w_load_files_status_empty_array), - cmocka_unit_test(test_w_load_files_status_path_NULL), - cmocka_unit_test(test_w_load_files_status_path_str_NULL), - cmocka_unit_test(test_w_load_files_status_no_file), - cmocka_unit_test(test_w_load_files_status_hash_NULL), - cmocka_unit_test(test_w_load_files_status_hash_str_NULL), - cmocka_unit_test(test_w_load_files_status_offset_NULL), - cmocka_unit_test(test_w_load_files_status_offset_str_NULL), - cmocka_unit_test(test_w_load_files_status_invalid_offset), - cmocka_unit_test_setup_teardown(test_w_load_files_status_update_add_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_load_files_status_update_hash_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_load_files_status_update_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_load_files_status_OK, setup_local_hashmap, teardown_local_hashmap), - // Related only to macos - cmocka_unit_test(test_w_load_files_status_valid_timestamp_only), - cmocka_unit_test(test_w_load_files_status_valid_settings_only), - cmocka_unit_test(test_w_load_files_status_valid_vault), - cmocka_unit_test(test_w_save_files_status_invalid_vault), - // Related only to journal - cmocka_unit_test(test_w_load_files_status_jorunal_no_journal_obj), - cmocka_unit_test(test_w_load_files_status_jorunal_no_journal_timestmap), - cmocka_unit_test(test_w_load_files_status_jorunal_invalid_timestamp), - cmocka_unit_test(test_w_load_files_status_jorunal_success), - - - // Test w_initialize_file_status - cmocka_unit_test(test_w_initialize_file_status_OSHash_Create_fail), - cmocka_unit_test(test_w_initialize_file_status_OSHash_setSize_fail), - cmocka_unit_test(test_w_initialize_file_status_fopen_fail), - cmocka_unit_test(test_w_initialize_file_status_fread_fail), - cmocka_unit_test_setup_teardown(test_w_initialize_file_status_OK, setup_local_hashmap, teardown_local_hashmap), - - // Test w_update_hash_node - cmocka_unit_test(test_w_update_hash_node_path_NULL), - cmocka_unit_test(test_w_update_hash_node_sha_fail), - cmocka_unit_test_setup_teardown(test_w_update_hash_node_update_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_update_hash_node_add_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_update_hash_node_OK, setup_local_hashmap, teardown_local_hashmap), - - // Test w_set_to_last_line_read - cmocka_unit_test(test_w_set_to_last_line_read_null_reader), - cmocka_unit_test_setup_teardown(test_w_set_to_last_line_read_OSHash_Get_ex_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test(test_w_set_to_last_line_read_fstat_fail), - cmocka_unit_test_setup_teardown(test_w_set_to_last_line_read_OS_SHA1_File_Nbytes_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_set_to_last_line_read_diferent_file, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_set_to_last_line_read_same_file, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_set_to_last_line_read_same_file_rotate, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test_w_set_to_last_line_read_update_hash_node_error, setup_local_hashmap, teardown_local_hashmap), - - // Test w_macos_release_log_show - cmocka_unit_test_setup_teardown(test_w_macos_release_log_show_not_launched, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_show_launched_and_running, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_show_launched_and_running_with_child, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_show_launched_and_not_running, setup_process, teardown_process), - - - // Test w_macos_release_log_stream - cmocka_unit_test_setup_teardown(test_w_macos_release_log_stream_not_launched, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_stream_launched_and_running, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_stream_launched_and_running_with_child, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_stream_launched_and_not_running, setup_process, teardown_process), - - // Test w_macos_release_log_execution - cmocka_unit_test_setup_teardown(test_w_macos_release_log_execution_log_stream_and_show_not_launched, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_execution_log_stream_and_show_launched_and_running, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_execution_log_stream_launched_and_show_not_launched, setup_process, teardown_process), - cmocka_unit_test_setup_teardown(test_w_macos_release_log_execution_log_stream_not_launched_and_show_launched, setup_process, teardown_process), - - // Test w_macos_release_log_execution - cmocka_unit_test_setup_teardown(check_ignore_and_restrict_null_config, setup_regex, teardown_regex), - cmocka_unit_test_setup_teardown(check_ignore_and_restrict_not_ignored, setup_regex, teardown_regex), - cmocka_unit_test_setup_teardown(check_ignore_and_restrict_ignored, setup_regex, teardown_regex), - cmocka_unit_test_setup_teardown(check_ignore_and_restrict_not_restricted, setup_regex, teardown_regex), - cmocka_unit_test_setup_teardown(check_ignore_and_restrict_restricted, setup_regex, teardown_regex) - - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/logcollector/test_macos_log.c b/src/unit_tests/logcollector/test_macos_log.c deleted file mode 100644 index 44a1caccd42..00000000000 --- a/src/unit_tests/logcollector/test_macos_log.c +++ /dev/null @@ -1,3483 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../logcollector/logcollector.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../../headers/shared.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/linux/socket_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/wazuh/shared/sysinfo_utils_wrappers.h" - -bool w_macos_is_log_predicate_valid(char * predicate); -char ** w_macos_create_log_stream_array(char * predicate, char * level, int type); -wfd_t * w_macos_log_exec(char ** log_cmd_array, u_int32_t flags); -void w_macos_create_log_env(logreader * lf, w_sysinfo_helpers_t * global_sysinfo); -bool w_macos_is_log_executable(void); -void w_macos_create_log_stream_env(logreader * lf); -void w_macos_log_show_array_add_level(char ** log_cmd_array, size_t * log_cmd_array_idx, char * level); -char * w_macos_log_show_create_type_predicate(int type); -void w_macos_log_show_array_add_predicate(char ** log_cmd_array, - size_t * log_cmd_array_idx, - char * query, - char * type_predicate); -char ** w_macos_create_log_show_array(char * start_date, char * query, char * level, int type); -void w_macos_set_last_log_timestamp(char * timestamp); -char * w_macos_get_last_log_timestamp(); -void w_macos_set_last_log_settings(char * timestamp); -char * w_macos_get_last_log_settings(); -void w_macos_create_log_show_env(logreader * lf); -void w_macos_create_log_stream_env(logreader * lf); -void w_macos_add_sierra_support(char ** log_cmd_array, size_t * log_cmd_array_idx); -pid_t w_get_first_child(pid_t parent_pid); - -extern w_macos_log_vault_t macos_log_vault; - -extern char * macos_codename; - -/* setup/teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; - -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; - -} - -static int setup_file(void **state) { - wfd_t * wfd = calloc(1, sizeof(wfd_t)); - - *state = wfd; - - return 0; -} - -static int teardown_file(void **state) { - wfd_t * wfd = *state; - - free(wfd); - - return 0; -} - -static int teardown_settings(void **state) { - os_free(macos_log_vault.settings); - - return 0; -} - -static int setup_timestamp_null(void **state) { - macos_log_vault.timestamp[0] = '\0'; - - return 0; -} - -static int teardown_timestamp_null(void **state) { - strncpy(macos_log_vault.timestamp, "2021-04-27 12:29:25-0700", OS_LOGCOLLECTOR_TIMESTAMP_SHORT_LEN); - - return 0; -} - -/* wraps */ - - -/* w_macos_is_log_predicate_valid */ -void test_w_macos_is_log_predicate_valid_empty(void ** state) { - - char predicate[] = ""; - - bool ret = w_macos_is_log_predicate_valid(predicate); - assert_false(ret); - -} - -void test_w_macos_is_log_predicate_valid_existing(void ** state) { - - char predicate[] = "test"; - - bool ret = w_macos_is_log_predicate_valid(predicate); - assert_true(ret); - -} - -/* w_macos_create_log_stream_array */ -void test_w_macos_create_log_stream_array_NULL(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_null(ret[4]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_level_default(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--level"); - assert_string_equal(ret[5], level); - assert_null(ret[6]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--level"); - assert_string_equal(ret[5], level); - assert_null(ret[6]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--level"); - assert_string_equal(ret[5], level); - assert_null(ret[6]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_type_activity(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_null(ret[6]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_type_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_null(ret[6]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_type_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_null(ret[6]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_type_activity_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_null(ret[8]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_type_activity_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_null(ret[8]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_type_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_null(ret[8]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_type_activity_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_null(ret[10]); - - free_strarray(ret); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "default"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_default_type_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "default"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_default_type_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "default"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "default"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "default"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_default_type_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "default"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - os_strdup("default", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_string_equal(ret[10], "--level"); - assert_string_equal(ret[11], "default"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "info"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info_type_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "info"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info_type_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "info"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "info"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "info"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info_type_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "info"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - os_strdup("info", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_string_equal(ret[10], "--level"); - assert_string_equal(ret[11], "info"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "debug"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "debug"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "debug"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity_log(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "debug"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "debug"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "debug"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity_log_trace(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - os_strdup("debug", level); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_string_equal(ret[10], "--level"); - assert_string_equal(ret[11], "debug"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - -} - - -//PREDICADO - -void test_w_macos_create_log_stream_array_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--predicate"); - assert_string_equal(ret[5], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[6]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--level"); - assert_string_equal(ret[5], "default"); - assert_string_equal(ret[6], "--predicate"); - assert_string_equal(ret[7], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--level"); - assert_string_equal(ret[5], "info"); - assert_string_equal(ret[6], "--predicate"); - assert_string_equal(ret[7], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 0; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--level"); - assert_string_equal(ret[5], "debug"); - assert_string_equal(ret[6], "--predicate"); - assert_string_equal(ret[7], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_type_activity_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--predicate"); - assert_string_equal(ret[7], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_type_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--predicate"); - assert_string_equal(ret[7], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_type_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_string_equal(ret[6], "--predicate"); - assert_string_equal(ret[7], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[8]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_type_activity_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_type_activity_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_type_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_type_activity_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "default"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_type_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "default"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_type_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "default"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "default"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "default"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_type_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "default"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_default_type_activity_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - os_strdup("default", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_string_equal(ret[10], "--level"); - assert_string_equal(ret[11], "default"); - assert_string_equal(ret[12], "--predicate"); - assert_string_equal(ret[13], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[14]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "info"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_type_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "info"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_type_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "info"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "info"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "info"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_type_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "info"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_info_type_activity_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - os_strdup("info", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_string_equal(ret[10], "--level"); - assert_string_equal(ret[11], "info"); - assert_string_equal(ret[12], "--predicate"); - assert_string_equal(ret[13], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[14]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 1; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "debug"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 2; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "debug"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 4; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "trace"); - assert_string_equal(ret[6], "--level"); - assert_string_equal(ret[7], "debug"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity_log_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 3; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "debug"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 5; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "debug"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 6; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "log"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "trace"); - assert_string_equal(ret[8], "--level"); - assert_string_equal(ret[9], "debug"); - assert_string_equal(ret[10], "--predicate"); - assert_string_equal(ret[11], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[12]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_level_debug_type_activity_log_trace_predicate(void ** state) { - - char * predicate = NULL; - char * level = NULL; - int type = 7; - - os_strdup("debug", level); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", predicate); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "stream"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--type"); - assert_string_equal(ret[5], "activity"); - assert_string_equal(ret[6], "--type"); - assert_string_equal(ret[7], "log"); - assert_string_equal(ret[8], "--type"); - assert_string_equal(ret[9], "trace"); - assert_string_equal(ret[10], "--level"); - assert_string_equal(ret[11], "debug"); - assert_string_equal(ret[12], "--predicate"); - assert_string_equal(ret[13], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(ret[14]); - - free_strarray(ret); - os_free(level); - os_free(predicate); - -} - -void test_w_macos_create_log_stream_array_on_sierra(void ** state) { - - int type = 0; - char * level = NULL; - char * predicate = NULL; - char * backup_codename = NULL; - - /* Sets the name "Sierra" to the global variable for the system to be identified as a Sierra Version of macOS */ - if (macos_codename != NULL) { - /* Just in case, backups the previous codename to be restored */ - w_strdup(macos_codename, backup_codename); - } - - w_strdup(MACOS_SIERRA_CODENAME_STR, macos_codename); - - char ** ret = w_macos_create_log_stream_array(predicate, level, type); - - assert_string_equal(ret[0], SCRIPT_CMD_STR); - assert_string_equal(ret[1], SCRIPT_CMD_ARGS); - assert_string_equal(ret[2], SCRIPT_CMD_SINK); - assert_string_equal(ret[3], "/usr/bin/log"); - assert_string_equal(ret[4], "stream"); - assert_string_equal(ret[5], "--style"); - assert_string_equal(ret[6], "syslog"); - assert_null(ret[7]); - - free_strarray(ret); - - os_free(macos_codename); - if (backup_codename != NULL) { - w_strdup(backup_codename, macos_codename); - os_free(backup_codename); - } -} - -/* w_macos_log_exec */ -void test_w_macos_log_exec_wpopenv_error(void ** state) { - - char * log_cmd_array = NULL; - os_strdup("log stream", log_cmd_array); - u_int32_t flags = 0; - - will_return(__wrap_wpopenv, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1974): An error ocurred while calling wpopenv(): Success (0)."); - - wfd_t * ret = w_macos_log_exec(&log_cmd_array, flags); - - assert_null(ret); - os_free(log_cmd_array); - -} - -void test_w_macos_log_exec_fileno_error(void ** state) { - - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - char * log_cmd_array = NULL; - os_strdup("log stream", log_cmd_array); - u_int32_t flags = 0; - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 0); - - expect_string(__wrap__merror, formatted_msg, - "(1971): The file descriptor couldn't be obtained from the file pointer of the Log Stream pipe: Success (0)."); - - will_return(__wrap_wpclose, 0); - - wfd_t * ret = w_macos_log_exec(&log_cmd_array, flags); - - assert_ptr_equal(ret, 0); - os_free(log_cmd_array); - -} - -void test_w_macos_log_exec_fp_to_fd_error(void ** state) { - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - char * log_cmd_array = NULL; - os_strdup("log stream", log_cmd_array); - u_int32_t flags = 0; - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 0); - - expect_string(__wrap__merror, formatted_msg, - "(1971): The file descriptor couldn't be obtained from the file pointer of the Log Stream pipe: Success (0)."); - - will_return(__wrap_wpclose, 0); - - wfd_t * ret = w_macos_log_exec(&log_cmd_array, flags); - - assert_ptr_equal(ret, 0); - os_free(log_cmd_array); - -} - -void test_w_macos_log_exec_get_flags_error(void ** state) { - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - char * log_cmd_array = NULL; - os_strdup("log stream", log_cmd_array); - u_int32_t flags = 0; - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 1); - - will_return(__wrap_fcntl, -1); - - expect_string(__wrap__merror, formatted_msg, - "(1972): The flags couldn't be obtained from the file descriptor: Success (0)."); - - will_return(__wrap_wpclose, 0); - - wfd_t * ret = w_macos_log_exec(&log_cmd_array, flags); - - assert_ptr_equal(ret, 0); - os_free(log_cmd_array); - -} - -void test_w_macos_log_exec_set_flags_error(void ** state) { - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - char * log_cmd_array = NULL; - os_strdup("log stream", log_cmd_array); - u_int32_t flags = 0; - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 1); - - will_return(__wrap_fcntl, 0); - - will_return(__wrap_fcntl, -1); - - expect_string(__wrap__merror, formatted_msg, - "(1973): The flags couldn't be set in the file descriptor: Success (0)."); - - will_return(__wrap_wpclose, 0); - - wfd_t * ret = w_macos_log_exec(&log_cmd_array, flags); - - assert_ptr_equal(ret, 0); - - os_free(log_cmd_array); - -} - -void test_w_macos_log_exec_success(void ** state) { - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - char * log_cmd_array = NULL; - os_strdup("log stream", log_cmd_array); - u_int32_t flags = 0; - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 1); - - will_return(__wrap_fcntl, 0); - - will_return(__wrap_fcntl, 0); - - wfd_t * ret = w_macos_log_exec(&log_cmd_array, flags); - - assert_ptr_equal(ret->file_out, wfd->file_out); - assert_int_equal(ret->pid, 0); - - os_free(log_cmd_array); - -} - -/* w_macos_is_log_executable */ -void test_w_macos_is_log_executable_success(void ** state) { - - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - bool ret = w_macos_is_log_executable(); - - assert_true(ret); - -} - -void test_w_macos_is_log_executable_error(void ** state) { - - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 1); - - expect_string(__wrap__merror, formatted_msg, "(1250): Error trying to execute \"/usr/bin/log\": Success (0)."); - - bool ret = w_macos_is_log_executable(); - - assert_false(ret); - -} - -void test_w_macos_is_log_executable_sierra_access_fail(void ** state) { - - char * backup_codename = NULL; - - if (macos_codename != NULL) { - w_strdup(macos_codename, backup_codename); - } - - w_strdup(MACOS_SIERRA_CODENAME_STR, macos_codename); - - expect_string(__wrap_access, __name, "/usr/bin/script"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 1); - - expect_string(__wrap__merror, formatted_msg, "(1250): Error trying to execute \"/usr/bin/script\": Success (0)."); - - bool ret = w_macos_is_log_executable(); - - assert_false(ret); - - os_free(macos_codename); - if (backup_codename != NULL) { - w_strdup(backup_codename, macos_codename); - os_free(backup_codename); - } -} - -/* w_macos_create_log_stream_env */ -void test_w_macos_create_log_stream_env_not_executable(void ** state) { - - logreader *current = NULL; - os_calloc(1, sizeof(logreader), current); - current->fp = (FILE*)1; - os_strdup("test", current->file); - current->diff_max_size = 0; - - os_calloc(1, sizeof(w_macos_log_config_t), current->macos_log); - current->macos_log->state = LOG_NOT_RUNNING; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", current->query); - os_strdup("debug", current->query_level); - current->query_type = 7; - - os_calloc(1, sizeof(wfd_t), current->macos_log->processes.stream.wfd); - current->macos_log->processes.stream.wfd->file_out = (FILE*)1; - - // test_w_macos_is_log_executable_error - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 1); - - expect_string(__wrap__merror, formatted_msg, "(1250): Error trying to execute \"/usr/bin/log\": Success (0)."); - - w_macos_create_log_stream_env(current); - - os_free(current->file); - os_free(current->query); - os_free(current->query_level); - os_free(current->macos_log->processes.stream.wfd); - os_free(current->macos_log); - os_free(current); - -} - -void test_w_macos_create_log_stream_env_log_wfd_NULL(void ** state) { - - logreader *current = NULL; - os_calloc(1, sizeof(logreader), current); - current->fp = (FILE*)1; - os_strdup("test", current->file); - current->diff_max_size = 0; - - os_calloc(1, sizeof(w_macos_log_config_t), current->macos_log); - current->macos_log->state = LOG_NOT_RUNNING; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", current->query); - os_strdup("debug", current->query_level); - current->query_type = 7; - - // test_w_macos_is_log_executable_error - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - // test_w_macos_create_log_stream_array_level_debug_type_activity_log_trace_predicate - - // test_w_macos_log_exec_wpopenv_error - will_return(__wrap_wpopenv, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1974): An error ocurred while calling wpopenv(): Success (0)."); - - w_macos_create_log_stream_env(current); - - os_free(current->file); - os_free(current->query); - os_free(current->query_level); - os_free(current->macos_log->processes.stream.wfd); - os_free(current->macos_log); - os_free(current); - -} - -void test_w_macos_create_log_stream_env_complete(void ** state) { - - logreader *current = NULL; - os_calloc(1, sizeof(logreader), current); - current->fp = (FILE*)1; - os_strdup("test", current->file); - current->diff_max_size = 0; - - os_calloc(1, sizeof(w_macos_log_config_t), current->macos_log); - current->macos_log->state = LOG_NOT_RUNNING; - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", current->query); - os_strdup("debug", current->query_level); - current->query_type = 7; - - // test_w_macos_is_log_executable_success - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - // test_w_macos_create_log_stream_array_level_debug_type_activity_log_trace_predicate - - // test_w_macos_log_exec_success - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 1); - - will_return(__wrap_fcntl, 0); - - will_return(__wrap_fcntl, 0); - - expect_string(__wrap__minfo, formatted_msg, "(1604): Monitoring macOS logs with: /usr/bin/log stream --style syslog --type activity --type log --type trace --level debug --predicate processImagePath CONTAINS[c] 'com.apple.geod'"); - - w_macos_create_log_stream_env(current); - - os_free(current->file); - os_free(current->query); - os_free(current->query_level); - os_free(current->macos_log); - os_free(current); - -} - -/* w_macos_log_show_array_add_level */ - -void test_w_macos_log_show_array_add_level_NULL(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - char * type_predicate = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * level = NULL; - - w_macos_log_show_array_add_level(log_cmd_array, &log_cmd_array_idx, level); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_null(log_cmd_array[6]); - - free_strarray(log_cmd_array); - -} - -void test_w_macos_log_show_array_add_level_default(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - char * type_predicate = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * level = MACOS_LOG_LEVEL_DEFAULT_STR; - - w_macos_log_show_array_add_level(log_cmd_array, &log_cmd_array_idx, level); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_null(log_cmd_array[6]); - - free_strarray(log_cmd_array); - -} - -void test_w_macos_log_show_array_add_level_info(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - char * type_predicate = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * level = SHOW_INFO_OPT_STR; - - w_macos_log_show_array_add_level(log_cmd_array, &log_cmd_array_idx, level); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_string_equal(log_cmd_array[6], "--info"); - assert_null(log_cmd_array[7]); - - free_strarray(log_cmd_array); - -} - -void test_w_macos_log_show_array_add_level_debug(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - char * type_predicate = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * level = MACOS_LOG_LEVEL_DEBUG_STR; - - w_macos_log_show_array_add_level(log_cmd_array, &log_cmd_array_idx, level); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_string_equal(log_cmd_array[6], "--info"); - assert_string_equal(log_cmd_array[7], "--debug"); - assert_null(log_cmd_array[8]); - - free_strarray(log_cmd_array); - -} - -/* w_macos_log_show_create_type_predicate */ - -void test_w_macos_log_show_create_type_predicate_NULL(void ** state) { - - char * type_predicate = NULL; - - int type = 0; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_null(type_predicate); - -} - -void test_w_macos_log_show_create_type_predicate_activity(void ** state) { - - char * type_predicate = NULL; - - int type = 1; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_string_equal(type_predicate, "eventType == activityCreateEvent " \ - "OR eventType == activityTransitionEvent " \ - "OR eventType == userActionEvent"); - - os_free(type_predicate); - -} - -void test_w_macos_log_show_create_type_predicate_log(void ** state) { - - char * type_predicate = NULL; - - int type = 2; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_string_equal(type_predicate, "eventType == logEvent"); - - os_free(type_predicate); - -} - -void test_w_macos_log_show_create_type_predicate_trace(void ** state) { - - char * type_predicate = NULL; - - int type = 4; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_string_equal(type_predicate, "eventType == traceEvent"); - - os_free(type_predicate); - -} - -void test_w_macos_log_show_create_type_predicate_activity_log(void ** state) { - - char * type_predicate = NULL; - - int type = 3; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_string_equal(type_predicate, "eventType == activityCreateEvent " \ - "OR eventType == activityTransitionEvent " \ - "OR eventType == userActionEvent " \ - "OR eventType == logEvent"); - - os_free(type_predicate); - -} - -void test_w_macos_log_show_create_type_predicate_activity_trace(void ** state) { - - char * type_predicate = NULL; - - int type = 5; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_string_equal(type_predicate, "eventType == activityCreateEvent " \ - "OR eventType == activityTransitionEvent " \ - "OR eventType == userActionEvent " \ - "OR eventType == traceEvent"); - - os_free(type_predicate); - -} - -void test_w_macos_log_show_create_type_predicate_log_trace(void ** state) { - - char * type_predicate = NULL; - - int type = 6; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_string_equal(type_predicate, "eventType == logEvent OR eventType == traceEvent"); - - os_free(type_predicate); - -} - -void test_w_macos_log_show_create_type_predicate_activity_log_trace(void ** state) { - - char * type_predicate = NULL; - - int type = 7; - - type_predicate = w_macos_log_show_create_type_predicate(type); - - assert_string_equal(type_predicate, "eventType == activityCreateEvent " \ - "OR eventType == activityTransitionEvent " \ - "OR eventType == userActionEvent " \ - "OR eventType == logEvent " \ - "OR eventType == traceEvent"); - - os_free(type_predicate); - -} - -/* w_macos_log_show_array_add_predicate */ - -void test_w_macos_log_show_array_add_predicate_query_and_predicate_null(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * query = NULL; - - char * type_predicate = NULL; - - w_macos_log_show_array_add_predicate(log_cmd_array, &log_cmd_array_idx, query, type_predicate); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_null(log_cmd_array[6]); - - free_strarray(log_cmd_array); - -} - -void test_w_macos_log_show_array_add_predicate_query_null_and_valid_predicate(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * query = NULL; - - char * type_predicate = NULL; - os_strdup("eventType == logEvent", type_predicate); - - w_macos_log_show_array_add_predicate(log_cmd_array, &log_cmd_array_idx, query, type_predicate); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_string_equal(log_cmd_array[6], "--predicate"); - assert_string_equal(log_cmd_array[7], "eventType == logEvent"); - assert_null(log_cmd_array[8]); - - free_strarray(log_cmd_array); - os_free(query); - os_free(type_predicate); - -} - -void test_w_macos_log_show_array_add_predicate_invalid_query_and_predicate_null(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * query = NULL; - os_strdup("", query); - - char * type_predicate = NULL; - - w_macos_log_show_array_add_predicate(log_cmd_array, &log_cmd_array_idx, query, type_predicate); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_null(log_cmd_array[6]); - - free_strarray(log_cmd_array); - os_free(query); - os_free(type_predicate); - -} - -void test_w_macos_log_show_array_add_predicate_invalid_query_valid_type_and_predicate_null(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * query = NULL; - os_strdup("", query); - - char * type_predicate = NULL; - w_strdup("message CONTAINS \"test\"", type_predicate); - - w_macos_log_show_array_add_predicate(log_cmd_array, &log_cmd_array_idx, query, type_predicate); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_string_equal(log_cmd_array[6], "--predicate"); - assert_string_equal(log_cmd_array[7], "message CONTAINS \"test\""); - assert_null(log_cmd_array[8]); - - free_strarray(log_cmd_array); - os_free(query); - os_free(type_predicate); - -} - -void test_w_macos_log_show_array_add_predicate_valid_query_and_predicate_null(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * query = NULL; - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", query); - - char * type_predicate = NULL; - - w_macos_log_show_array_add_predicate(log_cmd_array, &log_cmd_array_idx, query, type_predicate); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_string_equal(log_cmd_array[6], "--predicate"); - assert_string_equal(log_cmd_array[7], "processImagePath CONTAINS[c] 'com.apple.geod'"); - assert_null(log_cmd_array[8]); - - free_strarray(log_cmd_array); - os_free(query); - os_free(type_predicate); - -} - -void test_w_macos_log_show_array_add_predicate_valid_query_and_predicate(void ** state) { - - size_t log_cmd_array_idx = 0; - char ** log_cmd_array = NULL; - - os_calloc(MAX_LOG_SHOW_CMD_ARGS + 1, sizeof(char *), log_cmd_array); - - /* Adding `log` and `show` to the array */ - w_strdup(LOG_CMD_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(LOG_SHOW_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the style lines to the array (`--style syslog`) */ - w_strdup(STYLE_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup(SYSLOG_STR, log_cmd_array[log_cmd_array_idx++]); - - /* Adding the starting date lines to the array (`--start 2021-04-27 12:29:25-0700`) */ - w_strdup(SHOW_START_OPT_STR, log_cmd_array[log_cmd_array_idx++]); - w_strdup("2021-04-27 12:29:25-0700", log_cmd_array[log_cmd_array_idx++]); - - char * query = NULL; - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", query); - - char * type_predicate = NULL; - os_strdup("eventType == logEvent", type_predicate); - - w_macos_log_show_array_add_predicate(log_cmd_array, &log_cmd_array_idx, query, type_predicate); - - assert_string_equal(log_cmd_array[0], "/usr/bin/log"); - assert_string_equal(log_cmd_array[1], "show"); - assert_string_equal(log_cmd_array[2], "--style"); - assert_string_equal(log_cmd_array[3], "syslog"); - assert_string_equal(log_cmd_array[4], "--start"); - assert_string_equal(log_cmd_array[5], "2021-04-27 12:29:25-0700"); - assert_string_equal(log_cmd_array[6], "--predicate"); - assert_string_equal(log_cmd_array[7], "( processImagePath CONTAINS[c] 'com.apple.geod' ) AND ( eventType == logEvent )"); - assert_null(log_cmd_array[8]); - - free_strarray(log_cmd_array); - os_free(query); - os_free(type_predicate); - -} - -/* w_macos_create_log_show_array */ - -void test_w_macos_create_log_show_array_complete(void ** state) { - - char start_date[25] = "2021-04-27 12:29:25-0700"; - - char * query = NULL; - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", query); - - char * level = MACOS_LOG_LEVEL_DEBUG_STR; - - int type = 7; - - char ** ret = w_macos_create_log_show_array(start_date, query, level, type); - - assert_string_equal(ret[0], "/usr/bin/log"); - assert_string_equal(ret[1], "show"); - assert_string_equal(ret[2], "--style"); - assert_string_equal(ret[3], "syslog"); - assert_string_equal(ret[4], "--start"); - assert_string_equal(ret[5], "2021-04-27 12:29:25-0700"); - assert_string_equal(ret[6], "--info"); - assert_string_equal(ret[7], "--debug"); - assert_string_equal(ret[8], "--predicate"); - assert_string_equal(ret[9], "( processImagePath CONTAINS[c] 'com.apple.geod' ) " \ - "AND ( eventType == activityCreateEvent " \ - "OR eventType == activityTransitionEvent " \ - "OR eventType == userActionEvent " \ - "OR eventType == logEvent OR eventType == traceEvent )"); - assert_null(ret[10]); - - free_strarray(ret); - os_free(query); - -} - -void test_w_macos_create_log_show_array_complete_on_sierra(void ** state) { - - char start_date[25] = "2021-04-27 12:29:25-0700"; - - char * query = NULL; - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", query); - - char * level = MACOS_LOG_LEVEL_DEBUG_STR; - - int type = 7; - - char * backup_codename = NULL; - - if (macos_codename != NULL) { - w_strdup(macos_codename, backup_codename); - } - - w_strdup(MACOS_SIERRA_CODENAME_STR, macos_codename); - - char ** ret = w_macos_create_log_show_array(start_date, query, level, type); - - assert_string_equal(ret[0], SCRIPT_CMD_STR); - assert_string_equal(ret[1], SCRIPT_CMD_ARGS); - assert_string_equal(ret[2], SCRIPT_CMD_SINK); - assert_string_equal(ret[3], "/usr/bin/log"); - assert_string_equal(ret[4], "show"); - assert_string_equal(ret[5], "--style"); - assert_string_equal(ret[6], "syslog"); - assert_string_equal(ret[7], "--start"); - assert_string_equal(ret[8], "2021-04-27 12:29:25-0700"); - assert_string_equal(ret[9], "--info"); - assert_string_equal(ret[10], "--debug"); - assert_string_equal(ret[11], "--predicate"); - assert_string_equal(ret[12], "( processImagePath CONTAINS[c] 'com.apple.geod' ) " \ - "AND ( eventType == activityCreateEvent " \ - "OR eventType == activityTransitionEvent " \ - "OR eventType == userActionEvent " \ - "OR eventType == logEvent OR eventType == traceEvent )"); - assert_null(ret[13]); - - free_strarray(ret); - os_free(query); - - os_free(macos_codename); - if (backup_codename != NULL) { - w_strdup(backup_codename, macos_codename); - os_free(backup_codename); - } -} - -/* w_macos_set_last_log_timestamp */ - -void test_w_macos_set_last_log_timestamp_complete(void ** state) { - - char * timestamp = NULL; - os_strdup("2021-04-27 12:29:25-0700", timestamp); - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - w_macos_set_last_log_timestamp(timestamp); - - os_free(timestamp); - -} - -/* w_macos_get_last_log_timestamp */ - -void test_w_macos_get_last_log_timestamp_complete(void ** state) { - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - char * ret = w_macos_get_last_log_timestamp(); - - assert_string_equal(ret, "2021-04-27 12:29:25-0700"); - - os_free(ret); - -} - -/* w_macos_set_log_settings */ - -void test_w_macos_set_log_settings_complete(void ** state) { - - char * settings = NULL; - os_strdup("test", settings); - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - w_macos_set_log_settings(settings); - - os_free(settings); - -} - -/* w_macos_get_log_settings */ - -void test_w_macos_get_log_settings_complete(void ** state) { - - os_strdup("test", macos_log_vault.settings); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - char * ret = w_macos_get_log_settings(); - - assert_string_equal(ret, "test"); - - os_free(ret); - -} - -/* w_macos_create_log_show_env */ - -void test_w_macos_create_log_show_env_timestamp_NULL(void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - // test_w_macos_get_last_log_timestamp_complete */ - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - w_macos_create_log_show_env(lf); - - os_free(lf->macos_log); - os_free(lf); - -} - -void test_w_macos_create_log_show_env_show_wfd_NULL(void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - - // test_w_macos_get_last_log_timestamp_complete - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - // test_w_macos_log_exec_wpopenv_error - will_return(__wrap_wpopenv, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1974): An error ocurred while calling wpopenv(): Success (0)."); - - expect_string(__wrap__merror, formatted_msg, "(1605): Error while trying to execute `log show` as follows: " \ - "/usr/bin/log show --style syslog --start 2021-04-27 12:29:25-0700 " \ - "--info --debug --predicate processImagePath CONTAINS[c] 'com.apple.geod'."); - - w_macos_create_log_show_env(lf); - - os_free(lf->macos_log->processes.show.wfd); - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); - -} - -void test_w_macos_create_log_show_env_success(void ** state) { - - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - - // test_w_macos_get_last_log_timestamp_complete - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - // test_w_macos_log_exec_success - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 1); - - will_return(__wrap_fcntl, 0); - - will_return(__wrap_fcntl, 0); - - expect_string(__wrap__minfo, formatted_msg, "(1603): Monitoring macOS old logs with: " \ - "/usr/bin/log show --style syslog --start 2021-04-27 12:29:25-0700 " \ - "--info --debug --predicate processImagePath CONTAINS[c] 'com.apple.geod'."); - - w_macos_create_log_show_env(lf); - - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); - -} - -/* w_macos_create_log_stream_env */ -void test_w_macos_create_log_stream_env_show_wfd_NULL(void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - - // test_w_macos_log_exec_wpopenv_error - will_return(__wrap_wpopenv, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1974): An error ocurred while calling wpopenv(): Success (0)."); - - expect_string(__wrap__merror, formatted_msg, "(1606): Error while trying to execute `log stream` as follows: " \ - "/usr/bin/log stream --style syslog --level debug " \ - "--predicate processImagePath CONTAINS[c] 'com.apple.geod'."); - - w_macos_create_log_stream_env(lf); - - os_free(lf->macos_log->processes.show.wfd); - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); - -} - -void test_w_macos_create_log_stream_env_success(void ** state) { - - wfd_t * wfd = *state; - wfd->file_out = (FILE*) 1234; - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - - // test_w_macos_log_exec_success - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fileno, __stream, wfd->file_out); - will_return(__wrap_fileno, 1); - - will_return(__wrap_fcntl, 0); - - will_return(__wrap_fcntl, 0); - - expect_string(__wrap__minfo, formatted_msg, "(1604): Monitoring macOS logs with: " \ - "/usr/bin/log stream --style syslog --level debug " \ - "--predicate processImagePath CONTAINS[c] 'com.apple.geod'."); - - w_macos_create_log_stream_env(lf); - - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); - -} - -void test_w_macos_create_log_env_codename_null_only_future (void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - lf->future = 1; // No past events - - will_return(__wrap_w_get_os_codename, NULL); - - // test_w_macos_is_log_executable_success - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - will_return(__wrap_wpopenv, NULL); - - expect_any(__wrap__merror, formatted_msg); - expect_any(__wrap__merror, formatted_msg); - - w_macos_create_log_env(lf, NULL); - - os_free(lf->macos_log->current_settings); - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); -} - -void test_w_macos_create_log_env_codename_not_null_only_future (void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - lf->future = 1; // No past events - - will_return(__wrap_w_get_os_codename, "macTEST"); - - // test_w_macos_is_log_executable_success - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Creating environment for macOS macTEST."); - - will_return(__wrap_wpopenv, NULL); - - expect_any(__wrap__merror, formatted_msg); - expect_any(__wrap__merror, formatted_msg); - - w_macos_create_log_env(lf, NULL); - - os_free(lf->macos_log->current_settings); - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); -} - -void test_w_macos_create_log_env_codename_null_previous_settings_null (void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - - lf->query_type = 0; - lf->future = 0; // Look for past events - macos_log_vault.settings = NULL; - - will_return(__wrap_w_get_os_codename, NULL); - - // test_w_macos_is_log_executable_success - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_wpopenv, NULL); - - expect_any(__wrap__merror, formatted_msg); - expect_any(__wrap__merror, formatted_msg); - - w_macos_create_log_env(lf, NULL); - - os_free(lf->macos_log->current_settings); - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); -} - -void test_w_macos_create_log_env_codename_null_current_and_previous_settings_missmatch (void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - lf->future = 0; // Look for past events - - /* Forces the missmatch */ - w_strdup("some random setting", macos_log_vault.settings); - - will_return(__wrap_w_get_os_codename, NULL); - - // test_w_macos_is_log_executable_success - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - /* For reading the */ - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Current predicate differs from the stored one. Discarding old events."); - - will_return(__wrap_wpopenv, NULL); - - expect_any(__wrap__merror, formatted_msg); - expect_any(__wrap__merror, formatted_msg); - - w_macos_create_log_env(lf, NULL); - - os_free(macos_log_vault.settings); - os_free(lf->macos_log->current_settings); - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); -} - -void test_w_macos_create_log_env_codename_null_settings_match (void ** state) { - - logreader *lf = NULL; - os_calloc(1, sizeof(logreader), lf); - os_calloc(1, sizeof(w_macos_log_config_t), lf->macos_log); - - os_strdup("processImagePath CONTAINS[c] 'com.apple.geod'", lf->query); - os_strdup(MACOS_LOG_LEVEL_DEBUG_STR, lf->query_level); - lf->query_type = 0; - lf->future = 0; // Look for past events - w_strdup("/usr/bin/log stream --style syslog --level debug --predicate processImagePath CONTAINS[c] 'com.apple.geod'", macos_log_vault.settings); - - bzero(macos_log_vault.timestamp, OS_LOGCOLLECTOR_TIMESTAMP_SHORT_LEN + 1); // Prevents log show execution - - will_return(__wrap_w_get_os_codename, NULL); - - // test_w_macos_is_log_executable_success - expect_string(__wrap_access, __name, "/usr/bin/log"); - expect_value(__wrap_access, __type, 1); - will_return(__wrap_access, 0); - - // w_macos_get_log_settings locks - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - // w_macos_get_last_log_timestamp locks - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - will_return(__wrap_wpopenv, NULL); - - expect_any(__wrap__merror, formatted_msg); - expect_any(__wrap__merror, formatted_msg); - - w_macos_create_log_env(lf, NULL); - - os_free(macos_log_vault.settings); - os_free(lf->macos_log->current_settings); - os_free(lf->query_level); - os_free(lf->query); - os_free(lf->macos_log); - os_free(lf); -} - -void test_w_macos_add_sierra_support(void ** state) { - - size_t index = 0; - char ** log_cmd_array_idx = NULL; - os_calloc(4, sizeof(char *), log_cmd_array_idx); - - w_macos_add_sierra_support(log_cmd_array_idx, &index); - - assert_int_equal(index, 3); - assert_string_equal(log_cmd_array_idx[0], SCRIPT_CMD_STR); - assert_string_equal(log_cmd_array_idx[1], SCRIPT_CMD_ARGS); - assert_string_equal(log_cmd_array_idx[2], SCRIPT_CMD_SINK); - - free_strarray(log_cmd_array_idx); -} - -void test_w_get_first_child_NULL(void ** state) { - - will_return(__wrap_w_get_process_childs, NULL); - - assert_int_equal(w_get_first_child(0), 0); -} - -void test_w_get_first_child_non_null_non_zero(void ** state) { - - pid_t * pid_array = NULL; - - os_calloc(4, sizeof(pid_t), pid_array); - - pid_array[0] = 7; - pid_array[1] = 9; - pid_array[2] = 11; - pid_array[3] = 0; - - will_return(__wrap_w_get_process_childs, pid_array); - - assert_int_equal(w_get_first_child(0), 7); -} - -void test_w_get_first_child_non_null_zero(void ** state) { - - pid_t * pid_array = NULL; - - os_calloc(4, sizeof(pid_t), pid_array); - - pid_array[0] = 0; - pid_array[1] = 9; - pid_array[2] = 11; - pid_array[3] = 20; - - will_return(__wrap_w_get_process_childs, pid_array); - - assert_int_equal(w_get_first_child(0), 0); -} - -// Test w_macos_set_is_valid_data -void test_w_macos_set_is_valid_data_ok(void ** state) { - - bool bak_is_valid_data = macos_log_vault.is_valid_data; - macos_log_vault.is_valid_data = false; - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - w_macos_set_is_valid_data(true); - - assert_true(macos_log_vault.is_valid_data); - macos_log_vault.is_valid_data = bak_is_valid_data; - -} - -// Test w_macos_get_is_valid_data -void test_w_macos_get_is_valid_data_ok(void ** state) { - - bool bak_is_valid_data = macos_log_vault.is_valid_data; - macos_log_vault.is_valid_data = false; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - assert_false(w_macos_get_is_valid_data()); - macos_log_vault.is_valid_data = bak_is_valid_data; -} - -int main(void) { - - const struct CMUnitTest tests[] = { - // Test w_macos_is_log_predicate_valid - cmocka_unit_test(test_w_macos_is_log_predicate_valid_empty), - cmocka_unit_test(test_w_macos_is_log_predicate_valid_existing), - // Test w_macos_create_log_stream_array - cmocka_unit_test(test_w_macos_create_log_stream_array_NULL), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity_log), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity_log_trace), - cmocka_unit_test(test_w_macos_create_log_stream_array_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_type_activity_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_default_type_activity_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_info_type_activity_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity_log_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_level_debug_type_activity_log_trace_predicate), - cmocka_unit_test(test_w_macos_create_log_stream_array_on_sierra), - // Test w_macos_log_exec - cmocka_unit_test(test_w_macos_log_exec_wpopenv_error), - cmocka_unit_test_setup_teardown(test_w_macos_log_exec_fileno_error, setup_file, teardown_file), - cmocka_unit_test_setup_teardown(test_w_macos_log_exec_fp_to_fd_error, setup_file, teardown_file), - cmocka_unit_test_setup_teardown(test_w_macos_log_exec_get_flags_error, setup_file, teardown_file), - cmocka_unit_test_setup_teardown(test_w_macos_log_exec_set_flags_error, setup_file, teardown_file), - cmocka_unit_test_setup_teardown(test_w_macos_log_exec_success, setup_file, teardown_file), - // Test w_macos_is_log_executable - cmocka_unit_test(test_w_macos_is_log_executable_success), - cmocka_unit_test(test_w_macos_is_log_executable_error), - cmocka_unit_test(test_w_macos_is_log_executable_sierra_access_fail), - // Test w_macos_log_show_array_add_level - cmocka_unit_test(test_w_macos_log_show_array_add_level_NULL), - cmocka_unit_test(test_w_macos_log_show_array_add_level_default), - cmocka_unit_test(test_w_macos_log_show_array_add_level_info), - cmocka_unit_test(test_w_macos_log_show_array_add_level_debug), - // Test w_macos_log_show_create_type_predicate - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_NULL), - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_activity), - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_log), - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_trace), - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_activity_log), - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_activity_trace), - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_log_trace), - cmocka_unit_test(test_w_macos_log_show_create_type_predicate_activity_log_trace), - // Test w_macos_log_show_array_add_predicate - cmocka_unit_test(test_w_macos_log_show_array_add_predicate_query_and_predicate_null), - cmocka_unit_test(test_w_macos_log_show_array_add_predicate_query_null_and_valid_predicate), - cmocka_unit_test(test_w_macos_log_show_array_add_predicate_invalid_query_and_predicate_null), - cmocka_unit_test(test_w_macos_log_show_array_add_predicate_invalid_query_valid_type_and_predicate_null), - cmocka_unit_test(test_w_macos_log_show_array_add_predicate_valid_query_and_predicate_null), - cmocka_unit_test(test_w_macos_log_show_array_add_predicate_valid_query_and_predicate), - // Test w_macos_create_log_show_array - cmocka_unit_test(test_w_macos_create_log_show_array_complete), - cmocka_unit_test(test_w_macos_create_log_show_array_complete_on_sierra), - // Test w_macos_set_last_log_timestamp - cmocka_unit_test(test_w_macos_set_last_log_timestamp_complete), - // Test w_macos_get_last_log_timestamp - cmocka_unit_test(test_w_macos_get_last_log_timestamp_complete), - // Test w_macos_set_log_settings - cmocka_unit_test_teardown(test_w_macos_set_log_settings_complete, teardown_settings), - // Test w_macos_get_log_settings - cmocka_unit_test_teardown(test_w_macos_get_log_settings_complete, teardown_settings), - // Test w_macos_create_log_show_env - cmocka_unit_test_setup_teardown(test_w_macos_create_log_show_env_timestamp_NULL, setup_timestamp_null, teardown_timestamp_null), - cmocka_unit_test(test_w_macos_create_log_show_env_show_wfd_NULL), - cmocka_unit_test_setup_teardown(test_w_macos_create_log_show_env_success, setup_file, teardown_file), - // Test w_macos_create_log_stream_env - cmocka_unit_test(test_w_macos_create_log_stream_env_show_wfd_NULL), - cmocka_unit_test_setup_teardown(test_w_macos_create_log_stream_env_success, setup_file, teardown_file), - // Test w_macos_create_log_env - cmocka_unit_test(test_w_macos_create_log_env_codename_null_only_future), - cmocka_unit_test(test_w_macos_create_log_env_codename_not_null_only_future), - cmocka_unit_test(test_w_macos_create_log_env_codename_null_previous_settings_null), - cmocka_unit_test(test_w_macos_create_log_env_codename_null_current_and_previous_settings_missmatch), - cmocka_unit_test(test_w_macos_create_log_env_codename_null_settings_match), - // Test w_macos_add_sierra_support - cmocka_unit_test(test_w_macos_add_sierra_support), - // Test w_get_first_child - cmocka_unit_test(test_w_get_first_child_NULL), - cmocka_unit_test(test_w_get_first_child_non_null_non_zero), - cmocka_unit_test(test_w_get_first_child_non_null_zero), - // Test w_macos_set_is_valid_data - cmocka_unit_test(test_w_macos_set_is_valid_data_ok), - // Test w_macos_get_is_valid_data - cmocka_unit_test(test_w_macos_get_is_valid_data_ok), - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/logcollector/test_read_journal.c b/src/unit_tests/logcollector/test_read_journal.c deleted file mode 100644 index 2080a895f14..00000000000 --- a/src/unit_tests/logcollector/test_read_journal.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -/* Includes */ - -#include -#include -#include -#include -#include -#include - -#include "../../logcollector/logcollector.h" -#include "../../logcollector/journal_log.h" -#include "../../headers/shared.h" -#include "../wrappers/common.h" - -bool w_journald_can_read(unsigned long owner_id); -void set_gs_journald_global(unsigned long owner_id, bool is_disabled, void * journal_ctx); - -/* setup/teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -/* Wraps of journal_log */ -int __wrap_w_journal_context_create(w_journal_context_t ** ctx) { return mock_type(int); } - -int __wrap_w_journal_context_seek_most_recent(w_journal_context_t * ctx) { return mock_type(int); } - -int __wrap_w_journal_context_seek_timestamp(w_journal_context_t * ctx, uint64_t timestamp) { - // check timestamp - check_expected(timestamp); - return mock_type(int); -} - -int __wrap_w_journal_context_next_newest_filtered(w_journal_context_t * ctx, w_journal_filters_list_t filters) { - return mock_type(int); -} - -w_journal_entry_t * __wrap_w_journal_entry_dump(w_journal_context_t * ctx, w_journal_entry_dump_type_t type) { - return mock_type(w_journal_entry_t *); -} - -char * __wrap_w_journal_entry_to_string(w_journal_entry_t * entry) { return mock_type(char *); } - -void __wrap_w_journal_entry_free(w_journal_entry_t * entry) { function_called(); } - -/* Aux setters */ -void set_gs_journald_ofe(bool exist, bool ofe, uint64_t timestamp); -bool journald_isDisabled(); - -/* Other wraps */ -int __wrap_isDebug() { return mock(); } - -int __wrap_w_msg_hash_queues_push( - const char * str, char * file, unsigned long size, logtarget * targets, char queue_mq) { - check_expected(str); - check_expected(size); - return mock_type(int); -} - -int __wrap_can_read() { return mock_type(int); } - -/* Test w_journald_can_read */ -void test_w_journald_can_read_disable(void ** state) { - set_gs_journald_global(0, true, NULL); - assert_false(w_journald_can_read(0)); -} - -void test_w_journald_can_read_check_owner(void ** state) { - set_gs_journald_global(2, false, NULL); - assert_false(w_journald_can_read(1)); - assert_true(w_journald_can_read(2)); -} - -void test_w_journald_can_read_first_time_init_fail() { - int tid = 3; - - set_gs_journald_global(0, false, NULL); - - will_return(__wrap_w_journal_context_create, -1); - expect_string(__wrap__merror, formatted_msg, "(1608): Failed to connect to the journal, disabling journal log."); - - assert_false(w_journald_can_read(tid)); - assert_true(journald_isDisabled()); -} - -void test_w_journald_can_read_first_time_init_fail_seek() { - int tid = 3; - - set_gs_journald_global(0, false, NULL); - set_gs_journald_ofe(true, true, 123); - - will_return(__wrap_w_journal_context_create, 0); - - will_return(__wrap_w_journal_context_seek_most_recent, -1); - - expect_string(__wrap__merror, - formatted_msg, - "(1609): Failed to move to the end of the journal, disabling journal log: Operation not permitted."); - - assert_false(w_journald_can_read(tid)); - assert_true(journald_isDisabled()); -} - -void test_w_journald_can_read_first_time_init_ofe_yes(void ** state) { - - int tid = 3; - - set_gs_journald_global(0, false, NULL); - set_gs_journald_ofe(true, true, 123); - - will_return(__wrap_w_journal_context_create, 0); - - will_return(__wrap_w_journal_context_seek_most_recent, 0); - - expect_string(__wrap__minfo, formatted_msg, "(9203): Monitoring journal entries."); - - assert_true(w_journald_can_read(tid)); - assert_false(journald_isDisabled()); -} - -void test_w_journald_can_read_first_time_init_ofe_no(void ** state) { - int tid = 3; - - set_gs_journald_global(0, false, NULL); - set_gs_journald_ofe(true, false, 123); - - will_return(__wrap_w_journal_context_create, 0); - - expect_value(__wrap_w_journal_context_seek_timestamp, timestamp, 123); - will_return(__wrap_w_journal_context_seek_timestamp, 0); - - expect_string(__wrap__minfo, formatted_msg, "(9203): Monitoring journal entries."); - - assert_true(w_journald_can_read(tid)); - assert_false(journald_isDisabled()); -} - -/* w_journald_set_ofe */ -void test_w_journald_set_ofe(void ** state) { - w_journald_set_ofe(true); - w_journald_set_ofe(false); -} - -void test_read_journald_can_read_false(void ** state) { - - // Prepare environment - w_journal_context_t ctxt = {0}; - set_gs_journald_global(0, false, &ctxt); - - // Prepare args - logreader lf = {0}; - w_journal_log_config_t journal_log = {0}; - lf.journal_log = &journal_log; - int rc = 0; - - will_return(__wrap_can_read, 0); - - assert_null(read_journald(&lf, &rc, 0)); - assert_false(journald_isDisabled()); -} - -void test_read_journald_next_entry_error(void ** state) { - // Prepare environment - w_journal_context_t ctxt = {0}; - set_gs_journald_global(0, false, &ctxt); - - // Prepare args - logreader lf = {0}; - w_journal_log_config_t journal_log = {0}; - lf.journal_log = &journal_log; - int rc = 0; - - // Can read - will_return(__wrap_can_read, 1); - - // Fail get nex entry - will_return(__wrap_w_journal_context_next_newest_filtered, -1); - expect_string(__wrap__merror, - formatted_msg, - "(1610): Failed to get the next entry, disabling journal log: Operation not permitted."); - - assert_null(read_journald(&lf, &rc, 0)); - assert_true(journald_isDisabled()); -} - -void test_read_journald_next_entry_no_new_entry(void ** state) { - - // Prepare environment - w_journal_context_t ctxt = {0}; - set_gs_journald_global(0, false, &ctxt); - - // Prepare args - logreader lf = {0}; - w_journal_log_config_t journal_log = {0}; - lf.journal_log = &journal_log; - int rc = 0; - - // Can read - will_return(__wrap_can_read, 1); - - // Nothing to read - will_return(__wrap_w_journal_context_next_newest_filtered, 0); - expect_string(__wrap__mdebug2, formatted_msg, "(9006): No new entries in the journal."); - - assert_null(read_journald(&lf, &rc, 0)); - assert_false(journald_isDisabled()); -} - -void test_read_journald_dump_entry_error(void ** state) { - - // Prepare environment - w_journal_context_t ctxt = {0}; - set_gs_journald_global(0, false, &ctxt); - - // Prepare args - logreader lf = {0}; - w_journal_log_config_t journal_log = {0}; - lf.journal_log = &journal_log; - int rc = 0; - - // Can read - will_return(__wrap_can_read, 1); - - // Fail get nex entry - will_return(__wrap_w_journal_context_next_newest_filtered, 1); - will_return(__wrap_w_journal_entry_dump, NULL); - will_return(__wrap_w_journal_entry_to_string, NULL); - expect_function_call(__wrap_w_journal_entry_free); - - expect_string(__wrap__merror, formatted_msg, "(1611): Failed to get the message from the journal"); - - assert_null(read_journald(&lf, &rc, 0)); - assert_false(journald_isDisabled()); -} - -void test_read_journald_dump_entry_max_len(void ** state) { - - // Prepare environment - w_journal_context_t ctxt = {0}; - set_gs_journald_global(0, false, &ctxt); - - // Prepare args - logreader lf = {0}; - w_journal_log_config_t journal_log = {0}; - lf.journal_log = &journal_log; - int rc = 0; - - // Can read - will_return(__wrap_can_read, 1); - - // Fail get nex entry - will_return(__wrap_w_journal_context_next_newest_filtered, 1); - will_return(__wrap_w_journal_entry_dump, 0x1); - will_return(__wrap_w_journal_entry_to_string, strdup("MAX_STR_>>>_16_|xxxxxxxx")); - expect_function_call(__wrap_w_journal_entry_free); - - expect_string( - __wrap__mdebug1, formatted_msg, "(9007): Message size > maximum allowed, The message will be truncated."); - - will_return(__wrap_isDebug, 0); - - // Check message - expect_string(__wrap_w_msg_hash_queues_push, str, "MAX_STR_>>>_16_|"); - expect_value(__wrap_w_msg_hash_queues_push, size, strlen("MAX_STR_>>>_16_|") + 1); - will_return(__wrap_w_msg_hash_queues_push, 0); - - // Brek the loop - will_return(__wrap_can_read, 0); - - assert_null(read_journald(&lf, &rc, 0)); - assert_false(journald_isDisabled()); -} - -void test_read_journald_dump_entry_debug(void ** state) { - - // Prepare environment - w_journal_context_t ctxt = {0}; - set_gs_journald_global(0, false, &ctxt); - - // Prepare args - logreader lf = {0}; - w_journal_log_config_t journal_log = {0}; - lf.journal_log = &journal_log; - int rc = 0; - - // Can read - will_return(__wrap_can_read, 1); - - // Fail get nex entry - will_return(__wrap_w_journal_context_next_newest_filtered, 1); - will_return(__wrap_w_journal_entry_dump, 0x1); - will_return(__wrap_w_journal_entry_to_string, strdup("message test")); - expect_function_call(__wrap_w_journal_entry_free); - - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mdebug2, formatted_msg, "(9008): Reading from journal: 'message test'."); - - // Check message - expect_string(__wrap_w_msg_hash_queues_push, str, "message test"); - expect_value(__wrap_w_msg_hash_queues_push, size, strlen("message test") + 1); - will_return(__wrap_w_msg_hash_queues_push, 0); - - // Brek the loop - will_return(__wrap_can_read, 0); - - assert_null(read_journald(&lf, &rc, 0)); - assert_false(journald_isDisabled()); -} - -int main(void) { - - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_w_journald_set_ofe), - /* Test w_journald_can_read */ - cmocka_unit_test(test_w_journald_can_read_disable), - cmocka_unit_test(test_w_journald_can_read_check_owner), - cmocka_unit_test(test_w_journald_can_read_first_time_init_fail), - cmocka_unit_test(test_w_journald_can_read_first_time_init_fail_seek), - cmocka_unit_test(test_w_journald_can_read_first_time_init_ofe_yes), - cmocka_unit_test(test_w_journald_can_read_first_time_init_ofe_no), - /* Test read_journald */ - cmocka_unit_test(test_read_journald_can_read_false), - cmocka_unit_test(test_read_journald_next_entry_error), - cmocka_unit_test(test_read_journald_next_entry_no_new_entry), - cmocka_unit_test(test_read_journald_dump_entry_error), - cmocka_unit_test(test_read_journald_dump_entry_max_len), - cmocka_unit_test(test_read_journald_dump_entry_debug), - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/logcollector/test_read_macos.c b/src/unit_tests/logcollector/test_read_macos.c deleted file mode 100644 index ca53f412b9b..00000000000 --- a/src/unit_tests/logcollector/test_read_macos.c +++ /dev/null @@ -1,1945 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -/* Includes */ - -#include -#include -#include -#include -#include -#include - -#include "../../logcollector/logcollector.h" -#include "../../headers/shared.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/linux/socket_wrappers.h" -#include "../wrappers/wazuh/shared/expression_wrappers.h" -#include "../wrappers/wazuh/logcollector/logcollector_wrappers.h" -#include "../wrappers/wazuh/logcollector/macos_log_wrappers.h" -#include "../wrappers/posix/signal_wrappers.h" -#include "../wrappers/linux/wait_wrappers.h" -#include "../wrappers/posix/time_wrappers.h" - -/* Defines */ - -#define TESTING_MAXIMUM_LINES 1000 - -/* Prototypes */ - -bool w_macos_log_ctxt_restore(char * buffer, w_macos_log_ctxt_t * ctxt); -void w_macos_log_ctxt_backup(char * buffer, w_macos_log_ctxt_t * ctxt); -void w_macos_log_ctxt_clean(w_macos_log_ctxt_t * ctxt); -bool w_macos_is_log_ctxt_expired(time_t timeout, w_macos_log_ctxt_t * ctxt); -char * w_macos_log_get_last_valid_line(char * str); -bool w_macos_is_log_header(w_macos_log_config_t * macos_log_cfg, char * buffer); -bool w_macos_log_getlog(char * buffer, int length, FILE * stream, w_macos_log_config_t * macos_log_cfg); -char * w_macos_trim_full_timestamp(char *); -char * w_macos_get_last_log_timestamp(void); - -/* Globals */ - -extern w_macos_log_procceses_t * macos_processes; - -extern int maximum_lines; -extern int errno; - -/* Tests */ - -/* setup/teardown */ - -static int group_setup(void ** state) { - - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - - test_mode = 0; - return 0; -} - -/* wraps */ - -int __wrap_isDebug() { - return mock(); -} - -int __wrap_can_read() { - - return mock_type(int); -} - -// todo: this function is repeated in other file -int __wrap_w_msg_hash_queues_push(void) { - - return mock_type(int); -} - -/* tests */ - -/* w_macos_log_ctxt_restore */ - -void test_w_macos_log_ctxt_restore_false(void ** state) { - - w_macos_log_ctxt_t ctxt; - ctxt.buffer[0] = '\0'; - - char * buffer = NULL; - - bool ret = w_macos_log_ctxt_restore(buffer, &ctxt); - assert_false(ret); -} - -void test_w_macos_log_ctxt_restore_true(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - bool ret = w_macos_log_ctxt_restore(buffer, &ctxt); - assert_true(ret); -} - -/* w_macos_log_ctxt_backup */ - -void test_w_macos_log_ctxt_backup_success(void ** state) { - - w_macos_log_ctxt_t ctxt; - char buffer[OS_MAXSTR + 1]; - - buffer[OS_MAXSTR] = '\0'; - - strncpy(buffer, "test\n", OS_MAXSTR); - will_return(__wrap_time, 123456); - - w_macos_log_ctxt_backup(buffer, &ctxt); - - assert_string_equal(ctxt.buffer, "test\n"); - assert_int_equal(ctxt.timestamp, 123456); -} - -/* w_macos_log_ctxt_clean */ - -void test_w_macos_log_ctxt_clean_success(void ** state) { - - w_macos_log_ctxt_t ctxt; - - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - ctxt.timestamp = 123456; - - - w_macos_log_ctxt_clean(&ctxt); - - assert_int_equal(ctxt.timestamp, 0); - assert_string_equal(ctxt.buffer, "\0"); -} - -/* w_macos_is_log_ctxt_expired */ - -void test_w_macos_is_log_ctxt_expired_true(void ** state) { - - w_macos_log_ctxt_t ctxt; - time_t timeout = (time_t) MACOS_LOG_TIMEOUT; - - ctxt.timestamp = (time_t) 1000; - - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - bool ret = w_macos_is_log_ctxt_expired(timeout, &ctxt); - - assert_true(ret); -} - -void test_w_macos_is_log_ctxt_expired_false(void ** state) { - - w_macos_log_ctxt_t ctxt; - time_t timeout = (time_t) MACOS_LOG_TIMEOUT; - - ctxt.timestamp = 1000; - - // threshold timeout - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT); - - bool ret = w_macos_is_log_ctxt_expired(timeout, &ctxt); - - assert_false(ret); -} - -/* w_macos_log_get_last_valid_line */ - -void test_w_macos_log_get_last_valid_line_str_null(void ** state) { - - char * str = NULL; - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_null(ret); -} - -void test_w_macos_log_get_last_valid_line_str_empty(void ** state) { - - char * str = '\0'; - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_null(ret); -} - -void test_w_macos_log_get_last_valid_line_str_without_new_line(void ** state) { - - char * str = NULL; - - os_strdup("2021-04-22 12:00:00.230270-0700 test", str); - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_null(ret); - os_free(str); -} - -void test_w_macos_log_get_last_valid_line_str_with_new_line_end(void ** state) { - - char * str = NULL; - - os_strdup("2021-04-22 12:00:00.230270-0700 test\n", str); - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_null(ret); - os_free(str); -} - -void test_w_macos_log_get_last_valid_line_str_with_new_line_not_end(void ** state) { - - char * str = NULL; - - os_strdup("2021-04-22 12:00:00.230270-0700 test\n2021-04-22 12:00:00.230270-0700 test2", str); - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_string_equal(ret, "\n2021-04-22 12:00:00.230270-0700 test2"); - os_free(str); -} - -void test_w_macos_log_get_last_valid_line_str_with_two_new_lines_end(void ** state) { - - char * str = NULL; - - os_strdup("2021-04-22 12:00:00.230270-0700 test\n2021-04-22 12:00:00.230270-0700 test2\n", str); - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_string_equal(ret, "\n2021-04-22 12:00:00.230270-0700 test2\n"); - os_free(str); -} - -void test_w_macos_log_get_last_valid_line_str_with_two_new_lines_not_end(void ** state) { - - char * str = NULL; - - os_strdup("2021-04-22 12:00:00.230270-0700 test\n2021-04-22 12:00:00.230270-0700 test2\n2021-04-22 12:00:00.230270-0700 test3", str); - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_string_equal(ret, "\n2021-04-22 12:00:00.230270-0700 test3"); - os_free(str); -} - -void test_w_macos_log_get_last_valid_line_str_with_three_new_lines_end(void ** state) { - - char * str = NULL; - - os_strdup("2021-04-22 12:00:00.230270-0700 test\n2021-04-22 12:00:00.230270-0700 test2\n2021-04-22 12:00:00.230270-0700 test3\n", str); - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_string_equal(ret, "\n2021-04-22 12:00:00.230270-0700 test3\n"); - os_free(str); -} - -void test_w_macos_log_get_last_valid_line_str_with_three_new_lines_not_end(void ** state) { - - char * str = NULL; - - os_strdup("2021-04-22 12:00:00.230270-0700 test\n2021-04-22 12:00:00.230270-0700 test2\n2021-04-22 12:00:00.230270-0700 test3\n2021-04-22 12:00:00.230270-0700 test4", str); - - char * ret = w_macos_log_get_last_valid_line(str); - - assert_string_equal(ret, "\n2021-04-22 12:00:00.230270-0700 test4"); - os_free(str); -} - -/* w_macos_is_log_header */ - -void test_w_macos_is_log_header_false(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char * buffer = NULL; - os_strdup("test", buffer); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.log_start_regex = NULL; - macos_log_cfg.is_header_processed = false; - - will_return(__wrap_w_expression_match, true); - expect_value(__wrap_w_macos_set_is_valid_data, is_valid, true); - - bool ret = w_macos_is_log_header(& macos_log_cfg, buffer); - - assert_false(ret); - - os_free(buffer); -} - -void test_w_macos_is_log_header_log_stream_execution_error_after_exec(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char * buffer = NULL; - os_strdup("log: test", buffer); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.log_start_regex = NULL; - macos_log_cfg.is_header_processed = true; - - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__merror, formatted_msg, "(1602): Execution error 'log: test'"); - - expect_value(__wrap_w_macos_set_is_valid_data, is_valid, false); - - bool ret = w_macos_is_log_header(&macos_log_cfg, buffer); - - assert_true(ret); - - os_free(buffer); -} - -void test_w_macos_is_log_header_log_stream_execution_error_colon(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char * buffer = NULL; - os_strdup("log: ", buffer); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.log_start_regex = NULL; - macos_log_cfg.is_header_processed = true; - - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__merror, formatted_msg, "(1602): Execution error 'log'"); - expect_value(__wrap_w_macos_set_is_valid_data, is_valid, false); - - bool ret = w_macos_is_log_header(& macos_log_cfg, buffer); - - assert_true(ret); - - os_free(buffer); -} - -void test_w_macos_is_log_header_log_stream_execution_error_line_break(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char * buffer = NULL; - os_strdup("log: test\n", buffer); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.log_start_regex = NULL; - macos_log_cfg.is_header_processed = true; - - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__merror, formatted_msg, "(1602): Execution error 'log: test'"); - expect_value(__wrap_w_macos_set_is_valid_data, is_valid, false); - - bool ret = w_macos_is_log_header(& macos_log_cfg, buffer); - - assert_true(ret); - - os_free(buffer); -} - -void test_w_macos_is_log_header_reading_other_log(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char * buffer = NULL; - os_strdup("test", buffer); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.log_start_regex = NULL; - macos_log_cfg.is_header_processed = false; - - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Reading other log headers or errors: 'test'."); - - bool ret = w_macos_is_log_header(& macos_log_cfg, buffer); - - assert_true(ret); - - os_free(buffer); -} - -void test_w_macos_is_log_header_reading_other_log_line_break(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char * buffer = NULL; - os_strdup("test\n", buffer); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.log_start_regex = NULL; - macos_log_cfg.is_header_processed = false; - - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Reading other log headers or errors: 'test'."); - - bool ret = w_macos_is_log_header(& macos_log_cfg, buffer); - - assert_true(ret); - - os_free(buffer); -} - -/* w_macos_log_getlog */ -void test_w_macos_log_getlog_context_expired(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_true - ctxt.timestamp = (time_t) 1000; - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR - OS_LOG_HEADER; - - FILE * stream = NULL; - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_true(ret); - assert_string_equal(buffer, "test"); -} - -void test_w_macos_log_getlog_context_expired_new_line(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_true - ctxt.timestamp = (time_t) 1000; - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR - OS_LOG_HEADER; - - FILE * stream = NULL; - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_true(ret); - assert_string_equal(buffer, "test"); -} - -void test_w_macos_log_getlog_context_not_expired(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR - OS_LOG_HEADER; - - FILE * stream = (FILE*)1; - - will_return(__wrap_can_read, 1); - - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, NULL); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_false(ret); - assert_string_equal("test\n", macos_log_cfg.ctxt.buffer); - assert_int_equal(ctxt.timestamp, 1000); -} - -void test_w_macos_log_getlog_context_buffer_full(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\n", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = strlen(ctxt.buffer) + 1; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test"); - - //test_w_macos_log_get_last_valid_line - - will_return(__wrap_isDebug, 0); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, "test"); - assert_true(ret); - - os_free(stream); -} - -void test_w_macos_log_getlog_context_buffer_full_no_endl_force_split(void ** state) { - - /* It must split the log, because the last line received (incomplete) can be part of a second log */ - w_macos_log_ctxt_t ctxt; - ctxt.buffer[0] = '\0'; - ctxt.timestamp = 1000; - ctxt.force_send = false; - - const char *test_str = "test large\nlog"; - char buffer[OS_MAXSTR + 1]; - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = strlen(test_str) + 1; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, test_str); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Maximum message length reached. The remainder will be send separately."); - will_return(__wrap_time, 1000); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, "test large"); - assert_string_equal(macos_log_cfg.ctxt.buffer, "log"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1000); - assert_true(ret); - - os_free(stream); -} - -void test_w_macos_log_getlog_context_not_endline(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test-\0", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = strlen(ctxt.buffer) + 10; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Incomplete message."); - will_return(__wrap_time, ctxt.timestamp + 1); - - //test_w_macos_log_ctxt_backup_success - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(macos_log_cfg.ctxt.buffer, "test-test"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1000 + 1); - assert_false(ret); - - os_free(stream); -} - -void test_w_macos_log_getlog_context_full_buffer(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test--max...\0", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "more content................"); - int length = strlen(ctxt.buffer) + strlen("more content...") + 1; - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_fgetc, '\n'); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Maximum message length reached. The remainder was discarded."); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, "test--max...more content..."); - assert_string_equal("", macos_log_cfg.ctxt.buffer); - assert_int_equal(0, macos_log_cfg.ctxt.timestamp); - assert_true(ret); - - os_free(stream); -} - -void test_w_macos_log_getlog_discards_irrelevant_headers(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "Other headers, line1\n\0", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = false; - - int length = strlen(ctxt.buffer) + 100; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "Other headers, line2\n"); - - will_return(__wrap_w_is_macos_sierra, false); - - //test_w_macos_is_log_header_reading_other_log - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Reading other log headers or errors:" - " 'Other headers, line1\nOther headers, line2'."); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, ""); - assert_true(ret); - - os_free(stream); -} - -void test_w_macos_log_getlog_discards_irrelevant_headers_sierra_child_processes_already_set(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "Other headers, line1\n\0", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = false; - macos_log_cfg.processes.show.wfd = (wfd_t*) 123; - macos_log_cfg.processes.stream.wfd = (wfd_t*) 124; - macos_log_cfg.processes.show.child = 5; - macos_log_cfg.processes.stream.child = 6; - - int length = strlen(ctxt.buffer) + 100; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "Other headers, line2\n"); - - will_return(__wrap_w_is_macos_sierra, true); - - //test_w_macos_is_log_header_reading_other_log - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Reading other log headers or errors:" - " 'Other headers, line1\nOther headers, line2'."); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, ""); - assert_true(ret); - assert(macos_log_cfg.processes.show.child == 5); - assert(macos_log_cfg.processes.stream.child == 6); - - os_free(stream); -} - -void test_w_macos_log_getlog_discards_irrelevant_headers_sierra_stream_and_show_without_child_pid(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "Other headers, line1\n\0", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = false; - os_calloc(1, sizeof(wfd_t), macos_log_cfg.processes.show.wfd); - os_calloc(1, sizeof(wfd_t), macos_log_cfg.processes.stream.wfd); - macos_log_cfg.processes.show.wfd->pid = 10; - macos_log_cfg.processes.stream.wfd->pid = 11; - macos_log_cfg.processes.show.child = 0; - macos_log_cfg.processes.stream.child = 0; - - int length = strlen(ctxt.buffer) + 100; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "Other headers, line2\n"); - - will_return(__wrap_w_is_macos_sierra, true); - expect_value(__wrap_w_get_first_child, parent_pid, 10); - will_return(__wrap_w_get_first_child, 5); - expect_value(__wrap_w_get_first_child, parent_pid, 11); - will_return(__wrap_w_get_first_child, 6); - - - //test_w_macos_is_log_header_reading_other_log - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Reading other log headers or errors:" - " 'Other headers, line1\nOther headers, line2'."); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, ""); - assert_true(ret); - assert(macos_log_cfg.processes.show.child == 5); - assert(macos_log_cfg.processes.stream.child == 6); - - os_free(stream); - os_free(macos_log_cfg.processes.show.wfd); - os_free(macos_log_cfg.processes.stream.wfd); -} - -void test_w_macos_log_getlog_split_two_logs(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "log 1 first line\nlog 1 second line\n", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = strlen(ctxt.buffer) + 100; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "log 2 first line\r\n"); - - //test_w_macos_log_get_last_valid_line - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_w_expression_match, true); - will_return(__wrap_time, 1001); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, "log 1 first line\nlog 1 second line"); - assert_string_equal(macos_log_cfg.ctxt.buffer, "log 2 first line\n"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1001); - assert_true(ret); - - os_free(stream); -} - -void test_w_macos_log_getlog_backup_context(void ** state) { - - w_macos_log_ctxt_t ctxt; - ctxt.buffer[0] = '\0'; - ctxt.timestamp = 0; - ctxt.force_send = false; - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test\n"); - will_return(__wrap_time, 1000); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - will_return(__wrap_isDebug, 0); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_false(ret); - assert_string_equal(macos_log_cfg.ctxt.buffer, "test\n"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1000); - - os_free(stream); -} - -void test_w_macos_log_getlog_backup_context_sierra(void ** state) { - - w_macos_log_ctxt_t ctxt; - ctxt.buffer[0] = '\0'; - ctxt.timestamp = 0; - ctxt.force_send = false; - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test\r\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_time, 1000); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_false(ret); - assert_string_equal(macos_log_cfg.ctxt.buffer, "test\n"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1000); - - os_free(stream); -} - -void test_w_macos_log_getlog_backup_context_sierra_multiline(void ** state) { - - w_macos_log_ctxt_t ctxt; - ctxt.buffer[0] = '\0'; - ctxt.timestamp = 0; - ctxt.force_send = false; - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test multiline line 1\r\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_time, 1000); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test multiline line 2\r\n"); - will_return(__wrap_w_expression_match, false); - will_return(__wrap_time, 1000); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - will_return(__wrap_isDebug, 0); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_false(ret); - assert_string_equal(macos_log_cfg.ctxt.buffer, "test multiline line 1\ntest multiline line 2\n"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1000); - - os_free(stream); -} - -void test_w_macos_log_getlog_backup_context_sierra_new_line(void ** state) { - - w_macos_log_ctxt_t ctxt; - ctxt.buffer[0] = '\0'; - ctxt.timestamp = 0; - ctxt.force_send = false; - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "\r\n"); - will_return(__wrap_time, 1000); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - will_return(__wrap_isDebug, 0); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_false(ret); - assert_string_equal(macos_log_cfg.ctxt.buffer, "\n"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1000); - - os_free(stream); -} - -void test_w_macos_log_getlog_cannot_read(void ** state) { - - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test", OS_MAXSTR); - ctxt.force_send = false; - time_t now = 1000; - ctxt.timestamp = now; - will_return(__wrap_time, 1000 + 1); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = OS_MAXSTR; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 0); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_false(ret); - assert_string_equal(macos_log_cfg.ctxt.buffer, "test"); - assert(macos_log_cfg.ctxt.timestamp == now); - os_free(stream); - -} - -void test_w_macos_log_getlog_discard_until_null(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\0", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = strlen(ctxt.buffer) + 1; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test"); - - will_return(__wrap_isDebug, 0); - - //test_w_macos_log_ctxt_backup_success - - will_return(__wrap_fgetc, 'X'); - will_return(__wrap_fgetc, 'X'); - will_return(__wrap_fgetc, NULL); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Maximum message length reached. The remainder was discarded."); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - //assert_string_equal(buffer, "test"); - assert_true(ret); - - os_free(stream); - -} - -void test_w_macos_log_getlog_discard_until_eof(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "test\0", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = strlen(ctxt.buffer) + 1; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_fgetc, 'X'); - will_return(__wrap_fgetc, 'X'); - will_return(__wrap_fgetc, EOF); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Maximum message length reached. The remainder was discarded."); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - //assert_string_equal(buffer, "test"); - assert_true(ret); - - os_free(stream); - -} - -void test_w_macos_log_getlog_split_two_logs_debug(void ** state) { - - //test_w_macos_ctxt_restore_true - w_macos_log_ctxt_t ctxt; - strncpy(ctxt.buffer, "log 1 first line\nlog 1 second line\n", OS_MAXSTR); - - char buffer[OS_MAXSTR + 1]; - buffer[OS_MAXSTR] = '\0'; - - //test_w_macos_is_log_ctxt_expired_false - ctxt.timestamp = 1000; - ctxt.force_send = false; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - w_macos_log_config_t macos_log_cfg; - macos_log_cfg.ctxt = ctxt; - macos_log_cfg.is_header_processed = true; - - int length = strlen(ctxt.buffer) + 100; - - FILE * stream; - os_calloc(1, sizeof(FILE *), stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "log 2 first line\r\n"); - - //test_w_macos_log_ctxt_backup_success - - //test_w_macos_is_log_header_false - will_return(__wrap_w_expression_match, true); - - //test_w_macos_log_get_last_valid_line - - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mdebug2, formatted_msg, "Reading macOS message: ''..."); - - will_return(__wrap_time, 1001); - - bool ret = w_macos_log_getlog(buffer, length, stream, &macos_log_cfg); - - assert_string_equal(buffer, "log 1 first line\nlog 1 second line"); - assert_string_equal(macos_log_cfg.ctxt.buffer, "log 2 first line\n"); - assert_int_equal(macos_log_cfg.ctxt.timestamp, 1001); - assert_true(ret); - - os_free(stream); -} - -/* w_macos_trim_full_timestamp */ - -void test_w_macos_trim_full_timestamp_null_pointer(void ** state) { - - assert_null(w_macos_trim_full_timestamp(NULL)); -} - -void test_w_macos_trim_full_timestamp_empty_string(void ** state) { - - assert_null(w_macos_trim_full_timestamp("")); -} - -void test_w_macos_trim_full_timestamp_incomplete_timestamp(void ** state) { - - char * INCOMPLETE_TIMESTAMP = "2019-12-14 05:43:58.9"; - - assert_null(w_macos_trim_full_timestamp(INCOMPLETE_TIMESTAMP)); -} - -void test_w_macos_trim_full_timestamp_full_timestamp(void ** state) { - - char * FULL_TIMESTAMP = "2019-12-14 05:43:58.972536-0800"; - char * EXPECTED_TRIMMED_TIMESTAMP = "2019-12-14 05:43:58-0800"; - char * retstr; - - retstr = w_macos_trim_full_timestamp(FULL_TIMESTAMP); - - assert_non_null(retstr); - assert_string_equal(retstr, EXPECTED_TRIMMED_TIMESTAMP); - - os_free(retstr); -} - -/* read_macos */ - -void test_read_macos_can_read_false(void ** state) { - - logreader dummy_lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), dummy_lf.macos_log); - dummy_lf.macos_log->state = LOG_RUNNING_STREAM; - - will_return(__wrap_can_read, 0); - - assert_null(read_macos(&dummy_lf, &dummy_rc, 0)); - - os_free(dummy_lf.macos_log); -} - -void test_read_macos_getlog_false(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = getpid(); - - will_return(__wrap_can_read, 1); - will_return(__wrap_can_read, 0); // forces w_macos_log_getlog to return NULL - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 0); - will_return(__wrap_waitpid, 0); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); -} - -void test_read_macos_empty_log(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = getpid(); - lf.macos_log->is_header_processed = true; - - - will_return(__wrap_can_read, 1); - - // This block forces w_macos_log_getlog to return "true" and an empty buffer - lf.macos_log->ctxt.buffer[0] = '\n'; - lf.macos_log->ctxt.buffer[1] = '\0'; - lf.macos_log->ctxt.timestamp = 1000; - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Discarding empty message."); - will_return(__wrap_can_read, 0); // second loop - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 0); - will_return(__wrap_waitpid, 0); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); -} - -void test_read_macos_incomplete_short_log(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = getpid(); - lf.macos_log->ctxt.buffer[0] = '\0'; - - will_return(__wrap_can_read, 1); - - will_return(__wrap_can_read, 1); - lf.macos_log->ctxt.timestamp = 1000; - will_return(__wrap_time, 999 + MACOS_LOG_TIMEOUT); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "macOS ULS: Incomplete message."); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 0); - will_return(__wrap_waitpid, 0); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); -} - -void test_read_macos_single_full_log_store_timestamp_and_setting(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = getpid(); - lf.macos_log->is_header_processed = true; - lf.macos_log->store_current_settings = false; - lf.macos_log->current_settings = "some log command with predicate and stuff"; - lf.macos_log->ctxt.timestamp = 1000; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - strcpy(lf.macos_log->ctxt.buffer, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_can_read, 1); - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_can_read, 0); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:53-0700"); - expect_string(__wrap_w_macos_set_log_settings, settings, lf.macos_log->current_settings); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 0); - will_return(__wrap_waitpid, 0); - assert_null(read_macos(&lf, &dummy_rc, 0)); - assert_true(lf.macos_log->store_current_settings); - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); -} - -void test_read_macos_more_logs_than_maximum(void ** state) { - - logreader lf; - int dummy_rc; - int TIMESTAMP_TIME = 10; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = getpid(); - lf.macos_log->is_header_processed = true; - lf.macos_log->store_current_settings = true; - lf.macos_log->ctxt.timestamp = TIMESTAMP_TIME; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - maximum_lines = 3; - - will_return(__wrap_can_read, 1); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_time, TIMESTAMP_TIME); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:54.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_w_expression_match, true); - will_return(__wrap_time, TIMESTAMP_TIME); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_time, TIMESTAMP_TIME); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:55.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_w_expression_match, true); - will_return(__wrap_time, TIMESTAMP_TIME); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_time, TIMESTAMP_TIME); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:56.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_w_expression_match, true); - will_return(__wrap_time, TIMESTAMP_TIME); - will_return(__wrap_w_msg_hash_queues_push, 0); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:55-0700"); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - - maximum_lines = TESTING_MAXIMUM_LINES; - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); -} - -void test_read_macos_disable_maximum_lines(void ** state) { - - logreader lf; - int dummy_rc; - int TIMESTAMP_TIME = 10; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = getpid(); - lf.macos_log->is_header_processed = true; - lf.macos_log->store_current_settings = true; - lf.macos_log->ctxt.timestamp = TIMESTAMP_TIME; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - maximum_lines = 0; - - will_return(__wrap_can_read, 1); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_time, TIMESTAMP_TIME); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:54.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_w_expression_match, true); - will_return(__wrap_time, TIMESTAMP_TIME); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_time, TIMESTAMP_TIME); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:55.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_w_expression_match, true); - will_return(__wrap_time, TIMESTAMP_TIME); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_time, TIMESTAMP_TIME); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "2021-05-17 15:31:56.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_isDebug, 0); - - will_return(__wrap_w_expression_match, true); - will_return(__wrap_time, TIMESTAMP_TIME); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_time, TIMESTAMP_TIME + 100); - will_return(__wrap_w_msg_hash_queues_push, 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:56-0700"); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - - maximum_lines = TESTING_MAXIMUM_LINES; - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); -} - -void test_read_macos_toggle_correctly_ended_show_to_stream(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.show.wfd); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - wfd_t * show_ptr = lf.macos_log->processes.show.wfd; - wfd_t * stream_ptr = lf.macos_log->processes.stream.wfd; - lf.macos_log->state = LOG_RUNNING_SHOW; - lf.macos_log->processes.show.wfd->pid = 10; - lf.macos_log->processes.stream.wfd->pid = 11; - macos_processes = &lf.macos_log->processes; - lf.macos_log->store_current_settings = true; - lf.macos_log->is_header_processed = true; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - - // Save an expired context to send it immediately - strcpy(lf.macos_log->ctxt.buffer, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib)\n"); - lf.macos_log->ctxt.timestamp = 1000; - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - will_return(__wrap_can_read, 1); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:53-0700"); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 0); - will_return(__wrap_waitpid, 10); - - expect_string(__wrap__minfo, formatted_msg, "(1607): macOS 'log show' process exited, pid: 10, exit value: 0."); - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, NULL); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - assert_string_equal(lf.macos_log->ctxt.buffer, ""); - assert_true(lf.macos_log->store_current_settings); - assert_int_equal(lf.macos_log->state, LOG_RUNNING_STREAM); - assert_non_null(lf.macos_log->processes.stream.wfd); - assert_false(lf.macos_log->is_header_processed); - - os_free(show_ptr); - os_free(stream_ptr); - os_free(lf.macos_log); -} - -void test_read_macos_toggle_faulty_ended_show_to_stream(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.show.wfd); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - wfd_t * show_ptr = lf.macos_log->processes.show.wfd; - wfd_t * stream_ptr = lf.macos_log->processes.stream.wfd; - lf.macos_log->state = LOG_RUNNING_SHOW; - lf.macos_log->processes.show.wfd->pid = 10; - lf.macos_log->processes.stream.wfd->pid = 11; - macos_processes = &lf.macos_log->processes; - lf.macos_log->store_current_settings = true; - lf.macos_log->is_header_processed = true; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - - // Save an expired context to send it immediately - strcpy(lf.macos_log->ctxt.buffer, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib)\n"); - lf.macos_log->ctxt.timestamp = 1000; - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - will_return(__wrap_can_read, 1); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:53-0700"); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 1); - will_return(__wrap_waitpid, 10); - - expect_string(__wrap__merror, formatted_msg, "(1607): macOS 'log show' process exited, pid: 10, exit value: 1."); - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, NULL); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - assert_string_equal(lf.macos_log->ctxt.buffer, ""); - assert_true(lf.macos_log->store_current_settings); - assert_int_equal(lf.macos_log->state, LOG_RUNNING_STREAM); - assert_non_null(lf.macos_log->processes.stream.wfd); - assert_false(lf.macos_log->is_header_processed); - - os_free(show_ptr); - os_free(stream_ptr); - os_free(lf.macos_log); -} - -void test_read_macos_toggle_correctly_ended_show_to_faulty_stream(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.show.wfd); - wfd_t * show_ptr = lf.macos_log->processes.show.wfd; - lf.macos_log->state = LOG_RUNNING_SHOW; - lf.macos_log->processes.show.wfd->pid = 10; - lf.macos_log->processes.stream.wfd = NULL; - macos_processes = &lf.macos_log->processes; - lf.macos_log->store_current_settings = true; - lf.macos_log->is_header_processed = true; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - - // Save an expired context to send it immediately - strcpy(lf.macos_log->ctxt.buffer, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib)\n"); - lf.macos_log->ctxt.timestamp = 1000; - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - will_return(__wrap_can_read, 1); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:53-0700"); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 0); - will_return(__wrap_waitpid, 10); - - expect_string(__wrap__minfo, formatted_msg, "(1607): macOS 'log show' process exited, pid: 10, exit value: 0."); - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log show` resources."); - - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, NULL); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - assert_string_equal(lf.macos_log->ctxt.buffer, ""); - assert_true(lf.macos_log->store_current_settings); - assert_int_equal(lf.macos_log->state, LOG_NOT_RUNNING); - assert_null(macos_processes->show.wfd); - - os_free(show_ptr); - os_free(lf.macos_log); -} - -void test_read_macos_faulty_ended_stream(void ** state) { - - logreader lf; - int dummy_rc; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - wfd_t * stream_ptr = lf.macos_log->processes.stream.wfd; - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = 10; - macos_processes = &lf.macos_log->processes; - lf.macos_log->store_current_settings = true; - lf.macos_log->is_header_processed = true; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - - // Save an expired context to send it immediately - strcpy(lf.macos_log->ctxt.buffer, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib)\n"); - lf.macos_log->ctxt.timestamp = 1000; - - will_return(__wrap_can_read, 1); - - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:53-0700"); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 1); - will_return(__wrap_waitpid, 10); - - expect_string(__wrap__merror, formatted_msg, "(1607): macOS 'log stream' process exited, pid: 10, exit value: 1."); - expect_string(__wrap__mdebug1, formatted_msg, "macOS ULS: Releasing macOS `log stream` resources."); - - expect_value(__wrap_kill, sig, SIGTERM); - expect_value(__wrap_kill, pid, 10); - will_return(__wrap_kill, 0); - will_return(__wrap_wpclose, NULL); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - assert_string_equal(lf.macos_log->ctxt.buffer, ""); - assert_true(lf.macos_log->store_current_settings); - assert_int_equal(lf.macos_log->state, LOG_NOT_RUNNING); - assert_null(macos_processes->show.wfd); - - - os_free(stream_ptr); - os_free(lf.macos_log); -} - -void test_read_macos_faulty_waitpid(void ** state) { - - logreader lf; - int dummy_rc; - errno = 123; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = 10; - macos_processes = &lf.macos_log->processes; - lf.macos_log->store_current_settings = true; - lf.macos_log->is_header_processed = true; - lf.regex_ignore = NULL; - lf.regex_restrict = NULL; - - // Save an expired context to send it immediately - strcpy(lf.macos_log->ctxt.buffer, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib)\n"); - lf.macos_log->ctxt.timestamp = 1000; - - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - - will_return(__wrap_can_read, 1); - will_return(__wrap_w_msg_hash_queues_push, 0); - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_string(__wrap_w_macos_set_last_log_timestamp, timestamp, "2021-05-17 15:31:53-0700"); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 1); - will_return(__wrap_waitpid, 2); - will_return(__wrap_strerror, "error test"); - - expect_string(__wrap__merror, formatted_msg, "(1111): Error during waitpid()-call due to [(123)-(error test)]."); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - assert_string_equal(lf.macos_log->ctxt.buffer, ""); - assert_true(lf.macos_log->store_current_settings); - assert_null(macos_processes->show.wfd); - - - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); -} - -void test_read_macos_log_ignored(void ** state) { - logreader lf; - int dummy_rc; - char log_str[PATH_MAX + 1] = {0}; - w_expression_t * expression_ignore; - - os_calloc(1, sizeof(w_macos_log_config_t), lf.macos_log); - os_calloc(1, sizeof(wfd_t), lf.macos_log->processes.stream.wfd); - - lf.regex_ignore = OSList_Create(); - OSList_SetFreeDataPointer(lf.regex_ignore, (void (*)(void *))w_free_expression); - - w_calloc_expression_t(&expression_ignore, EXP_TYPE_PCRE2); - w_expression_compile(expression_ignore, "ignore.*", 0); - OSList_InsertData(lf.regex_ignore, NULL, expression_ignore); - - lf.macos_log->state = LOG_RUNNING_STREAM; - lf.macos_log->processes.stream.wfd->pid = getpid(); - lf.macos_log->is_header_processed = true; - lf.macos_log->store_current_settings = false; - lf.macos_log->current_settings = "some log command with predicate and stuff"; - lf.macos_log->ctxt.timestamp = 1000; - lf.regex_restrict = NULL; - strcpy(lf.macos_log->ctxt.buffer, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name\n"); - - will_return(__wrap_can_read, 1); - will_return(__wrap_time, 1000 + MACOS_LOG_TIMEOUT + 1); - will_return(__wrap_w_expression_match, true); - - snprintf(log_str, PATH_MAX, LF_MATCH_REGEX, "2021-05-17 15:31:53.586313-0700 localhost sshd[880]: (libsystem_info.dylib) Created Activity ID: 0x2040, Description: Retrieve User by Name", "ignore", "ignore.*"); - expect_string(__wrap__mdebug2, formatted_msg, log_str); - - will_return(__wrap_can_read, 0); - - expect_any(__wrap_waitpid, __pid); - expect_any(__wrap_waitpid, __options); - will_return(__wrap_waitpid, 0); - will_return(__wrap_waitpid, 0); - - assert_null(read_macos(&lf, &dummy_rc, 0)); - - os_free(lf.macos_log->processes.stream.wfd); - os_free(lf.macos_log); - - if (lf.regex_ignore) { - OSList_Destroy(lf.regex_ignore); - lf.regex_ignore = NULL; - } -} - -int main(void) { - - maximum_lines = TESTING_MAXIMUM_LINES; - const struct CMUnitTest tests[] = { - // Test w_macos_log_ctxt_restore - cmocka_unit_test(test_w_macos_log_ctxt_restore_false), - cmocka_unit_test(test_w_macos_log_ctxt_restore_true), - // Test w_macos_log_ctxt_backup - cmocka_unit_test(test_w_macos_log_ctxt_backup_success), - // Test w_macos_log_ctxt_clean - cmocka_unit_test(test_w_macos_log_ctxt_clean_success), - // Test w_macos_is_log_ctxt_expired - cmocka_unit_test(test_w_macos_is_log_ctxt_expired_true), - cmocka_unit_test(test_w_macos_is_log_ctxt_expired_false), - // Test w_macos_log_get_last_valid_line - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_null), - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_empty), - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_without_new_line), - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_with_new_line_end), - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_with_new_line_not_end), - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_with_two_new_lines_end), - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_with_two_new_lines_not_end), - cmocka_unit_test(test_w_macos_log_get_last_valid_line_str_with_three_new_lines_not_end), - // Test w_macos_is_log_header - cmocka_unit_test(test_w_macos_is_log_header_false), - cmocka_unit_test(test_w_macos_is_log_header_log_stream_execution_error_after_exec), - cmocka_unit_test(test_w_macos_is_log_header_log_stream_execution_error_colon), - cmocka_unit_test(test_w_macos_is_log_header_log_stream_execution_error_line_break), - cmocka_unit_test(test_w_macos_is_log_header_reading_other_log), - cmocka_unit_test(test_w_macos_is_log_header_reading_other_log_line_break), - // Test w_macos_log_getlog - cmocka_unit_test(test_w_macos_log_getlog_context_expired), - cmocka_unit_test(test_w_macos_log_getlog_context_expired_new_line), - cmocka_unit_test(test_w_macos_log_getlog_context_not_expired), - cmocka_unit_test(test_w_macos_log_getlog_context_buffer_full), - cmocka_unit_test(test_w_macos_log_getlog_context_buffer_full_no_endl_force_split), - cmocka_unit_test(test_w_macos_log_getlog_context_not_endline), - cmocka_unit_test(test_w_macos_log_getlog_context_full_buffer), - cmocka_unit_test(test_w_macos_log_getlog_discards_irrelevant_headers), - cmocka_unit_test(test_w_macos_log_getlog_discards_irrelevant_headers_sierra_child_processes_already_set), - cmocka_unit_test(test_w_macos_log_getlog_discards_irrelevant_headers_sierra_stream_and_show_without_child_pid), - cmocka_unit_test(test_w_macos_log_getlog_split_two_logs), - cmocka_unit_test(test_w_macos_log_getlog_backup_context), - cmocka_unit_test(test_w_macos_log_getlog_backup_context_sierra), - cmocka_unit_test(test_w_macos_log_getlog_backup_context_sierra_multiline), - cmocka_unit_test(test_w_macos_log_getlog_backup_context_sierra_new_line), - cmocka_unit_test(test_w_macos_log_getlog_cannot_read), - cmocka_unit_test(test_w_macos_log_getlog_discard_until_eof), - cmocka_unit_test(test_w_macos_log_getlog_discard_until_null), - cmocka_unit_test(test_w_macos_log_getlog_split_two_logs_debug), - // Test w_macos_trim_full_timestamp - cmocka_unit_test(test_w_macos_trim_full_timestamp_null_pointer), - cmocka_unit_test(test_w_macos_trim_full_timestamp_empty_string), - cmocka_unit_test(test_w_macos_trim_full_timestamp_incomplete_timestamp), - cmocka_unit_test(test_w_macos_trim_full_timestamp_full_timestamp), - // Test w_read_macos - cmocka_unit_test(test_read_macos_can_read_false), - cmocka_unit_test(test_read_macos_getlog_false), - cmocka_unit_test(test_read_macos_empty_log), - cmocka_unit_test(test_read_macos_incomplete_short_log), - cmocka_unit_test(test_read_macos_single_full_log_store_timestamp_and_setting), - cmocka_unit_test(test_read_macos_more_logs_than_maximum), - cmocka_unit_test(test_read_macos_disable_maximum_lines), - cmocka_unit_test(test_read_macos_toggle_correctly_ended_show_to_stream), - cmocka_unit_test(test_read_macos_toggle_faulty_ended_show_to_stream), - cmocka_unit_test(test_read_macos_toggle_correctly_ended_show_to_faulty_stream), - cmocka_unit_test(test_read_macos_faulty_ended_stream), - cmocka_unit_test(test_read_macos_faulty_waitpid), - cmocka_unit_test(test_read_macos_log_ignored), - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/logcollector/test_read_multiline.c b/src/unit_tests/logcollector/test_read_multiline.c deleted file mode 100644 index c2ab1c86c4e..00000000000 --- a/src/unit_tests/logcollector/test_read_multiline.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../logcollector/logcollector.h" -#include "../../headers/shared.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" - -/* Setup & Teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -/* Wraps */ -int __wrap_can_read() { - return mock_type(int); -} - -bool __wrap_w_get_hash_context(const char * path, EVP_MD_CTX * context, int64_t position) { - return mock_type(bool); -} - -int __wrap_w_update_file_status(const char * path, int64_t pos, EVP_MD_CTX * context) { - bool free_context = mock_type(bool); - if (free_context) { - EVP_MD_CTX_free(context); - } - return mock_type(int); -} - -void __wrap_OS_SHA1_Stream(EVP_MD_CTX *c, os_sha1 output, char * buf) { - function_called(); - return; -} - -/* Tests */ - -void test_buffer_space(void ** state) { - logreader lf = { .file = "test", .linecount = 3 }; - int rc; - char * input_str = malloc(OS_MAX_LOG_SIZE); - memset(input_str, '.', OS_MAX_LOG_SIZE - 1); - input_str[OS_MAX_LOG_SIZE - 1] = '\0'; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - - will_return(__wrap_w_get_hash_context, true); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, input_str); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) OS_MAX_LOG_SIZE - 1); - - expect_function_call(__wrap_OS_SHA1_Stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "\n"); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) OS_MAX_LOG_SIZE); - - expect_function_call(__wrap_OS_SHA1_Stream); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, input_str); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) (OS_MAX_LOG_SIZE) * 2 - 1); - - expect_function_call(__wrap_OS_SHA1_Stream); - - expect_any(__wrap__merror, formatted_msg); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) (OS_MAX_LOG_SIZE) * 2 - 1); - - will_return(__wrap_can_read, 0); - - will_return(__wrap_w_update_file_status, true); - will_return(__wrap_w_update_file_status, 0); - - read_multiline(&lf, &rc, 1); - - free(input_str); -} - -void test_buffer_space_invalid_context(void ** state) { - logreader lf = { .file = "test", .linecount = 3 }; - int rc; - char * input_str = malloc(OS_MAX_LOG_SIZE); - memset(input_str, '.', OS_MAX_LOG_SIZE - 1); - input_str[OS_MAX_LOG_SIZE - 1] = '\0'; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - - will_return(__wrap_w_get_hash_context, false); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, input_str); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) OS_MAX_LOG_SIZE - 1); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "\n"); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) OS_MAX_LOG_SIZE); - - will_return(__wrap_can_read, 1); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, input_str); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) (OS_MAX_LOG_SIZE) * 2 - 1); - - expect_any(__wrap__merror, formatted_msg); - - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) (OS_MAX_LOG_SIZE) * 2 - 1); - - will_return(__wrap_can_read, 0); - - read_multiline(&lf, &rc, 1); - - free(input_str); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_buffer_space), - cmocka_unit_test(test_buffer_space_invalid_context), - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/logcollector/test_read_multiline_regex.c b/src/unit_tests/logcollector/test_read_multiline_regex.c deleted file mode 100644 index eb700dd30cb..00000000000 --- a/src/unit_tests/logcollector/test_read_multiline_regex.c +++ /dev/null @@ -1,1902 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../logcollector/logcollector.h" -#include "../../headers/shared.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" - -void multiline_replace(char * buffer, w_multiline_replace_type_t type); -bool multiline_ctxt_is_expired(time_t timeout, w_multiline_ctxt_t * ctxt); -bool multiline_ctxt_restore(char * buffer, int * readed_lines, w_multiline_ctxt_t * ctxt); -void multiline_ctxt_free(w_multiline_ctxt_t ** ctxt); -void multiline_ctxt_backup(char * buffer, int readed_lines, w_multiline_ctxt_t ** ctxt); - -int multiline_getlog_start(char * buffer, int length, FILE * stream, w_multiline_config_t * ml_cfg); -int multiline_getlog_end(char * buffer, int length, FILE * stream, w_multiline_config_t * ml_cfg); -int multiline_getlog_all(char * buffer, int length, FILE * stream, w_multiline_config_t * ml_cfg); -int multiline_getlog(char * buffer, int length, FILE * stream, w_multiline_config_t * ml_cfg); -void * read_multiline_regex(logreader * lf, int * rc, int drop_it); -char * get_file_chunk(FILE * stream, int64_t initial_pos, int64_t final_pos); - -/* setup/teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -/* wraps */ -int __wrap_can_read() { - return mock_type(int); -} - -bool __wrap_w_expression_match(w_expression_t * expression, const char * str_test, const char ** end_match, - regex_matching * regex_match) { - return mock_type(bool); -} - -int __wrap_w_msg_hash_queues_push(const char * str, char * file, unsigned long size, logtarget * targets, - char queue_mq) { - return mock_type(int); -} - -bool __wrap_w_get_hash_context(const char * path, EVP_MD_CTX * context, int64_t position) { - return mock_type(bool); -} - -int __wrap_w_update_file_status(const char * path, int64_t pos, EVP_MD_CTX * context) { - bool free_context = mock_type(bool); - if (free_context) { - EVP_MD_CTX_free(context); - } - return mock_type(int); -} - -void __wrap_OS_SHA1_Stream(EVP_MD_CTX *c, os_sha1 output, char * buf) { - function_called(); - return; -} - -/* tests */ - -/* multiline_replace linux */ -void test_multiline_replace_ws_not_found(void ** state) { - - char str[] = "test replace white space"; - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - const char str_expected[] = "test replace white space"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_ws_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - multiline_replace(NULL, type); -} - -void test_multiline_replace_ws_char_empty_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - char str[] = ""; - multiline_replace(str, type); -} - -void test_multiline_replace_ws_char_noreplace(void ** state) { - - char str[] = "test replace\nwhite space"; - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - const char str_expected[] = "test replace\nwhite space"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_ws_char_replace_last(void ** state) { - - char str[] = "test replace\ntab\n"; - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - const char str_expected[] = "test replace\ntab "; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_tab_not_found(void ** state) { - - char str[] = "test replace tab"; - w_multiline_replace_type_t type = ML_REPLACE_TAB; - const char str_expected[] = "test replace tab"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_tab_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_TAB; - multiline_replace(NULL, type); -} - -void test_multiline_replace_tab_char_empty_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_TAB; - char str[] = ""; - multiline_replace(str, type); -} - -void test_multiline_replace_tab_char_noreplace(void ** state) { - - char str[] = "test replace\ntab"; - w_multiline_replace_type_t type = ML_REPLACE_TAB; - const char str_expected[] = "test replace\ntab"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_tab_char_replace_last(void ** state) { - - char str[] = "test replace\ntab\n"; - w_multiline_replace_type_t type = ML_REPLACE_TAB; - const char str_expected[] = "test replace\ntab\t"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_none_not_found(void ** state) { - - char str[] = "test replace none"; - w_multiline_replace_type_t type = ML_REPLACE_NONE; - const char str_expected[] = "test replace none"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_none_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_NONE; - multiline_replace(NULL, type); -} - -void test_multiline_replace_none_char_empty_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_NONE; - char str[] = ""; - multiline_replace(str, type); -} - -void test_multiline_replace_none_char_noreplace(void ** state) { - - char str[] = "test replace\nnone"; - w_multiline_replace_type_t type = ML_REPLACE_NONE; - const char str_expected[] = "test replace\nnone"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_none_char_replace_last(void ** state) { - - char str[] = "test replace\nnone\n"; - w_multiline_replace_type_t type = ML_REPLACE_NONE; - const char str_expected[] = "test replace\nnone"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_noreplace_not_found(void ** state) { - - char str[] = "test replace no replace"; - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - const char str_expected[] = "test replace no replace"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_noreplace_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - multiline_replace(NULL, type); -} - -void test_multiline_replace_noreplace_char_replace(void ** state) { - - char str[] = "test replace\nno replace"; - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - const char str_expected[] = "test replace\nno replace"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_noreplace_char_replace_last(void ** state) { - - char str[] = "test replace\nno replace\n"; - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - const char str_expected[] = "test replace\nno replace\n"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -/* multiline_replace windows */ -void test_multiline_replace_w_ws_not_found(void ** state) { - - char str[] = "test replace white space"; - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - const char str_expected[] = "test replace white space"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_ws_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - multiline_replace(NULL, type); -} - -void test_multiline_replace_w_ws_char_noreplace(void ** state) { - - char str[] = "test replace\r\nwhite space"; - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - const char str_expected[] = "test replace\r\nwhite space"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_ws_char_replace_last(void ** state) { - - char str[] = "test replace\r\ntab\r\n"; - w_multiline_replace_type_t type = ML_REPLACE_WSPACE; - const char str_expected[] = "test replace\r\ntab "; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_tab_not_found(void ** state) { - - char str[] = "test replace tab"; - w_multiline_replace_type_t type = ML_REPLACE_TAB; - const char str_expected[] = "test replace tab"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_tab_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_TAB; - multiline_replace(NULL, type); -} - -void test_multiline_replace_w_tab_char_noreplace(void ** state) { - - char str[] = "test replace\r\ntab"; - w_multiline_replace_type_t type = ML_REPLACE_TAB; - const char str_expected[] = "test replace\r\ntab"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_tab_char_replace_last(void ** state) { - - char str[] = "test replace\r\ntab\r\n"; - w_multiline_replace_type_t type = ML_REPLACE_TAB; - const char str_expected[] = "test replace\r\ntab\t"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_none_not_found(void ** state) { - - char str[] = "test replace none"; - w_multiline_replace_type_t type = ML_REPLACE_NONE; - const char str_expected[] = "test replace none"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_none_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_NONE; - multiline_replace(NULL, type); -} - -void test_multiline_replace_w_none_char_noreplace(void ** state) { - - char str[] = "test replace\r\nnone"; - w_multiline_replace_type_t type = ML_REPLACE_NONE; - const char str_expected[] = "test replace\r\nnone"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_none_char_replace_last(void ** state) { - - char str[] = "test replace\r\nnone\r\n"; - w_multiline_replace_type_t type = ML_REPLACE_NONE; - const char str_expected[] = "test replace\r\nnone"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_noreplace_not_found(void ** state) { - - char str[] = "test replace no replace"; - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - const char str_expected[] = "test replace no replace"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_noreplace_char_null_str(void ** state) { - - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - multiline_replace(NULL, type); -} - -void test_multiline_replace_w_noreplace_char_noreplace(void ** state) { - - char str[] = "test replace\r\nno replace"; - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - const char str_expected[] = "test replace\r\nno replace"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} - -void test_multiline_replace_w_noreplace_char_replace_last(void ** state) { - - char str[] = "test replace\r\nno replace\r\n"; - w_multiline_replace_type_t type = ML_REPLACE_NO_REPLACE; - const char str_expected[] = "test replace\r\nno replace\r\n"; - - multiline_replace(str, type); - assert_string_equal(str, str_expected); -} -// Test multiline_ctxt_is_expired -void test_multiline_ctxt_is_expired_not_found(void ** state) { assert_true(multiline_ctxt_is_expired(1, NULL)); } - -void test_multiline_ctxt_is_expired_not_expired(void ** state) { - - w_multiline_ctxt_t ctxt = {.timestamp = 50}; - unsigned int timeout = 75; - - will_return(__wrap_time, (unsigned int) 100); - - assert_false(multiline_ctxt_is_expired(timeout, &ctxt)); -} - -void test_multiline_ctxt_is_expired_expired(void ** state) { - w_multiline_ctxt_t ctxt = {.timestamp = 50}; - unsigned int timeout = 10; - - will_return(__wrap_time, (unsigned int) 100); - - assert_true(multiline_ctxt_is_expired(timeout, &ctxt)); -} - -/* multiline_ctxt_restore */ -void test_multiline_ctxt_restore_restore(void ** state) { - - // orginal content - w_multiline_ctxt_t ctxt = { - .buffer = "Test buffer", - .lines_count = 100, - .timestamp = 0, - }; - // restore - int readed_lines = -1; - char * buffer; - os_calloc(strlen(ctxt.buffer) + 1, sizeof(char), buffer); - - assert_true(multiline_ctxt_restore(buffer, &readed_lines, &ctxt)); - assert_int_equal(readed_lines, ctxt.lines_count); - assert_string_equal(buffer, ctxt.buffer); - - os_free(buffer); -} - -void test_multiline_ctxt_restore_null(void ** state) { - - // restore - int readed_lines = -1; - char * buffer = NULL; - - assert_false(multiline_ctxt_restore(buffer, &readed_lines, NULL)); - assert_int_equal(readed_lines, -1); - assert_null(buffer); -} - -/* multiline_ctxt_free */ -void test_multiline_ctxt_free_null(void ** state) { - - w_multiline_ctxt_t * ctxt = NULL; - multiline_ctxt_free(&ctxt); -} - -void test_multiline_ctxt_free_free(void ** state) { - - w_multiline_ctxt_t * ctxt; - os_calloc(1, sizeof(w_multiline_ctxt_t), ctxt); - os_calloc(1, sizeof(char), ctxt->buffer); - multiline_ctxt_free(&ctxt); - assert_null(ctxt); -} - -/* multiline_ctxt_backup */ -void test_multiline_ctxt_backup_no_restore(void ** state) { - - char buffer[] = "hi!, no new content"; - int readed_lines = 6; - w_multiline_ctxt_t * ctxt; - os_calloc(1, sizeof(w_multiline_ctxt_t), ctxt); - w_strdup(buffer, ctxt->buffer); - ctxt->lines_count = readed_lines; - ctxt->timestamp = (time_t) 5; - - multiline_ctxt_backup(buffer, readed_lines, &ctxt); - - assert_int_equal(ctxt->timestamp, 5); - assert_int_equal(readed_lines, 6); - assert_string_equal(buffer, ctxt->buffer); - - multiline_ctxt_free(&ctxt); -} - -void test_multiline_ctxt_backup_new_ctxt(void ** state) { - - char buffer[] = "hi!, new content"; - int readed_lines = 6; - w_multiline_ctxt_t * ctxt = NULL; - - will_return(__wrap_time, 10); - multiline_ctxt_backup(buffer, readed_lines, &ctxt); - - assert_int_equal(ctxt->timestamp, 10); - assert_int_equal(readed_lines, 6); - assert_string_equal(buffer, ctxt->buffer); - - multiline_ctxt_free(&ctxt); -} - -void test_multiline_ctxt_backup_increment(void ** state) { - - char buffer[] = "old content + New content"; - int readed_lines = 6; - w_multiline_ctxt_t * ctxt; - os_calloc(1, sizeof(w_multiline_ctxt_t), ctxt); - w_strdup("old content + ", ctxt->buffer); - ctxt->lines_count = 5; - ctxt->timestamp = (time_t) 5; - - will_return(__wrap_time, 10); - multiline_ctxt_backup(buffer, readed_lines, &ctxt); - - assert_int_equal(ctxt->timestamp, 10); - assert_int_equal(readed_lines, 6); - assert_string_equal(buffer, ctxt->buffer); - - multiline_ctxt_free(&ctxt); -} - -/* multiline_getlog_start */ -void test_multiline_getlog_start_single_no_context(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_START; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - will_return(__wrap_time, 1); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 0); - assert_string_equal(ml_confg.ctxt->buffer, "no match\n"); - assert_int_equal(ml_confg.ctxt->lines_count, 1); - assert_int_equal(ml_confg.ctxt->timestamp, 1); - multiline_ctxt_free(&ml_confg.ctxt); -} - -void test_multiline_getlog_start_ctxt_timeout(void ** state) { - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1] = {0}; - - w_multiline_config_t ml_confg = {0}; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_START; - os_strdup("no match\n", ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 1; - ml_confg.ctxt->timestamp = 0; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - will_return(__wrap_time, timeout + 1); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match"); -} - -void test_multiline_getlog_start_ctxt_append_ctxt(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1] = {0}; - const char * msg = "no match\nno match2\n"; - w_multiline_config_t ml_confg = {0}; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_time, timeout - 1); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match3\n"); - will_return(__wrap_w_expression_match, false); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - will_return(__wrap_time, timeout); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 0); - assert_non_null(ml_confg.ctxt); - assert_string_equal(ml_confg.ctxt->buffer, "no match\nno match2\nno match3\n"); - assert_int_equal(ml_confg.ctxt->lines_count, 3); - assert_int_equal(ml_confg.ctxt->timestamp, timeout); - multiline_ctxt_free(&ml_confg.ctxt); -} - -void test_multiline_getlog_start_ctxt_match(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1] = {0}; - const char * msg = "no match\nno match2\n"; - w_multiline_config_t ml_confg = {0}; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_time, timeout - 1); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "match"); - will_return(__wrap_w_expression_match, true); - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, 0); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 2); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match\nno match2"); -} - -void test_multiline_getlog_start_no_ctxt_match(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_START; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match2\n"); - will_return(__wrap_w_expression_match, false); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "match"); - will_return(__wrap_w_expression_match, true); - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, 0); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 2); - assert_string_equal(buffer, "no match\nno match2"); - assert_null(ml_confg.ctxt); -} - -void test_multiline_getlog_start_no_ctxt_overflow(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_START; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "01234567890123456789------"); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '\0'); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "0123456789012345678"); -} - -void test_multiline_getlog_start_ctxt_overflow(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - const char * msg = "123456789\n"; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_START; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_time, 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "0123456789------"); - - will_return(__wrap_w_expression_match, false); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '\0'); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "123456789\n012345678"); -} - -void test_multiline_getlog_start_no_ctxt_cant_read(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_START; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_can_read, 0); - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 0); - assert_null(ml_confg.ctxt); -} - -void test_multiline_getlog_start_ctxt_cant_read(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - const char * msg = "123456789\n"; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_START; - ml_confg.ctxt->lines_count = 1; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_time, 0); - - will_return(__wrap_can_read, 0); - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 0); - assert_non_null(ml_confg.ctxt); - assert_string_equal(ml_confg.ctxt->buffer, "123456789\n"); - assert_int_equal(ml_confg.ctxt->lines_count, 1); - multiline_ctxt_free(&ml_confg.ctxt); -} - -void test_multiline_getlog_start_match_multi_replace(void ** state) { - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NONE; - ml_confg.match_type = ML_MATCH_START; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match-\n"); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, ">no match2\n"); - - will_return(__wrap_w_expression_match, false); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "next header"); - will_return(__wrap_w_expression_match, true); - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, 0); - - retval = multiline_getlog_start(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 2); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match->no match2"); -} - -/* multiline_getlog_end_single */ -void test_multiline_getlog_end_single_match_no_context(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "end match"); -} - -void test_multiline_getlog_end_ctxt_timeout(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1] = {0}; - - w_multiline_config_t ml_confg = {0}; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - os_strdup("no match\n", ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 1; - ml_confg.ctxt->timestamp = 0; - - will_return(__wrap_time, timeout + 1); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match"); -} - -void test_multiline_getlog_end_ctxt_append_ctxt(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1] = {0}; - const char * msg = "no match\nno match2\n"; - w_multiline_config_t ml_confg = {0}; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - - will_return(__wrap_time, timeout - 1); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match3\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - will_return(__wrap_time, timeout); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 0); - assert_non_null(ml_confg.ctxt); - assert_string_equal(ml_confg.ctxt->buffer, "no match\nno match2\nno match3\n"); - assert_int_equal(ml_confg.ctxt->lines_count, 3); - assert_int_equal(ml_confg.ctxt->timestamp, timeout); - multiline_ctxt_free(&ml_confg.ctxt); -} - -void test_multiline_getlog_end_multi_match_no_context(void ** state) { - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup("initial\n ctx\n", ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_time, timeout - 1); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 4); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "initial\n ctx\nno match\nend match"); -} - -void test_multiline_getlog_end_multi_match_context(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 2); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match\nend match"); -} - -void test_multiline_getlog_end_no_ctxt_overflow(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "01234567890123456789------"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '\0'); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "0123456789012345678"); -} - -void test_multiline_getlog_end_ctxt_overflow(void ** state) { - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - const char * msg = "123456789\n"; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_time, 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "0123456789------"); - - will_return(__wrap_w_expression_match, false); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '\0'); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "123456789\n012345678"); -} - -void test_multiline_getlog_end_no_ctxt_cant_read(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_can_read, 0); - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 0); - assert_null(ml_confg.ctxt); -} - -void test_multiline_getlog_end_ctxt_cant_read(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - const char * msg = "123456789\n"; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - ml_confg.ctxt->lines_count = 1; - - will_return(__wrap_time, 0); - - will_return(__wrap_can_read, 0); - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 0); - assert_non_null(ml_confg.ctxt); - assert_string_equal(ml_confg.ctxt->buffer, "123456789\n"); - assert_int_equal(ml_confg.ctxt->lines_count, 1); - multiline_ctxt_free(&ml_confg.ctxt); -} - -void test_multiline_getlog_end_match_multi_replace(void ** state) { - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup("initial ctx", ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NONE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_time, timeout - 1); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_end(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 4); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "initial ctxno matchend match"); -} - -// Test multiline_getlog_all -void test_multiline_getlog_all_single_match_no_context(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "all match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "all match"); -} - -void test_multiline_getlog_all_ctxt_timeout(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1] = {0}; - - w_multiline_config_t ml_confg = {0}; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - os_strdup("no match\n", ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 1; - ml_confg.ctxt->timestamp = 0; - - will_return(__wrap_time, timeout + 1); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match"); -} - -void test_multiline_getlog_all_ctxt_append_ctxt(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500 + 1] = {0}; - const char * msg = "no match\nno match2\n"; - w_multiline_config_t ml_confg = {0}; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - - will_return(__wrap_time, timeout - 1); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match3\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - will_return(__wrap_time, timeout); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 0); - assert_non_null(ml_confg.ctxt); - assert_string_equal(ml_confg.ctxt->buffer, "no match\nno match2\nno match3\n"); - assert_int_equal(ml_confg.ctxt->lines_count, 3); - assert_int_equal(ml_confg.ctxt->timestamp, timeout); - multiline_ctxt_free(&ml_confg.ctxt); -} - -void test_multiline_getlog_all_multi_match_no_context(void ** state) { - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup("initial\n ctx\n", ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_time, timeout - 1); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 4); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "initial\n ctx\nno match\nend match"); -} - -void test_multiline_getlog_all_multi_match_context(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 2); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match\nend match"); -} - -void test_multiline_getlog_all_no_ctxt_overflow(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "01234567890123456789------"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '\0'); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "0123456789012345678"); -} - -void test_multiline_getlog_all_ctxt_overflow(void ** state) { - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - const char * msg = "123456789\n"; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_time, 0); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "0123456789------"); - - will_return(__wrap_w_expression_match, false); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '-'); - will_return(__wrap_fgetc, '\0'); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "123456789\n012345678"); -} - -void test_multiline_getlog_all_no_ctxt_cant_read(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_can_read, 0); - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 0); - assert_null(ml_confg.ctxt); -} - -void test_multiline_getlog_all_ctxt_cant_read(void ** state) { - - int retval; - const size_t buffer_size = 20; - const time_t timeout = (time_t) 100; - char buffer[20]; - w_multiline_config_t ml_confg = {0}; - - const char * msg = "123456789\n"; - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - ml_confg.ctxt->lines_count = 1; - - will_return(__wrap_time, 0); - - will_return(__wrap_can_read, 0); - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - assert_int_equal(retval, 0); - assert_non_null(ml_confg.ctxt); - assert_string_equal(ml_confg.ctxt->buffer, "123456789\n"); - assert_int_equal(ml_confg.ctxt->lines_count, 1); - multiline_ctxt_free(&ml_confg.ctxt); -} - -void test_multiline_getlog_all_match_multi_replace(void ** state) { - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup("initial ctx", ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NONE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_time, timeout - 1); - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "no match\n"); - will_return(__wrap_w_expression_match, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog_all(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 4); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "initial ctxno matchend match"); -} - -/* multiline_getlog */ -void test_multiline_getlog_unknown(void ** state) { - - char buffer[] = "1234567890"; - int length = 100; - int retval; - w_multiline_config_t ml_cfg = {0}; - ml_cfg.match_type = ML_MATCH_MAX; - - retval = multiline_getlog(buffer, length, 0, &ml_cfg); - - assert_int_equal(retval, 0); - assert_int_equal(strlen(buffer), 0); -} - -void test_multiline_getlog_start(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500] = {0}; - const char * msg = "no match\nno match2\n"; - w_multiline_config_t ml_confg = {0}; - - os_calloc(1, sizeof(w_multiline_config_t), ml_confg.ctxt); - os_strdup(msg, ml_confg.ctxt->buffer); - ml_confg.ctxt->lines_count = 2; - ml_confg.ctxt->timestamp = 0; - ml_confg.timeout = timeout; - ml_confg.match_type = ML_MATCH_START; - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, 0); - will_return(__wrap_time, timeout - 1); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "match"); - will_return(__wrap_w_expression_match, true); - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 0); - will_return(__wrap_w_fseek, 0); - - retval = multiline_getlog(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 2); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "no match\nno match2"); -} - -void test_multiline_getlog_end(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "end match"); -} - -void test_multiline_getlog_all(void ** state) { - - int retval; - const size_t buffer_size = 500; - const time_t timeout = (time_t) 100; - char buffer[500]; - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = timeout; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_ALL; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - - retval = multiline_getlog(buffer, buffer_size, 0, &ml_confg); - - assert_int_equal(retval, 1); - assert_null(ml_confg.ctxt); - assert_string_equal(buffer, "end match"); -} - -/* read_multiline_regex */ -void test_read_multiline_regex_log_process(void ** state) { - - logreader lf = {0}; - int rc = 0; - int drop_it = 0; - - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = 500; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - lf.multiline = &ml_confg; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 5); - will_return(__wrap_w_get_hash_context, true); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - will_return(__wrap_w_msg_hash_queues_push, 0); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 10); - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 5); - will_return(__wrap_w_fseek, 0); - - will_return(__wrap_fread, "test0"); - will_return(__wrap_fread, 5); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_function_call(__wrap_OS_SHA1_Stream); - will_return(__wrap_w_update_file_status, true); - will_return(__wrap_w_update_file_status, 0); - - void * retval = read_multiline_regex(&lf, &rc, drop_it); - assert_ptr_equal(retval, NULL); - assert_null(ml_confg.ctxt); -} - -void test_read_multiline_regex_no_aviable_log(void ** state) { - logreader lf = {0}; - int rc = 0; - int drop_it = 0; - - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = 500; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - lf.multiline = &ml_confg; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 5); - will_return(__wrap_w_get_hash_context, true); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - will_return(__wrap_w_update_file_status, true); - will_return(__wrap_w_update_file_status, 0); - - void * retval = read_multiline_regex(&lf, &rc, drop_it); - assert_ptr_equal(retval, NULL); - assert_null(ml_confg.ctxt); -} - -void test_read_multiline_regex_cant_read(void ** state) { - logreader lf = {0}; - int rc = 0; - int drop_it = 0; - - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = 500; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - lf.multiline = &ml_confg; - - will_return(__wrap_can_read, 0); - void * retval = read_multiline_regex(&lf, &rc, drop_it); - assert_ptr_equal(retval, NULL); - assert_null(ml_confg.ctxt); -} - -void test_read_multiline_regex_invalid_context(void ** state) { - - logreader lf = {0}; - int rc = 0; - int drop_it = 0; - - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = 500; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - lf.multiline = &ml_confg; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 5); - will_return(__wrap_w_get_hash_context, false); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "end match\n"); - will_return(__wrap_w_expression_match, true); - will_return(__wrap_w_msg_hash_queues_push, 0); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 10); - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 5); - will_return(__wrap_w_fseek, 0); - - will_return(__wrap_fread, "test0"); - will_return(__wrap_fread, 5); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - void * retval = read_multiline_regex(&lf, &rc, drop_it); - assert_ptr_equal(retval, NULL); - assert_null(ml_confg.ctxt); -} - -void test_read_multiline_regex_log_ignored(void ** state) { - - logreader lf = {0}; - int rc = 0; - int drop_it = 0; - char log_str[PATH_MAX + 1] = {0}; - w_expression_t * expression_ignore; - - lf.regex_ignore = OSList_Create(); - OSList_SetFreeDataPointer(lf.regex_ignore, (void (*)(void *))w_free_expression); - - w_calloc_expression_t(&expression_ignore, EXP_TYPE_PCRE2); - w_expression_compile(expression_ignore, "ignore.*", 0); - OSList_InsertData(lf.regex_ignore, NULL, expression_ignore); - - w_multiline_config_t ml_confg = {0}; - - ml_confg.timeout = 500; - ml_confg.replace_type = ML_REPLACE_NO_REPLACE; - ml_confg.match_type = ML_MATCH_END; - - lf.multiline = &ml_confg; - - will_return(__wrap_can_read, 1); - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 5); - will_return(__wrap_w_get_hash_context, true); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, "ignore this log\n"); - will_return(__wrap_w_expression_match, true); - - will_return(__wrap_w_expression_match, true); - - snprintf(log_str, PATH_MAX, LF_MATCH_REGEX, "ignore this log", "ignore", "ignore.*"); - expect_string(__wrap__mdebug2, formatted_msg, log_str); - - expect_any(__wrap_w_ftell, x); - will_return(__wrap_w_ftell, (int64_t) 10); - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 5); - will_return(__wrap_w_fseek, 0); - - will_return(__wrap_fread, "test0"); - will_return(__wrap_fread, 5); - - will_return(__wrap_can_read, 1); - expect_any(__wrap_fgets, __stream); - will_return(__wrap_fgets, NULL); - - expect_function_call(__wrap_OS_SHA1_Stream); - will_return(__wrap_w_update_file_status, true); - will_return(__wrap_w_update_file_status, 0); - - void * retval = read_multiline_regex(&lf, &rc, drop_it); - - assert_ptr_equal(retval, NULL); - assert_null(ml_confg.ctxt); - - if (lf.regex_ignore) { - OSList_Destroy(lf.regex_ignore); - lf.regex_ignore = NULL; - } -} - -// Test get_file_chunk -void test_get_file_chunk_fseek_fail(void ** state) { - - char * retval; - int64_t initial_pos = 10; - int64_t final_pos = 5; - - retval = get_file_chunk(NULL, initial_pos, final_pos); - assert_null(retval); -} - -void test_get_file_chunk_size_reduce(void ** state) { - - char * retval; - int64_t initial_pos = 5; - int64_t final_pos = 10; - - will_return(__wrap_fread, "test"); - will_return(__wrap_fread, 4); - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 5); - will_return(__wrap_w_fseek, 0); - - retval = get_file_chunk(NULL, initial_pos, final_pos); - assert_null(retval); -} - -void test_get_file_chunk_ok(void ** state) { - - char * retval; - int64_t initial_pos = 5; - int64_t final_pos = 10; - - expect_any(__wrap_w_fseek, x); - expect_value(__wrap_w_fseek, pos, 5); - will_return(__wrap_w_fseek, 0); - will_return(__wrap_fread, "test"); - will_return(__wrap_fread, 5); - - retval = get_file_chunk(NULL, initial_pos, final_pos); - assert_string_equal("test", retval); - os_free(retval); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test replace_char - cmocka_unit_test(test_multiline_replace_ws_not_found), - cmocka_unit_test(test_multiline_replace_ws_char_null_str), - cmocka_unit_test(test_multiline_replace_ws_char_empty_str), - cmocka_unit_test(test_multiline_replace_ws_char_noreplace), - cmocka_unit_test(test_multiline_replace_ws_char_replace_last), - cmocka_unit_test(test_multiline_replace_tab_not_found), - cmocka_unit_test(test_multiline_replace_tab_char_null_str), - cmocka_unit_test(test_multiline_replace_tab_char_empty_str), - cmocka_unit_test(test_multiline_replace_tab_char_noreplace), - cmocka_unit_test(test_multiline_replace_tab_char_replace_last), - cmocka_unit_test(test_multiline_replace_none_not_found), - cmocka_unit_test(test_multiline_replace_none_char_null_str), - cmocka_unit_test(test_multiline_replace_none_char_empty_str), - cmocka_unit_test(test_multiline_replace_none_char_noreplace), - cmocka_unit_test(test_multiline_replace_none_char_replace_last), - cmocka_unit_test(test_multiline_replace_noreplace_not_found), - cmocka_unit_test(test_multiline_replace_noreplace_char_null_str), - cmocka_unit_test(test_multiline_replace_noreplace_char_replace), - cmocka_unit_test(test_multiline_replace_noreplace_char_replace_last), - cmocka_unit_test(test_multiline_replace_w_ws_not_found), - cmocka_unit_test(test_multiline_replace_w_ws_char_null_str), - cmocka_unit_test(test_multiline_replace_w_ws_char_noreplace), - cmocka_unit_test(test_multiline_replace_w_ws_char_replace_last), - cmocka_unit_test(test_multiline_replace_w_tab_not_found), - cmocka_unit_test(test_multiline_replace_w_tab_char_null_str), - cmocka_unit_test(test_multiline_replace_w_tab_char_noreplace), - cmocka_unit_test(test_multiline_replace_w_tab_char_replace_last), - cmocka_unit_test(test_multiline_replace_w_none_not_found), - cmocka_unit_test(test_multiline_replace_w_none_char_null_str), - cmocka_unit_test(test_multiline_replace_w_none_char_noreplace), - cmocka_unit_test(test_multiline_replace_w_none_char_replace_last), - cmocka_unit_test(test_multiline_replace_w_noreplace_not_found), - cmocka_unit_test(test_multiline_replace_w_noreplace_char_null_str), - cmocka_unit_test(test_multiline_replace_w_noreplace_char_noreplace), - cmocka_unit_test(test_multiline_replace_w_noreplace_char_replace_last), - // Test multiline_ctxt_is_expired - cmocka_unit_test(test_multiline_ctxt_is_expired_not_found), - cmocka_unit_test(test_multiline_ctxt_is_expired_not_expired), - cmocka_unit_test(test_multiline_ctxt_is_expired_expired), - // Test multiline_ctxt_restore - cmocka_unit_test(test_multiline_ctxt_restore_null), - cmocka_unit_test(test_multiline_ctxt_restore_restore), - // Test multiline_ctxt_free - cmocka_unit_test(test_multiline_ctxt_free_null), - cmocka_unit_test(test_multiline_ctxt_free_free), - // Test multiline_ctxt_backup - cmocka_unit_test(test_multiline_ctxt_backup_no_restore), - cmocka_unit_test(test_multiline_ctxt_backup_new_ctxt), - cmocka_unit_test(test_multiline_ctxt_backup_increment), - // Test multiline_getlog_start - cmocka_unit_test(test_multiline_getlog_start_single_no_context), - cmocka_unit_test(test_multiline_getlog_start_ctxt_timeout), - cmocka_unit_test(test_multiline_getlog_start_ctxt_append_ctxt), - cmocka_unit_test(test_multiline_getlog_start_ctxt_match), - cmocka_unit_test(test_multiline_getlog_start_no_ctxt_match), - cmocka_unit_test(test_multiline_getlog_start_no_ctxt_overflow), - cmocka_unit_test(test_multiline_getlog_start_ctxt_overflow), - cmocka_unit_test(test_multiline_getlog_start_no_ctxt_cant_read), - cmocka_unit_test(test_multiline_getlog_start_ctxt_cant_read), - cmocka_unit_test(test_multiline_getlog_start_match_multi_replace), - // Test multiline_getlog_end - cmocka_unit_test(test_multiline_getlog_end_single_match_no_context), - cmocka_unit_test(test_multiline_getlog_end_ctxt_timeout), - cmocka_unit_test(test_multiline_getlog_end_ctxt_append_ctxt), - cmocka_unit_test(test_multiline_getlog_end_multi_match_no_context), - cmocka_unit_test(test_multiline_getlog_end_multi_match_context), - cmocka_unit_test(test_multiline_getlog_end_no_ctxt_overflow), - cmocka_unit_test(test_multiline_getlog_end_ctxt_overflow), - cmocka_unit_test(test_multiline_getlog_end_no_ctxt_cant_read), - cmocka_unit_test(test_multiline_getlog_end_ctxt_cant_read), - cmocka_unit_test(test_multiline_getlog_end_match_multi_replace), - // Test multiline_getlog_all - cmocka_unit_test(test_multiline_getlog_all_single_match_no_context), - cmocka_unit_test(test_multiline_getlog_all_ctxt_timeout), - cmocka_unit_test(test_multiline_getlog_all_ctxt_append_ctxt), - cmocka_unit_test(test_multiline_getlog_all_multi_match_no_context), - cmocka_unit_test(test_multiline_getlog_all_multi_match_context), - cmocka_unit_test(test_multiline_getlog_all_no_ctxt_overflow), - cmocka_unit_test(test_multiline_getlog_all_ctxt_overflow), - cmocka_unit_test(test_multiline_getlog_all_no_ctxt_cant_read), - cmocka_unit_test(test_multiline_getlog_all_ctxt_cant_read), - cmocka_unit_test(test_multiline_getlog_all_match_multi_replace), - // Tests multiline_getlog - cmocka_unit_test(test_multiline_getlog_unknown), - cmocka_unit_test(test_multiline_getlog_start), - cmocka_unit_test(test_multiline_getlog_end), - cmocka_unit_test(test_multiline_getlog_all), - // Tests read_multiline_regex - cmocka_unit_test(test_read_multiline_regex_no_aviable_log), - cmocka_unit_test(test_read_multiline_regex_log_process), - cmocka_unit_test(test_read_multiline_regex_cant_read), - cmocka_unit_test(test_read_multiline_regex_invalid_context), - cmocka_unit_test(test_read_multiline_regex_log_ignored), - // Test get_file_chunk - cmocka_unit_test(test_get_file_chunk_fseek_fail), - cmocka_unit_test(test_get_file_chunk_size_reduce), - cmocka_unit_test(test_get_file_chunk_ok), - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/logcollector/test_read_win_event_channel.c b/src/unit_tests/logcollector/test_read_win_event_channel.c deleted file mode 100644 index 30dcba1fbda..00000000000 --- a/src/unit_tests/logcollector/test_read_win_event_channel.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ -#include "shared.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -typedef struct test_struct { - EVT_HANDLE evt; - LPCWSTR provider_name; - const char *message; -} test_struct_t; - -char *get_message(EVT_HANDLE evt, LPCWSTR provider_name, DWORD flags); - -/* Setup & Teardown */ - -static int test_setup(void ** state) { - test_struct_t *init_data = NULL; - - os_calloc(1, sizeof(test_struct_t), init_data); - init_data->evt = NULL; - init_data->provider_name = L"provider_name"; - init_data->message = "Test_Message"; - *state = init_data; - - test_mode = 1; - return 0; -} - -static int test_teardown(void ** state) { - test_struct_t *data = (test_struct_t*)*state; - - os_free(data); - - test_mode = 0; - return 0; -} - -/* Wraps */ - -/* Tests */ - -void test_get_message_get_publisher_fail(void ** state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(wrap_EvtOpenPublisherMetadata, Session, NULL); - expect_string(wrap_EvtOpenPublisherMetadata, PublisherId, data->provider_name); - expect_value(wrap_EvtOpenPublisherMetadata, LogFilePath, NULL); - expect_value(wrap_EvtOpenPublisherMetadata, Locale, 0); - expect_value(wrap_EvtOpenPublisherMetadata, Flags, 0); - will_return(wrap_EvtOpenPublisherMetadata, NULL); - - will_return(wrap_GetLastError, ERROR_FILE_NOT_FOUND); - will_return(wrap_FormatMessage, "File not found."); - expect_string(__wrap__mdebug1, formatted_msg, "Could not EvtOpenPublisherMetadata() with flags (1) which returned (2): File not found."); - - assert_null(get_message(data->evt, data->provider_name, EvtFormatMessageEvent)); -} - -void test_get_message_get_size_fail(void ** state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(wrap_EvtOpenPublisherMetadata, Session, NULL); - expect_string(wrap_EvtOpenPublisherMetadata, PublisherId, data->provider_name); - expect_value(wrap_EvtOpenPublisherMetadata, LogFilePath, NULL); - expect_value(wrap_EvtOpenPublisherMetadata, Locale, 0); - expect_value(wrap_EvtOpenPublisherMetadata, Flags, 0); - will_return(wrap_EvtOpenPublisherMetadata, 1); - - will_return(wrap_EvtFormatMessage, strlen(data->message)); - will_return(wrap_EvtFormatMessage, TRUE); - will_return(wrap_GetLastError, ERROR_INSUFFICIENT_BUFFER); - expect_string(__wrap__merror, formatted_msg, "Could not EvtFormatMessage() to determine buffer size with flags (1) which returned (122)"); - - will_return(wrap_EvtClose, TRUE); - - assert_null(get_message(data->evt, data->provider_name, EvtFormatMessageEvent)); - -} - -void test_get_message_format_fail(void ** state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(wrap_EvtOpenPublisherMetadata, Session, NULL); - expect_string(wrap_EvtOpenPublisherMetadata, PublisherId, data->provider_name); - expect_value(wrap_EvtOpenPublisherMetadata, LogFilePath, NULL); - expect_value(wrap_EvtOpenPublisherMetadata, Locale, 0); - expect_value(wrap_EvtOpenPublisherMetadata, Flags, 0); - will_return(wrap_EvtOpenPublisherMetadata, 1); - - will_return(wrap_EvtFormatMessage, strlen(data->message)); - will_return(wrap_EvtFormatMessage, FALSE); - will_return(wrap_GetLastError, ERROR_INSUFFICIENT_BUFFER); - - will_return(wrap_EvtFormatMessage, data->message); - will_return(wrap_EvtFormatMessage, FALSE); - will_return(wrap_GetLastError, ERROR_INSUFFICIENT_BUFFER); - expect_string(__wrap__merror, formatted_msg, "Could not EvtFormatMessage() with flags (1) which returned (122)"); - - will_return(wrap_EvtClose, TRUE); - - assert_null(get_message(data->evt, data->provider_name, EvtFormatMessageEvent)); -} - -void test_get_message_convert_string_fail(void ** state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(wrap_EvtOpenPublisherMetadata, Session, NULL); - expect_string(wrap_EvtOpenPublisherMetadata, PublisherId, data->provider_name); - expect_value(wrap_EvtOpenPublisherMetadata, LogFilePath, NULL); - expect_value(wrap_EvtOpenPublisherMetadata, Locale, 0); - expect_value(wrap_EvtOpenPublisherMetadata, Flags, 0); - will_return(wrap_EvtOpenPublisherMetadata, 1); - - will_return(wrap_EvtFormatMessage, strlen(data->message)); - will_return(wrap_EvtFormatMessage, FALSE); - will_return(wrap_GetLastError, ERROR_INSUFFICIENT_BUFFER); - - will_return(wrap_EvtFormatMessage, data->message); - will_return(wrap_EvtFormatMessage, TRUE); - - expect_string(__wrap_convert_windows_string, string, "Test_Message"); - will_return(__wrap_convert_windows_string, NULL); - - will_return(wrap_EvtClose, TRUE); - - assert_null(get_message(data->evt, data->provider_name, EvtFormatMessageEvent)); -} - -void test_get_message_success(void ** state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(wrap_EvtOpenPublisherMetadata, Session, NULL); - expect_string(wrap_EvtOpenPublisherMetadata, PublisherId, data->provider_name); - expect_value(wrap_EvtOpenPublisherMetadata, LogFilePath, NULL); - expect_value(wrap_EvtOpenPublisherMetadata, Locale, 0); - expect_value(wrap_EvtOpenPublisherMetadata, Flags, 0); - will_return(wrap_EvtOpenPublisherMetadata, 1); - - will_return(wrap_EvtFormatMessage, strlen(data->message)); - will_return(wrap_EvtFormatMessage, FALSE); - will_return(wrap_GetLastError, ERROR_INSUFFICIENT_BUFFER); - - will_return(wrap_EvtFormatMessage, data->message); - will_return(wrap_EvtFormatMessage, TRUE); - - expect_string(__wrap_convert_windows_string, string, "Test_Message"); - will_return(__wrap_convert_windows_string, "Test_Message"); - - will_return(wrap_EvtClose, TRUE); - - assert_non_null(get_message(data->evt, data->provider_name, EvtFormatMessageEvent)); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_get_message_get_publisher_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_message_get_size_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_message_format_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_message_convert_string_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_message_success, test_setup, test_teardown) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/logcollector/test_state.c b/src/unit_tests/logcollector/test_state.c deleted file mode 100644 index e7354677788..00000000000 --- a/src/unit_tests/logcollector/test_state.c +++ /dev/null @@ -1,1233 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../logcollector/state.h" - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/posix/pthread_wrappers.h" - -void w_logcollector_state_init(w_lc_state_type_t state_type, bool state_file_enabled); -cJSON * w_logcollector_state_get(); -cJSON * _w_logcollector_generate_state(w_lc_state_storage_t * state, bool restart); -void _w_logcollector_state_update_file(w_lc_state_storage_t * state, char * fpath, uint64_t bytes); -void w_logcollector_state_update_file(char * fpath, uint64_t bytes); -void _w_logcollector_state_update_target(w_lc_state_storage_t * state, char * fpath, char * target, bool dropped); -void w_logcollector_state_update_target(char * fpath, char * target, bool dropped); -void w_logcollector_state_generate(); -void w_logcollector_state_dump(); -void * w_logcollector_state_main(__attribute__((unused)) void * args); -void _w_logcollector_state_delete_file(w_lc_state_storage_t * state, char * fpath); -void w_logcollector_state_delete_file(char * fpath); - -extern cJSON * g_lc_json_stats; -extern w_lc_state_storage_t * g_lc_states_global; -extern w_lc_state_storage_t * g_lc_states_interval; -extern w_lc_state_type_t g_lc_state_type; - -void free_state_file(w_lc_state_file_t * data) { - if (data == NULL) { - return; - } - - if (data->targets != NULL) { - w_lc_state_target_t ** target = data->targets; - while (target && *target != NULL) { - os_free((*target)->name); - os_free(*target); - target++; - } - os_free(data->targets); - } - os_free(data); -} - -/* setup/teardown */ -static int setup_local_hashmap(void **state) { - if (mock_hashmap == NULL) { - will_return(__wrap_time, (time_t) 50); - if (setup_hashmap(state) != 0) { - return 1; - } - } - - OSHash *hash; - - will_return(__wrap_time, (time_t) 50); - - - hash = __real_OSHash_Create(); - - if (hash == NULL) { - return -1; - } - - *state = hash; - - return 0; -} - - -static int setup_hashmap_state_file(void **state) { - if (setup_local_hashmap(state) != 0) { - return 1; - } - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))free_state_file); - - return 0; -} - -static int teardown_local_hashmap(void **state) { - if (teardown_hashmap(state) != 0) { - return 1; - } - OSHash *hash = *state; - - if (hash == NULL) { - return 0; - } - - OSHash_Free(hash); - return 0; -} - -static int setup_global_variables(void ** state) { - os_calloc(1, sizeof(w_lc_state_storage_t), g_lc_states_global); - os_calloc(1, sizeof(w_lc_state_storage_t), g_lc_states_interval); - - if (setup_local_hashmap((void **)&(g_lc_states_global->states))) { - return -1; - } - - if (setup_local_hashmap((void **)&(g_lc_states_interval->states))) { - return -1; - } - - return 0; -} - -static int teardown_global_variables(void ** state) { - if (g_lc_states_global != NULL) { - if (teardown_local_hashmap((void **)&(g_lc_states_global->states))) { - return -1; - } - } - - if (g_lc_states_interval != NULL) { - if (teardown_local_hashmap((void **)&(g_lc_states_interval->states))) { - return -1; - } - } - - os_free(g_lc_states_global); - os_free(g_lc_states_interval); - - return 0; -} - -static int setup_group(void ** state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void ** state) { - test_mode = 0; - return 0; -} - -static int setup_global(void ** state) { - char **array = calloc(10, sizeof(char*)); - - if(array == NULL) - return -1; - - *state = array; - - return 0; -} - -static int teardown_global(void ** state) { - - return 0; -} - -/* wraps */ -size_t __wrap_strftime(char *s, size_t max, const char *format, - const struct tm *tm) { - strncpy(s, mock_type(char *), max); - return mock(); -} - -/* tests */ - -/* w_logcollector_state_init */ -void test_w_logcollector_state_init_fail_hash_create_global(void ** state) { - will_return(__wrap_time, (time_t) 50); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, NULL); - - expect_string(__wrap__merror_exit, formatted_msg, "(1296): Unable to create a 'logcollector_state' hash table"); - expect_assert_failure(w_logcollector_state_init(LC_STATE_GLOBAL|LC_STATE_INTERVAL, true)); -} - -void test_w_logcollector_state_init_fail_hash_create_interval(void ** state) { - os_free(g_lc_states_global); - os_free(g_lc_states_interval); - OSHash *mock_local_hash = *state; - will_return(__wrap_time, (time_t) 50); - - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_local_hash); - - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_time, 51); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, NULL); - - expect_string(__wrap__merror_exit, formatted_msg, "(1296): Unable to create a 'logcollector_state' hash table"); - expect_assert_failure(w_logcollector_state_init(LC_STATE_GLOBAL|LC_STATE_INTERVAL, true)); -} - -void test_w_logcollector_state_init_fail_hash_setsize_global(void ** state) { - os_free(g_lc_states_global); - os_free(g_lc_states_interval); - - OSHash *mock_local_hash = *state; - - will_return(__wrap_time, (time_t) 50); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, mock_local_hash); - will_return(__wrap_OSHash_setSize, 0); - - expect_string(__wrap__merror_exit, formatted_msg, "(1297): Unable to set size of 'logcollector_state' hash table"); - - expect_assert_failure(w_logcollector_state_init(LC_STATE_GLOBAL|LC_STATE_INTERVAL, true)); -} - -void test_w_logcollector_state_init_fail_hash_setsize_interval(void ** state) { - os_free(g_lc_states_global); - os_free(g_lc_states_interval); - will_return_always(__wrap_time, (time_t) 50); - - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, __real_OSHash_Create()); - will_return(__wrap_OSHash_setSize, 1); - - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, __real_OSHash_Create()); - will_return(__wrap_OSHash_setSize, 0); - - expect_string(__wrap__merror_exit, formatted_msg, "(1297): Unable to set size of 'logcollector_state' hash table"); - - expect_assert_failure(w_logcollector_state_init(LC_STATE_GLOBAL|LC_STATE_INTERVAL, true)); -} - -void test_w_logcollector_state_init_ok(void ** state) { - g_lc_state_type = 0; - will_return(__wrap_time, (time_t) 50); - will_return(__wrap_time, (time_t) 51); - - OSHash *global_state = __real_OSHash_Create(); - OSHash *states_interval = __real_OSHash_Create(); - - will_return(__wrap_time, (time_t) 50); - will_return(__wrap_time, (time_t) 51); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, global_state); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, states_interval); - - will_return(__wrap_OSHash_setSize, 1); - will_return(__wrap_OSHash_setSize, 1); - - w_logcollector_state_init(LC_STATE_GLOBAL | LC_STATE_INTERVAL, true); - - assert_non_null(g_lc_states_global); - assert_non_null(g_lc_states_interval); - - assert_ptr_equal(g_lc_states_global->states, global_state); - assert_ptr_equal(g_lc_states_interval->states, states_interval); - - assert_int_equal(g_lc_state_type, LC_STATE_GLOBAL | LC_STATE_INTERVAL); -} - - -void test_w_logcollector_state_get_null(void ** state) { - g_lc_state_type = LC_STATE_INTERVAL; - g_lc_json_stats = NULL; - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - assert_null(w_logcollector_state_get()); -} - -void test_w_logcollector_state_get_non_null(void ** state) { - - cJSON * expect_retval = (cJSON *) 3; - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - g_lc_json_stats = (cJSON *) 5; - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_cJSON_Duplicate, expect_retval); - expect_function_call(__wrap_pthread_mutex_unlock); - - cJSON * retval = w_logcollector_state_get(); - - assert_ptr_not_equal(g_lc_json_stats, retval); - assert_ptr_equal(expect_retval, retval); -} - -/* Test _w_logcollector_generate_state */ -void test__w_logcollector_generate_state_fail_get_node(void ** state) { - - w_lc_state_storage_t stats = {.states = (OSHash *) 2}; - cJSON * retval; - expect_value(__wrap_OSHash_Begin, self, stats.states); - will_return(__wrap_OSHash_Begin, NULL); - - retval = _w_logcollector_generate_state(&stats, 0); - assert_null(retval); -} - -void test__w_logcollector_generate_state_one_target(void ** state) { - cJSON * retval; - w_lc_state_storage_t stats = {.states = (OSHash *) 2 , }; - w_lc_state_target_t target = {.drops = 10, .name = "sock1"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - OSHashNode hash_node = {.data = &data, .key = "key_test"}; - - expect_value(__wrap_OSHash_Begin, self, stats.states); - will_return(__wrap_OSHash_Begin, &hash_node); - - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - will_return_always(__wrap_cJSON_AddItemToArray, true); - will_return_always(__wrap_cJSON_AddItemToObject, true); - - will_return_always(__wrap_cJSON_CreateObject, (cJSON *) 10); - will_return_always(__wrap_cJSON_CreateArray, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "sock1"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "drops"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 10); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - - expect_string(__wrap_cJSON_AddStringToObject, name, "location"); - expect_string(__wrap_cJSON_AddStringToObject, string, "key_test"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "events"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - expect_string(__wrap_cJSON_AddNumberToObject, name, "bytes"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 100); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_value(__wrap_OSHash_Next, self, stats.states); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_strftime,"2019-02-05 12:18:37"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_cJSON_AddStringToObject, name, "start"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:37"); - - will_return(__wrap_time, (time_t) 2525); - will_return(__wrap_strftime,"2019-02-05 12:18:42"); - will_return(__wrap_strftime, 20); - expect_string(__wrap_cJSON_AddStringToObject, name, "end"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:42"); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - retval = _w_logcollector_generate_state(&stats, false); - assert_ptr_equal(retval, (cJSON *) 10); - assert_int_equal(data.bytes, 100); - assert_int_equal(data.events, 5); -} - -void test__w_logcollector_generate_state_one_target_restart(void ** state) { - - cJSON * retval; - w_lc_state_storage_t stats = {.states = (OSHash *) 2, .start = (time_t) 2020}; - w_lc_state_target_t target = {.drops = 10, .name = "sock1"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - OSHashNode hash_node = {.data = &data, .key = "key_test"}; - - expect_value(__wrap_OSHash_Begin, self, stats.states); - will_return(__wrap_OSHash_Begin, &hash_node); - - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - will_return_always(__wrap_cJSON_AddItemToArray, true); - will_return_always(__wrap_cJSON_AddItemToObject, true); - - will_return_always(__wrap_cJSON_CreateObject, (cJSON *) 10); - will_return_always(__wrap_cJSON_CreateArray, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "sock1"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "drops"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 10); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_string(__wrap_cJSON_AddStringToObject, name, "location"); - expect_string(__wrap_cJSON_AddStringToObject, string, "key_test"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "events"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - expect_string(__wrap_cJSON_AddNumberToObject, name, "bytes"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 100); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_value(__wrap_OSHash_Next, self, stats.states); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_strftime,"2019-02-05 12:18:37"); - will_return(__wrap_strftime, 20); - expect_string(__wrap_cJSON_AddStringToObject, name, "start"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:37"); - - will_return(__wrap_time, (time_t) 2525); - will_return(__wrap_strftime,"2019-02-05 12:18:42"); - will_return(__wrap_strftime, 20);; - expect_string(__wrap_cJSON_AddStringToObject, name, "end"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:42"); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_time, (time_t) 2525); - - retval = _w_logcollector_generate_state(&stats, true); - - assert_ptr_equal(retval, (cJSON *) 10); - assert_int_equal(data.bytes, 0); - assert_int_equal(data.events, 0); - assert_int_equal(stats.start, 2525); -} - -/* Test _w_logcollector_state_update_file */ -void test__w_logcollector_state_update_file_new_data(void ** state) { - w_lc_state_storage_t stat = {0}; - stat.states = *state; - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))free_state_file); - - expect_value(__wrap_OSHash_Get, self, stat.states); - expect_string(__wrap_OSHash_Get, key, "/test_path"); - will_return(__wrap_OSHash_Get, NULL); - - will_return(__wrap_OSHash_Update, 0); - - expect_value(__wrap_OSHash_Add, key, "/test_path"); - will_return(__wrap_OSHash_Add, 2); - - _w_logcollector_state_update_file(&stat, "/test_path", 100); -} - -void test__w_logcollector_state_update_file_update(void ** state) { - w_lc_state_storage_t stat = { .states = *state }; - w_lc_state_file_t *data = calloc(1, sizeof(w_lc_state_file_t)); - - expect_value(__wrap_OSHash_Get, self, stat.states); - expect_string(__wrap_OSHash_Get, key, "/test_path"); - will_return(__wrap_OSHash_Get, data); - - will_return(__wrap_OSHash_Update, 1); - - _w_logcollector_state_update_file(&stat, "/test_path", 100); - - assert_int_equal(data->bytes, 100); - assert_int_equal(data->events, 1); - free(data); -} - -/* w_logcollector_state_update_file */ -void test__w_logcollector_state_update_file_fail_update(void ** state) { - w_lc_state_storage_t stat = { .states = *state }; - __real_OSHash_SetFreeDataPointer(stat.states, (void (*)(void *))free_state_file); - - w_lc_state_file_t * data = NULL; - os_calloc(1, sizeof(w_lc_state_file_t), data); - os_calloc(2, sizeof(w_lc_state_target_t *), data->targets); - os_calloc(1, sizeof(w_lc_state_target_t), data->targets[0]); - - expect_value(__wrap_OSHash_Get, self, stat.states); - expect_string(__wrap_OSHash_Get, key, "/test_path"); - will_return(__wrap_OSHash_Get, data); - - will_return(__wrap_OSHash_Update, 0); - expect_value(__wrap_OSHash_Add, key, "/test_path"); - will_return(__wrap_OSHash_Add, 0); - - expect_string(__wrap__merror, formatted_msg, - "(1299): Failure to update '/test_path' to 'logcollector_state' hash table"); - - _w_logcollector_state_update_file(&stat, "/test_path", 100); -} - -/* w_logcollector_state_update_file */ -void test_w_logcollector_state_update_file_null(void ** state) { - w_logcollector_state_update_file(NULL, 500); -} - - -/* _w_logcollector_state_update_target */ -void test__w_logcollector_state_update_target_get_file_stats_fail(void ** state) { - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - w_lc_state_storage_t stats = { .states = *state }; - w_lc_state_file_t *mock_entry = calloc(1, sizeof(w_lc_state_file_t)); - char *fpath = "/test_path"; - char *target = "test"; - - __real_OSHash_Add_ex(mock_hashmap, fpath, mock_entry); - bool dropped = false; - - expect_value(__wrap_OSHash_Get, self, stats.states); - expect_string(__wrap_OSHash_Get, key, fpath); - will_return(__wrap_OSHash_Get, NULL); - - will_return(__wrap_OSHash_Update, 1); - - _w_logcollector_state_update_target(&stats, fpath, target, dropped); -} - -void test__w_logcollector_state_update_target_find_target_fail(void ** state) { - char * fpath = "/test_path"; - char * target_str = "test2"; - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - - __real_OSHash_Add_ex(mock_hashmap, fpath, calloc(1, sizeof(w_lc_state_file_t))); - - w_lc_state_storage_t * stats = NULL; - os_calloc(1, sizeof(w_lc_state_storage_t), stats); - stats->states = *state; - stats->start = (time_t) 2020; - - w_lc_state_target_t * target; - os_calloc(1, sizeof(w_lc_state_target_t), target); - target->drops = 10; - os_strdup("test", target->name); - - w_lc_state_target_t ** target_array; - os_calloc(2, sizeof(w_lc_state_target_t *), target_array); - target_array[0] = target; - - w_lc_state_file_t * data; - os_calloc(1, sizeof(w_lc_state_file_t), data); - data->targets = target_array; - data->bytes = 100; - data->events = 5; - - bool dropped = false; - - expect_value(__wrap_OSHash_Get, self, stats->states); - expect_string(__wrap_OSHash_Get, key, fpath); - will_return(__wrap_OSHash_Get, data); - - will_return(__wrap_OSHash_Update, 1); - - _w_logcollector_state_update_target(stats, fpath, target_str, dropped); - free(stats); -} - - -void test__w_logcollector_state_update_target_find_target_ok(void ** state) { - char * fpath = "/test_path"; - char * target_str = "test"; - - bool dropped = false; - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - w_lc_state_storage_t stats = {.states = *state, .start = (time_t) 2020}; - w_lc_state_target_t target = {.drops = 10, .name = "test"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - - - expect_value(__wrap_OSHash_Get, self, stats.states); - expect_string(__wrap_OSHash_Get, key, fpath); - will_return(__wrap_OSHash_Get, &data); - - will_return(__wrap_OSHash_Update, 1); - - _w_logcollector_state_update_target(&stats, fpath, target_str, dropped); -} - -void test__w_logcollector_state_update_target_dropped_true(void ** state) { - - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - w_lc_state_storage_t stats = {.states = (OSHash *) *state, .start = (time_t) 2020}; - w_lc_state_target_t target = {.drops = 10, .name = "test"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - - char * fpath = "/test_path"; - char * target_str = "test"; - - expect_value(__wrap_OSHash_Get, self, stats.states); - expect_string(__wrap_OSHash_Get, key, fpath); - will_return(__wrap_OSHash_Get, &data); - - will_return(__wrap_OSHash_Update, 1); - bool dropped = true; - - _w_logcollector_state_update_target(&stats, fpath, target_str, dropped); -} - -void test__w_logcollector_state_update_target_OSHash_Update_fail(void ** state) { - - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - w_lc_state_storage_t stats = {.states = (OSHash *) *state, .start = (time_t) 2020}; - w_lc_state_target_t target = {.drops = 10, .name = "test"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - - char * fpath = "/test_path"; - char * target_str = "test"; - - bool dropped = true; - - - expect_value(__wrap_OSHash_Get, self, stats.states); - expect_string(__wrap_OSHash_Get, key, fpath); - will_return(__wrap_OSHash_Get, &data); - - will_return(__wrap_OSHash_Update, 0); - - expect_value(__wrap_OSHash_Add, key, "/test_path"); - will_return(__wrap_OSHash_Add, 2); - - _w_logcollector_state_update_target(&stats, fpath, target_str, dropped); -} - -void test__w_logcollector_state_update_target_OSHash_Add_fail(void ** state) { - - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - w_lc_state_storage_t stats = {.states = (OSHash *) *state}; - w_lc_state_target_t * target; - os_calloc(1, sizeof(w_lc_state_target_t), target); - target->drops = 10; - os_strdup("test", target->name); - - w_lc_state_target_t ** target_array; - os_calloc(2, sizeof(w_lc_state_target_t *), target_array); - target_array[0] = target; - - w_lc_state_file_t * data; - os_calloc(1, sizeof(w_lc_state_file_t), data); - data->targets = target_array; - data->bytes = 100; - data->events = 5; - - char * fpath = "/test_path"; - char * target_str = "test"; - - bool dropped = true; - - expect_value(__wrap_OSHash_Get, self, stats.states); - expect_string(__wrap_OSHash_Get, key, fpath); - will_return(__wrap_OSHash_Get, data); - - will_return(__wrap_OSHash_Update, 0); - - expect_value(__wrap_OSHash_Add, key, "/test_path"); - will_return(__wrap_OSHash_Add, 0); - - expect_string(__wrap__merror, formatted_msg, - "(1299): Failure to update '/test_path' to 'logcollector_state' hash table"); - - _w_logcollector_state_update_target(&stats, fpath, target_str, dropped); -} - -void test_w_logcollector_state_update_file_ok(void ** state) { - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - - w_lc_state_file_t data = {0}; - w_lc_state_file_t data2 = {.bytes = 10, .events = 5}; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_value(__wrap_OSHash_Get, self, g_lc_states_global->states); - expect_string(__wrap_OSHash_Get, key, "/test_path"); - will_return(__wrap_OSHash_Get, &data); - - will_return(__wrap_OSHash_Update, 1); - - expect_value(__wrap_OSHash_Get, self, g_lc_states_interval->states); - expect_string(__wrap_OSHash_Get, key, "/test_path"); - will_return(__wrap_OSHash_Get, &data2); - - will_return(__wrap_OSHash_Update, 1); - - expect_function_call(__wrap_pthread_mutex_unlock); - w_logcollector_state_update_file("/test_path", 500); - - assert_int_equal(data.bytes, 500); - assert_int_equal(data.events, 1); - assert_int_equal(data2.bytes, 510); - assert_int_equal(data2.events, 6); -} - -// Tests w_logcollector_state_update_target -void test_w_logcollector_state_update_target_null_target(void ** state) { - w_logcollector_state_update_target("test path", NULL, false); -} - -void test_w_logcollector_state_update_target_null_path(void ** state) { - w_logcollector_state_update_target(NULL, "test_target", false); -} - -void test_w_logcollector_state_update_target_ok(void ** state) { - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL; - - w_lc_state_target_t target = {.drops = 10, .name = "test_target"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get, self, g_lc_states_global->states); - expect_string(__wrap_OSHash_Get, key, "test_path"); - will_return(__wrap_OSHash_Get, &data); - - will_return(__wrap_OSHash_Update, 1); - - w_lc_state_target_t target2 = {.drops = 10, .name = "test_target"}; - w_lc_state_target_t * target_array2[2] = {&target, NULL}; - w_lc_state_file_t data2 = {.targets = (w_lc_state_target_t **) &target_array2, .bytes = 100, .events = 5}; - - expect_value(__wrap_OSHash_Get, self, g_lc_states_interval->states); - expect_string(__wrap_OSHash_Get, key, "test_path"); - will_return(__wrap_OSHash_Get, &data2); - - will_return(__wrap_OSHash_Update, 1); - - expect_function_call(__wrap_pthread_mutex_unlock); - - w_logcollector_state_update_target("test_path", "test_target", false); -} - -/* w_logcollector_state_generate */ -void test_w_logcollector_generate_state_ok(void ** state) { - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL;; - - w_lc_state_target_t target = {.drops = 10, .name = "sock1"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - OSHashNode hash_node = {.data = &data, .key = "key_test"}; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_function_call(__wrap_cJSON_Delete); - - will_return_always(__wrap_cJSON_CreateObject, (cJSON *) 10); - - expect_value(__wrap_OSHash_Begin, self, g_lc_states_global->states); - will_return(__wrap_OSHash_Begin, &hash_node); - - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - will_return_always(__wrap_cJSON_AddItemToArray, true); - will_return_always(__wrap_cJSON_AddItemToObject, true); - - will_return_always(__wrap_cJSON_CreateArray, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "sock1"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "drops"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 10); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_string(__wrap_cJSON_AddStringToObject, name, "location"); - expect_string(__wrap_cJSON_AddStringToObject, string, "key_test"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "events"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - expect_string(__wrap_cJSON_AddNumberToObject, name, "bytes"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 100); - expect_function_call(__wrap_cJSON_AddItemToObject); - - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_value(__wrap_OSHash_Next, self, g_lc_states_global->states); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_strftime,"2019-02-05 12:18:37"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_cJSON_AddStringToObject, name, "start"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:37"); - - will_return(__wrap_time, (time_t) 2525); - will_return(__wrap_strftime,"2019-02-05 12:18:42"); - will_return(__wrap_strftime, 20); - expect_string(__wrap_cJSON_AddStringToObject, name, "end"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:42"); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - g_lc_states_interval->start = (time_t) 2020; - - w_lc_state_file_t data2 = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - OSHashNode hash_node2 = {.data = &data2, .key = "key_test"}; - - expect_value(__wrap_OSHash_Begin, self, g_lc_states_interval->states); - will_return(__wrap_OSHash_Begin, &hash_node2); - - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "sock1"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "drops"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 10); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - - expect_string(__wrap_cJSON_AddStringToObject, name, "location"); - expect_string(__wrap_cJSON_AddStringToObject, string, "key_test"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "events"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - expect_string(__wrap_cJSON_AddNumberToObject, name, "bytes"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 100); - expect_function_call(__wrap_cJSON_AddItemToObject); - - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_value(__wrap_OSHash_Next, self, g_lc_states_interval->states); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_strftime,"2019-02-05 12:18:37"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_cJSON_AddStringToObject, name, "start"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:37"); - - will_return(__wrap_time, (time_t) 2525); - will_return(__wrap_strftime,"2019-02-05 12:18:42"); - will_return(__wrap_strftime, 20); - expect_string(__wrap_cJSON_AddStringToObject, name, "end"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:42"); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_time, (time_t) 2525); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_mutex_unlock); - - w_logcollector_state_generate(); - - assert_int_equal(data.bytes, 100); - assert_int_equal(data.events, 5); - assert_int_equal(data2.bytes, 0); - assert_int_equal(data2.events, 0); - assert_int_equal(g_lc_states_interval->start, 2525); -} - -/* w_logcollector_state_dump */ -void test_w_logcollector_state_dump_fail_open(void ** state) { - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_cJSON_Duplicate, (cJSON *) 3); - expect_function_call(__wrap_pthread_mutex_unlock); - will_return(__wrap_cJSON_Print, strdup("Test 123")); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap_wfopen, path, LOGCOLLECTOR_STATE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, NULL); - - const char * error_msg = "(1103): Could not open file " - "'" LOGCOLLECTOR_STATE "' due to"; - - expect_memory(__wrap__merror, formatted_msg, error_msg, strlen(error_msg)); - - w_logcollector_state_dump(); -} - -void test_w_logcollector_state_dump_fail_write(void ** state) { - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_cJSON_Duplicate, (cJSON *) 3); - expect_function_call(__wrap_pthread_mutex_unlock); - will_return(__wrap_cJSON_Print, strdup("Test 123")); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap_wfopen, path, LOGCOLLECTOR_STATE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *) 100); - will_return(__wrap_fwrite, 0); - - const char * error_msg = "(1110): Could not write file " - "'" LOGCOLLECTOR_STATE "' due to"; - - expect_memory(__wrap__merror, formatted_msg, error_msg, strlen(error_msg)); - - expect_value(__wrap_fclose, _File, (FILE *) 100); - will_return(__wrap_fclose, 0); - - w_logcollector_state_dump(); -} - -void test_w_logcollector_state_dump_ok(void ** state) { - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_cJSON_Duplicate, (cJSON *) 3); - expect_function_call(__wrap_pthread_mutex_unlock); - will_return(__wrap_cJSON_Print, strdup("Test 123")); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap_wfopen, path, LOGCOLLECTOR_STATE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *) 100); - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, (FILE *) 100); - will_return(__wrap_fclose, 0); - - w_logcollector_state_dump(); -} - -void test_w_logcollector_state_main_bad_interval(void ** state) { - - g_lc_state_type = LC_STATE_GLOBAL | LC_STATE_INTERVAL;; - int interval = -1; - w_logcollector_state_main((void *) &interval); -} - -void test_w_logcollector_state_main_ok(void ** state) { - - int interval = 105; - will_return(__wrap_FOREVER, 1); - expect_value(__wrap_sleep, seconds, interval); - - w_lc_state_target_t target = {.drops = 10, .name = "sock1"}; - w_lc_state_target_t * target_array[2] = {&target, NULL}; - - w_lc_state_file_t data = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - OSHashNode hash_node = {.data = &data, .key = "key_test"}; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_function_call(__wrap_cJSON_Delete); - - will_return_always(__wrap_cJSON_CreateObject, (cJSON *) 10); - - expect_value(__wrap_OSHash_Begin, self, g_lc_states_global->states); - will_return(__wrap_OSHash_Begin, &hash_node); - - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - will_return_always(__wrap_cJSON_AddItemToArray, true); - will_return_always(__wrap_cJSON_AddItemToObject, true); - - will_return_always(__wrap_cJSON_CreateArray, (cJSON *) 1); - - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "sock1"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "drops"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 10); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_string(__wrap_cJSON_AddStringToObject, name, "location"); - expect_string(__wrap_cJSON_AddStringToObject, string, "key_test"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "events"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - expect_string(__wrap_cJSON_AddNumberToObject, name, "bytes"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 100); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_value(__wrap_OSHash_Next, self, g_lc_states_global->states); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_strftime,"2019-02-05 12:18:37"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_cJSON_AddStringToObject, name, "start"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:37"); - - will_return(__wrap_time, (time_t) 2525); - will_return(__wrap_strftime,"2019-02-05 12:18:42"); - will_return(__wrap_strftime, 20); - expect_string(__wrap_cJSON_AddStringToObject, name, "end"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:42"); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - g_lc_states_interval->start = (time_t) 2020; - - w_lc_state_file_t data2 = {.targets = (w_lc_state_target_t **) &target_array, .bytes = 100, .events = 5}; - OSHashNode hash_node2 = {.data = &data2, .key = "key_test"}; - - expect_value(__wrap_OSHash_Begin, self, g_lc_states_interval->states); - will_return(__wrap_OSHash_Begin, &hash_node2); - - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "sock1"); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "drops"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 10); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - - expect_string(__wrap_cJSON_AddStringToObject, name, "location"); - expect_string(__wrap_cJSON_AddStringToObject, string, "key_test"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "events"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 5); - expect_string(__wrap_cJSON_AddNumberToObject, name, "bytes"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 100); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_cJSON_AddItemToArray); - - expect_value(__wrap_OSHash_Next, self, g_lc_states_interval->states); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_strftime,"2019-02-05 12:18:37"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_cJSON_AddStringToObject, name, "start"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:37"); - - will_return(__wrap_time, (time_t) 2525); - will_return(__wrap_strftime,"2019-02-05 12:18:42"); - will_return(__wrap_strftime, 20); - expect_string(__wrap_cJSON_AddStringToObject, name, "end"); - expect_string(__wrap_cJSON_AddStringToObject, string, "2019-02-05 12:18:42"); - - expect_function_call(__wrap_cJSON_AddItemToObject); - will_return(__wrap_time, (time_t) 2525); - - expect_function_call(__wrap_cJSON_AddItemToObject); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_cJSON_Duplicate, (cJSON *) 3); - expect_function_call(__wrap_pthread_mutex_unlock); - will_return(__wrap_cJSON_Print, strdup("Test 123")); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap_wfopen, path, LOGCOLLECTOR_STATE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *) 100); - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, (FILE *) 100); - will_return(__wrap_fclose, 0); - - will_return(__wrap_FOREVER, 0); - - w_logcollector_state_main((void *) &interval); -} - -/* _test_w_logcollector_state_delete_file */ - -void test__w_logcollector_state_delete_file_no_data(void ** state) { - w_lc_state_storage_t storage = { .states = *state }; - - expect_value(__wrap_OSHash_Delete, self, storage.states); - expect_string(__wrap_OSHash_Delete, key, "test_path"); - will_return(__wrap_OSHash_Delete, NULL); - - _w_logcollector_state_delete_file(&storage, "test_path"); -} - -void test__w_logcollector_state_delete_file_ok(void ** state) { - w_lc_state_storage_t storage = {.states = *state}; - - w_lc_state_file_t * data = NULL; - os_calloc(1, sizeof(w_lc_state_file_t), data); - os_calloc(3, sizeof(w_lc_state_target_t *), data->targets); - os_calloc(1, sizeof(w_lc_state_target_t), data->targets[0]); - os_strdup("target name 1", data->targets[0]->name); - os_calloc(1, sizeof(w_lc_state_target_t), data->targets[1]); - os_strdup("target name 2", data->targets[1]->name); - - expect_value(__wrap_OSHash_Delete, self, storage.states); - expect_string(__wrap_OSHash_Delete, key, "test_path"); - will_return(__wrap_OSHash_Delete, data); - - _w_logcollector_state_delete_file(&storage, "test_path"); -} - -/* w_logcollector_state_delete_file */ - -void test_w_logcollector_state_delete_file_fpath_NULL(void ** state) { - - char * fpath = NULL; - - w_logcollector_state_delete_file(fpath); - -} - -void test_w_logcollector_state_delete_file_global(void ** state) { - g_lc_state_type = 1; - char * fpath = "test"; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Delete, self, g_lc_states_global->states); - expect_string(__wrap_OSHash_Delete, key, fpath); - will_return(__wrap_OSHash_Delete, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - - w_logcollector_state_delete_file(fpath); -} - -void test_w_logcollector_state_delete_file_interval(void ** state) { - char * fpath = "test"; - g_lc_state_type = 2; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Delete, self, g_lc_states_interval->states); - expect_string(__wrap_OSHash_Delete, key, fpath); - will_return(__wrap_OSHash_Delete, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - - w_logcollector_state_delete_file(fpath); -} - -void test_w_logcollector_state_delete_file_global_interval(void ** state) { - char * fpath = "test"; - g_lc_state_type = 3; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_value(__wrap_OSHash_Delete, self, g_lc_states_global->states); - expect_string(__wrap_OSHash_Delete, key, fpath); - will_return(__wrap_OSHash_Delete, NULL); - - expect_value(__wrap_OSHash_Delete, self, g_lc_states_interval->states); - expect_string(__wrap_OSHash_Delete, key, fpath); - will_return(__wrap_OSHash_Delete, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - - w_logcollector_state_delete_file(fpath); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Tests w_logcollector_state_init - cmocka_unit_test_teardown(test_w_logcollector_state_init_fail_hash_create_global, teardown_global_variables), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_init_fail_hash_create_interval, setup_local_hashmap, teardown_global_variables), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_init_fail_hash_setsize_global, setup_local_hashmap, teardown_global_variables), - cmocka_unit_test_teardown(test_w_logcollector_state_init_fail_hash_setsize_interval, teardown_global_variables), - cmocka_unit_test_teardown(test_w_logcollector_state_init_ok, teardown_global_variables), - - // Tests w_logcollector_state_get - cmocka_unit_test(test_w_logcollector_state_get_null), - cmocka_unit_test(test_w_logcollector_state_get_non_null), - - // Tests _w_logcollector_generate_state - cmocka_unit_test_setup_teardown(test__w_logcollector_generate_state_fail_get_node, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_generate_state_one_target, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_generate_state_one_target_restart, setup_local_hashmap, teardown_local_hashmap), - - // Tests _w_logcollector_state_update_file - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_file_new_data, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_file_update, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_file_fail_update, setup_local_hashmap, teardown_local_hashmap), - - // Tests w_logcollector_state_update_file - cmocka_unit_test(test_w_logcollector_state_update_file_null), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_update_file_ok, setup_global_variables, teardown_global_variables), - - // Tests _w_logcollector_state_update_target - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_target_get_file_stats_fail, setup_hashmap_state_file, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_target_find_target_fail, setup_hashmap_state_file, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_target_find_target_ok, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_target_dropped_true, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_target_OSHash_Update_fail, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_update_target_OSHash_Add_fail, setup_local_hashmap, teardown_local_hashmap), - - // Tests w_logcollector_state_update_target - cmocka_unit_test(test_w_logcollector_state_update_target_null_path), - cmocka_unit_test(test_w_logcollector_state_update_target_null_target), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_update_target_ok, setup_global_variables, teardown_global_variables), - - // Tests w_logcollector_state_generate - cmocka_unit_test_setup_teardown(test_w_logcollector_generate_state_ok, setup_global_variables, teardown_global_variables), - - // Tests w_logcollector_state_dump - cmocka_unit_test(test_w_logcollector_state_dump_fail_open), - cmocka_unit_test(test_w_logcollector_state_dump_fail_write), - cmocka_unit_test(test_w_logcollector_state_dump_ok), - - // Tests w_logcollector_state_main - cmocka_unit_test(test_w_logcollector_state_main_bad_interval), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_main_ok, setup_global_variables, teardown_global_variables), - - // Test _w_logcollector_state_delete_file - cmocka_unit_test_setup_teardown(test__w_logcollector_state_delete_file_no_data, setup_local_hashmap, teardown_local_hashmap), - cmocka_unit_test_setup_teardown(test__w_logcollector_state_delete_file_ok, setup_local_hashmap, teardown_local_hashmap), - - // Test _w_logcollector_state_delete_file - cmocka_unit_test(test_w_logcollector_state_delete_file_fpath_NULL), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_delete_file_global, setup_global_variables, teardown_global_variables), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_delete_file_interval, setup_global_variables, teardown_global_variables), - cmocka_unit_test_setup_teardown(test_w_logcollector_state_delete_file_global_interval, setup_global_variables, teardown_global_variables), - - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/monitord/CMakeLists.txt b/src/unit_tests/monitord/CMakeLists.txt deleted file mode 100644 index 23822c8395e..00000000000 --- a/src/unit_tests/monitord/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -# Generate monitord library -file(GLOB monitord_files - ${SRC_FOLDER}/monitord/*.o) - -# Generate os_maild library -file(GLOB os_maild_files - ${SRC_FOLDER}/os_maild/*.o) - -add_library(MONITOR_O STATIC ${monitord_files}) -add_library(MAILD_O STATIC ${os_maild_files}) - -set_source_files_properties( - ${monitord_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_source_files_properties( - ${os_maild_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - MONITOR_O - PROPERTIES - LINKER_LANGUAGE C -) - -set_target_properties( - MAILD_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(MONITOR_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) -target_link_libraries(MAILD_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -list(APPEND monitord_tests_names "test_monitord") -list(APPEND monitord_tests_flags "-Wl,--wrap,time\ - -Wl,--wrap,StartMQ -Wl,--wrap,SendMSG -Wl,--wrap,getDefine_Int -Wl,--wrap,ReadConfig\ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND monitord_tests_names "test_monitor_actions") -list(APPEND monitord_tests_flags "-Wl,--wrap,SendMSG -Wl,--wrap,wdb_find_agent\ - -Wl,--wrap,wdb_disconnect_agents -Wl,--wrap,time -Wl,--wrap,wdb_get_agent_info -Wl,--wrap,auth_connect\ - -Wl,--wrap,get_agent_id_from_name -Wl,--wrap,auth_remove_agent -Wl,--wrap,wdb_get_agents_by_connection_status\ - -Wl,--wrap,w_rotate_log -Wl,--wrap,stat ${HASH_OP_WRAPPERS} ${DEBUG_OP_WRAPPERS}") - -# Add extra compiling flags -add_compile_options(-Wall) - -# Compilig tests -list(LENGTH monitord_tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET monitord_tests_names ${counter} test_name) - list(GET monitord_tests_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - MONITOR_O - MAILD_O - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/monitord/test_monitor_actions.c b/src/unit_tests/monitord/test_monitor_actions.c deleted file mode 100644 index fbe4dbd2c18..00000000000 --- a/src/unit_tests/monitord/test_monitor_actions.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * November, 2020. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh//monitord/monitord_wrappers.h" -#include "../wrappers/posix/stat_wrappers.h" -#include "../wrappers/wazuh/shared/auth_client_wrappers.h" -#include "../wrappers/wazuh/shared/agent_op_wrappers.h" - -#include "../config/client-config.h" -#include "../headers/store_op.h" -#include "../monitord/monitord.h" -#include "../headers/defs.h" -#include "../headers/shared.h" -#include "../config/config.h" - -/* redefinitons/wrapping */ -extern monitor_time_control mond_time_control; - -/* setup/teardown */ - -int setup_monitord(void **state) { - test_mode = 1; - mond.global.agents_disconnection_alert_time = 0; - mond.global.agents_disconnection_time = 0; - - mond.delete_old_agents = 0; - mond.a_queue = -1; - mond.day_wait = 0; - mond.rotate_log = 1; - mond.size_rotate = 0; - mond.monitor_agents = 0; - - mond_time_control.disconnect_counter = 0; - mond_time_control.alert_counter = 0; - mond_time_control.delete_counter = 0; - mond_time_control.today = 0; - mond_time_control.thismonth = 0; - mond_time_control.thisyear = 0; - - return 0; -} - -int teardown_monitord(void **state) { - test_mode = 0; - - mond.global.agents_disconnection_alert_time = 0; - mond.global.agents_disconnection_time = 0; - - mond.delete_old_agents = 0; - mond.a_queue = -1; - mond.day_wait = 0; - mond.rotate_log = 1; - mond.size_rotate = 0; - mond.monitor_agents = 0; - - mond_time_control.disconnect_counter = 0; - mond_time_control.alert_counter = 0; - mond_time_control.delete_counter = 0; - mond_time_control.today = 0; - mond_time_control.thismonth = 0; - mond_time_control.thisyear = 0; - - return 0; -} - -// Tests - -/* Tests monitor_send_deletion_msg */ - -void test_monitor_send_deletion_msg_success(void **state) { - char *agent = "Agent1-any"; - char msg_to_send[OS_SIZE_1024]; - - snprintf(msg_to_send, OS_SIZE_1024, OS_AG_REMOVED, agent); - mond.a_queue = 1; - - expect_string(__wrap_SendMSG, message, msg_to_send); - expect_string(__wrap_SendMSG, locmsg, ARGV0); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - monitor_send_deletion_msg(agent); - - assert_int_equal(1, mond.a_queue); -} - -void test_monitor_send_deletion_msg_fail(void **state) { - char *agent = "Agent1-any"; - char msg_to_send[OS_SIZE_1024]; - - snprintf(msg_to_send, OS_SIZE_1024, OS_AG_REMOVED, agent); - mond.a_queue = 1; - - expect_string(__wrap_SendMSG, message, msg_to_send); - expect_string(__wrap_SendMSG, locmsg, ARGV0); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not generate removed agent alert for 'Agent1-any'"); - expect_string(__wrap__merror, formatted_msg, QUEUE_SEND); - - monitor_send_deletion_msg(agent); - - assert_int_equal(-1, mond.a_queue); -} - -/* Tests monitor_send_disconnection_msg */ - -void test_monitor_send_disconnection_msg_success(void **state) { - char *agent = "Agent1-any"; - char msg_to_send[OS_SIZE_1024]; - char header[OS_SIZE_256]; - - expect_string(__wrap_wdb_find_agent, name, "Agent1"); - expect_string(__wrap_wdb_find_agent, ip, "any"); - will_return(__wrap_wdb_find_agent, 1); - - snprintf(msg_to_send, OS_SIZE_1024, AG_DISCON_MSG, agent); - snprintf(header, OS_SIZE_256, "[%03d] (%s) %s", 1, "Agent1", "any"); - - expect_string(__wrap_SendMSG, message, msg_to_send); - expect_string(__wrap_SendMSG, locmsg, header); - expect_value(__wrap_SendMSG, loc, SECURE_MQ); - will_return(__wrap_SendMSG, 1); - mond.a_queue = 1; - - monitor_send_disconnection_msg(agent); - - assert_int_equal(1, mond.a_queue); -} - -void test_monitor_send_disconnection_msg_send_msg_fail(void **state) { - char *agent = "Agent1-any"; - char msg_to_send[OS_SIZE_1024]; - char header[OS_SIZE_256]; - - expect_string(__wrap_wdb_find_agent, name, "Agent1"); - expect_string(__wrap_wdb_find_agent, ip, "any"); - will_return(__wrap_wdb_find_agent, 1); - - snprintf(msg_to_send, OS_SIZE_1024, AG_DISCON_MSG, agent); - snprintf(header, OS_SIZE_256, "[%03d] (%s) %s", 1, "Agent1", "any"); - - expect_string(__wrap_SendMSG, message, msg_to_send); - expect_string(__wrap_SendMSG, locmsg, header); - expect_value(__wrap_SendMSG, loc, SECURE_MQ); - will_return(__wrap_SendMSG, -1); - mond.a_queue = 1; - expect_string(__wrap__merror, formatted_msg, QUEUE_SEND); - expect_string(__wrap__mdebug1, formatted_msg, "Could not generate disconnected agent alert for 'Agent1-any'"); - - monitor_send_disconnection_msg(agent); - - assert_int_equal(-1, mond.a_queue); -} - -void test_monitor_send_disconnection_msg_agent_removed(void **state) { - char *agent = "Agent1-any"; - char msg_to_send[OS_SIZE_1024]; - - expect_string(__wrap_wdb_find_agent, name, "Agent1"); - expect_string(__wrap_wdb_find_agent, ip, "any"); - will_return(__wrap_wdb_find_agent, -2); - - // monitor_send_deletion_msg - snprintf(msg_to_send, OS_SIZE_1024, OS_AG_REMOVED, agent); - expect_string(__wrap_SendMSG, message, msg_to_send); - expect_string(__wrap_SendMSG, locmsg, ARGV0); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - mond.a_queue = 1; - - monitor_send_disconnection_msg(agent); - - assert_int_equal(1, mond.a_queue); -} - -void test_monitor_send_disconnection_msg_fail(void **state) { - char *agent = "Agent1-any"; - - expect_string(__wrap_wdb_find_agent, name, "Agent1"); - expect_string(__wrap_wdb_find_agent, ip, "any"); - will_return(__wrap_wdb_find_agent, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not generate disconnected agent alert for 'Agent1-any'"); - mond.a_queue = 1; - - monitor_send_disconnection_msg(agent); - - assert_int_equal(1, mond.a_queue); -} - -/* Tests monitor_agents_disconnection */ - -void test_monitor_agents_disconnection(void **state) { - int *agents_array_test = NULL; - // Arbitraty date 03 Nov 2020 11:39:10 - int last_keepalive = 1604403550; - - os_calloc(3, sizeof(int), agents_array_test); - // Arbitrary agent's ID 13,5 - agents_array_test[0] = 13; - agents_array_test[1] = 5; - agents_array_test[2] = -1; - - mond.global.agents_disconnection_time = 100; - mond.monitor_agents = 1; - - expect_value(__wrap_wdb_disconnect_agents, keepalive, last_keepalive - mond.global.agents_disconnection_time); - expect_string(__wrap_wdb_disconnect_agents, sync_status, "synced"); - will_return(__wrap_wdb_disconnect_agents, agents_array_test); - - will_return_count(__wrap_time, 1604403550, -1); - will_return(__wrap_OSHash_Add, 2); - will_return(__wrap_OSHash_Add, 0); - expect_string(__wrap_OSHash_Add, key, "13"); - expect_string(__wrap_OSHash_Add, key, "5"); - - expect_string(__wrap__mdebug1, formatted_msg, "Can't add agent ID '5' to the alerts hash table"); - - monitor_agents_disconnection(); -} - -void test_monitor_send_disconnection_ip_fail(void **state) { - char *agent = "Agent1"; - - expect_string(__wrap__mdebug1, formatted_msg, "Could not generate disconnected agent alert for 'Agent1'"); - - monitor_send_disconnection_msg(agent); -} - -void test_monitor_send_disconnection_name_size_fail(void **state) { - char *agent = NULL; - char *agent_append = "text"; - char debug_message[OS_SIZE_512]; - - // Creating a long name - do {wm_strcat(&agent, agent_append, 0);} while (strlen(agent) < 256); - wm_strcat(&agent, "any", '-'); - - snprintf(debug_message, OS_SIZE_512, "Could not generate disconnected agent alert for '%s'", agent); - expect_string(__wrap__mdebug1, formatted_msg, debug_message); - - monitor_send_disconnection_msg(agent); - - os_free(agent); -} - -/* Tests monitor_agents_alert */ - -void test_monitor_agents_alert_active() { - // Setting an arbitrary last_keepalive = 100 - cJSON *j_agent_info = cJSON_Parse("[{\"connection_status\":\"active\",\"last_keepalive\":100,\"name\":\"Agent1\",\"register_ip\":\"any\"}]"); - OSHashNode *current_node = NULL; - - os_calloc(1, sizeof(OSHashNode), current_node); - current_node->next = NULL; - current_node->key = "1"; - - expect_value(__wrap_OSHash_Begin, self, agents_to_alert_hash); - will_return(__wrap_OSHash_Begin, current_node); - - expect_value(__wrap_OSHash_Next, self, agents_to_alert_hash); - will_return(__wrap_OSHash_Next, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info); - - expect_value(__wrap_OSHash_Delete, self, agents_to_alert_hash); - expect_value(__wrap_OSHash_Delete, key, "1"); - will_return(__wrap_OSHash_Delete, 2); - - monitor_agents_alert(); - - os_free(current_node); -} - -void test_monitor_agents_alert_agent_info_fail() { - cJSON *j_agent_info = NULL; - OSHashNode *current_node = NULL; - - os_calloc(1, sizeof(OSHashNode), current_node); - current_node->next = NULL; - current_node->key = "1"; - - expect_value(__wrap_OSHash_Begin, self, agents_to_alert_hash); - will_return(__wrap_OSHash_Begin, current_node); - - expect_value(__wrap_OSHash_Next, self, agents_to_alert_hash); - will_return(__wrap_OSHash_Next, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info); - - expect_string(__wrap__mdebug1, formatted_msg, "Unable to retrieve agent's '1' data from Wazuh DB"); - expect_value(__wrap_OSHash_Delete, self, agents_to_alert_hash); - expect_value(__wrap_OSHash_Delete, key, "1"); - will_return(__wrap_OSHash_Delete, 2); - - monitor_agents_alert(); - - os_free(current_node); -} - -void test_monitor_agents_alert_message_sent() { - // Setting an arbitrary last_keepalive = 100 - cJSON *j_agent_info = cJSON_Parse("[{\"connection_status\":\"disconnected\",\ - \"last_keepalive\":100,\"name\":\"Agent1\",\"register_ip\":\"any\"}]"); - OSHashNode *current_node = NULL; - char msg_to_send[OS_SIZE_1024]; - char header[OS_SIZE_256]; - - os_calloc(1, sizeof(OSHashNode), current_node); - current_node->next = NULL; - current_node->key = "1"; - - expect_value(__wrap_OSHash_Begin, self, agents_to_alert_hash); - will_return(__wrap_OSHash_Begin, current_node); - - expect_value(__wrap_OSHash_Next, self, agents_to_alert_hash); - will_return(__wrap_OSHash_Next, NULL); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info); - - mond.global.agents_disconnection_time = 20; - mond.global.agents_disconnection_alert_time = 100; - will_return(__wrap_time, 1000); - - // monitor_send_disconnection_msg - expect_string(__wrap_wdb_find_agent, name, "Agent1"); - expect_string(__wrap_wdb_find_agent, ip, "any"); - will_return(__wrap_wdb_find_agent, 1); - snprintf(msg_to_send, OS_SIZE_1024, AG_DISCON_MSG, "Agent1-any"); - snprintf(header, OS_SIZE_256, "[%03d] (%s) %s", 1, "Agent1", "any"); - expect_string(__wrap_SendMSG, message, msg_to_send); - expect_string(__wrap_SendMSG, locmsg, header); - expect_value(__wrap_SendMSG, loc, SECURE_MQ); - will_return(__wrap_SendMSG, 1); - - expect_value(__wrap_OSHash_Delete, self, agents_to_alert_hash); - expect_value(__wrap_OSHash_Delete, key, "1"); - will_return(__wrap_OSHash_Delete, 2); - - monitor_agents_alert(); - - os_free(current_node); -} - -/* Tests monitor_agents_deletion */ - -void test_monitor_agents_deletion_success() { - int *agents_array_test = NULL; - char msg_to_send[OS_SIZE_1024]; - char *agent_id_str = NULL; - // Setting an arbitrary last_keepalive = 100 - cJSON *j_agent_info = cJSON_Parse("[{\"last_keepalive\":100,\"name\":\"Agent13\",\"register_ip\":\"any\"}]"); - - os_calloc(2, sizeof(int), agents_array_test); - // Arbitrary agent's ID 13 - agents_array_test[0] = 13; - agents_array_test[1] = -1; - - mond.global.agents_disconnection_time = 20; - mond.delete_old_agents = 2; - will_return(__wrap_time, 1000); - - expect_string(__wrap_wdb_get_agents_by_connection_status, status, "disconnected"); - will_return(__wrap_wdb_get_agents_by_connection_status, agents_array_test); - - expect_value(__wrap_wdb_get_agent_info, id, 13); - will_return(__wrap_wdb_get_agent_info, j_agent_info); - - // delete_old_agent - os_strdup("13", agent_id_str); - will_return(__wrap_get_agent_id_from_name, agent_id_str); - will_return(__wrap_auth_connect, 1); - expect_string(__wrap_auth_remove_agent, id, agent_id_str); - will_return(__wrap_auth_remove_agent, 0); - - // monitor_send_deletion_msg - snprintf(msg_to_send, OS_SIZE_1024, OS_AG_REMOVED, "Agent13-any"); - expect_string(__wrap_SendMSG, message, msg_to_send); - expect_string(__wrap_SendMSG, locmsg, ARGV0); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - monitor_agents_deletion(); -} - -void test_monitor_agents_deletion_agent_info_fail() { - int *agents_array_test = NULL; - - os_calloc(2, sizeof(int), agents_array_test); - // Arbitrary agent's ID 13 - agents_array_test[0] = 13; - agents_array_test[1] = -1; - - expect_string(__wrap_wdb_get_agents_by_connection_status, status, "disconnected"); - will_return(__wrap_wdb_get_agents_by_connection_status, agents_array_test); - - expect_value(__wrap_wdb_get_agent_info, id, 13); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Unable to retrieve agent's '13' data from Wazuh DB"); - expect_value(__wrap_OSHash_Delete, self, agents_to_alert_hash); - expect_string(__wrap_OSHash_Delete, key, "13"); - will_return(__wrap_OSHash_Delete, 2); - - monitor_agents_deletion(); -} - -void test_monitor_agents_deletion_auth_fail() { - int *agents_array_test = NULL; - char *agent_id_str = NULL; - // Setting an arbitrary last_keepalive = 100 - cJSON *j_agent_info = cJSON_Parse("[{\"last_keepalive\":100,\"name\":\"Agent13\",\"register_ip\":\"any\"}]"); - - os_calloc(2, sizeof(int), agents_array_test); - // Arbitrary agent's ID 13 - agents_array_test[0] = 13; - agents_array_test[1] = -1; - - mond.global.agents_disconnection_time = 20; - mond.delete_old_agents = 2; - will_return(__wrap_time, 1000); - - expect_string(__wrap_wdb_get_agents_by_connection_status, status, "disconnected"); - will_return(__wrap_wdb_get_agents_by_connection_status, agents_array_test); - - expect_value(__wrap_wdb_get_agent_info, id, 13); - will_return(__wrap_wdb_get_agent_info, j_agent_info); - - // delete_old_agent - os_strdup("13", agent_id_str); - will_return(__wrap_get_agent_id_from_name, agent_id_str); - will_return(__wrap_auth_connect, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Monitord could not connect to to Authd socket. Is Authd running?"); - - monitor_agents_deletion(); -} - -void test_monitor_agents_deletion_agent_id_fail() { - int *agents_array_test = NULL; - // Setting an arbitrary last_keepalive = 100 - cJSON *j_agent_info = cJSON_Parse("[{\"last_keepalive\":100,\"name\":\"Agent13\",\"register_ip\":\"any\"}]"); - - os_calloc(2, sizeof(int), agents_array_test); - // Arbitrary agent's ID 13 - agents_array_test[0] = 13; - agents_array_test[1] = -1; - - mond.global.agents_disconnection_time = 20; - mond.delete_old_agents = 2; - will_return(__wrap_time, 1000); - - expect_string(__wrap_wdb_get_agents_by_connection_status, status, "disconnected"); - will_return(__wrap_wdb_get_agents_by_connection_status, agents_array_test); - - expect_value(__wrap_wdb_get_agent_info, id, 13); - will_return(__wrap_wdb_get_agent_info, j_agent_info); - - // delete_old_agent - will_return(__wrap_get_agent_id_from_name, NULL); - - monitor_agents_deletion(); -} - -/* Tests monitor_logs */ - - void test_monitor_logs_size_false() { - bool check_logs_size = FALSE; - char path[PATH_MAX] = "/path"; - char path_json[PATH_MAX] = "/path_json"; - - mond.day_wait = 0; - mond.rotate_log = 1; - - monitor_logs(check_logs_size, path, path_json); - } - - void test_monitor_logs_size_true() { - bool check_logs_size = TRUE; - char path[PATH_MAX] = "/path"; - char path_json[PATH_MAX] = "/path_json"; - struct stat stat_load = { .st_mode = 100 }; - - mond.day_wait = 0; - mond.rotate_log = 1; - mond.size_rotate = 10; - - expect_string(__wrap_stat, __file, path); - will_return(__wrap_stat, &stat_load); - will_return(__wrap_stat, 0); - - expect_string(__wrap_stat, __file, path_json); - will_return(__wrap_stat, &stat_load); - will_return(__wrap_stat, 0); - - monitor_logs(check_logs_size, path, path_json); - } - -int main() -{ - const struct CMUnitTest tests[] = - { - /* Tests monitor_send_deletion_msg */ - cmocka_unit_test_setup_teardown(test_monitor_send_deletion_msg_success, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_send_deletion_msg_fail, setup_monitord, teardown_monitord), - /* Tests monitor_send_disconnection_msg */ - cmocka_unit_test_setup_teardown(test_monitor_send_disconnection_msg_success, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_send_disconnection_msg_send_msg_fail, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_send_disconnection_msg_agent_removed, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_send_disconnection_msg_fail, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_send_disconnection_ip_fail, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_send_disconnection_name_size_fail, setup_monitord, teardown_monitord), - /* Tests monitor_agents_disconnection */ - cmocka_unit_test_setup_teardown(test_monitor_agents_disconnection, setup_monitord, teardown_monitord), - /* Tests monitor_agents_alert */ - cmocka_unit_test_setup_teardown(test_monitor_agents_alert_active, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_agents_alert_agent_info_fail, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_agents_alert_message_sent, setup_monitord, teardown_monitord), - /* Tests monitor_agents_deletion */ - cmocka_unit_test_setup_teardown(test_monitor_agents_deletion_success, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_agents_deletion_agent_info_fail, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_agents_deletion_auth_fail, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_agents_deletion_agent_id_fail, setup_monitord, teardown_monitord), - /* Tests monitor_logs */ - cmocka_unit_test_setup_teardown(test_monitor_logs_size_false, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_logs_size_true, setup_monitord, teardown_monitord), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/monitord/test_monitord.c b/src/unit_tests/monitord/test_monitord.c deleted file mode 100644 index 336597a1ae6..00000000000 --- a/src/unit_tests/monitord/test_monitord.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * November, 2020. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../wrappers/wazuh/shared/validate_op_wrappers.h" - -#include "../external/cJSON/cJSON.h" -#include "../headers/store_op.h" -#include "../monitord/monitord.h" -#include "../headers/defs.h" -#include "../headers/shared.h" -#include "../config/config.h" -#include "os_err.h" - -/* redefinitons/wrapping */ - -int __wrap_ReadConfig(int modules, const char *cfgfile, __attribute__((unused)) void *d1, __attribute__((unused)) void *d2) { - check_expected(modules); - check_expected(cfgfile); - return mock(); -} - -extern monitor_time_control mond_time_control; - -/* setup/teardown */ - -int setup_monitord(void **state) { - test_mode = 1; - - mond.global.agents_disconnection_alert_time = 0; - mond.global.agents_disconnection_time = 0; - - mond.delete_old_agents = 0; - mond.a_queue = -1; - mond.day_wait = 0; - mond.compress = 0; - mond.sign = 0; - mond.monitor_agents = 0; - mond.keep_log_days = 0; - mond.rotate_log = 0; - mond.size_rotate = 0; - mond.daily_rotations = 0; - mond.delete_old_agents = 0; - - mond_time_control.disconnect_counter = 0; - mond_time_control.alert_counter = 0; - mond_time_control.delete_counter = 0; - mond_time_control.today = 0; - mond_time_control.thismonth = 0; - mond_time_control.thisyear = 0; - - return 0; -} - -int teardown_monitord(void **state) { - test_mode = 0; - - mond.global.agents_disconnection_alert_time = 0; - mond.global.agents_disconnection_time = 0; - - mond.delete_old_agents = 0; - mond.a_queue = -1; - mond.day_wait = 0; - mond.compress = 0; - mond.sign = 0; - mond.monitor_agents = 0; - mond.keep_log_days = 0; - mond.rotate_log = 0; - mond.size_rotate = 0; - mond.daily_rotations = 0; - mond.delete_old_agents = 0; - - mond_time_control.disconnect_counter = 0; - mond_time_control.alert_counter = 0; - mond_time_control.delete_counter = 0; - mond_time_control.today = 0; - mond_time_control.thismonth = 0; - mond_time_control.thisyear = 0; - - return 0; -} - -// Tests - -/* Tests monitor_init_time */ - -void test_monitor_init_time_success(void **state) { - // Setting an arbitrary date 02-Nov-20 12:10:01 - time_t tm = 1604319001; - struct tm test_time; - localtime_r(&tm, &test_time); - - will_return(__wrap_time, 1604319001); - // Setting random data - mond_time_control.disconnect_counter = 123; - mond_time_control.alert_counter = 456; - mond_time_control.delete_counter = 789; - - monitor_init_time_control(); - - assert_int_equal(0, mond_time_control.disconnect_counter); - assert_int_equal(0, mond_time_control.alert_counter); - assert_int_equal(0, mond_time_control.delete_counter); - - assert_int_equal(test_time.tm_sec, mond_time_control.current_time.tm_sec); - assert_int_equal(test_time.tm_min, mond_time_control.current_time.tm_min); - assert_int_equal(test_time.tm_hour, mond_time_control.current_time.tm_hour); - assert_int_equal(test_time.tm_mday, mond_time_control.current_time.tm_mday); - assert_int_equal(test_time.tm_mon, mond_time_control.current_time.tm_mon); - assert_int_equal(test_time.tm_year, mond_time_control.current_time.tm_year); - - assert_int_equal(mond_time_control.today, mond_time_control.current_time.tm_mday); - assert_int_equal(mond_time_control.thismonth, mond_time_control.current_time.tm_mon); - assert_int_equal(mond_time_control.thisyear, mond_time_control.current_time.tm_year + 1900); -} - -/* Tests monitor_step_time */ - -void test_monitor_step_time_success(void **state) { - // Setting an arbitrary date 02-Nov-20 12:20:01 - time_t tm = 1604319601; - struct tm test_time; - localtime_r(&tm, &test_time); - - mond.delete_old_agents = 1; - mond.monitor_agents = 1; - mond_time_control.disconnect_counter = 0; - mond_time_control.alert_counter = 0; - mond_time_control.delete_counter = 0; - will_return(__wrap_time, 1604319601); - - monitor_step_time(); - - assert_int_equal(1, mond_time_control.disconnect_counter); - assert_int_equal(1, mond_time_control.alert_counter); - assert_int_equal(1, mond_time_control.delete_counter); - - assert_int_equal(test_time.tm_sec, mond_time_control.current_time.tm_sec); - assert_int_equal(test_time.tm_min, mond_time_control.current_time.tm_min); - assert_int_equal(test_time.tm_hour, mond_time_control.current_time.tm_hour); - assert_int_equal(test_time.tm_mday, mond_time_control.current_time.tm_mday); - assert_int_equal(test_time.tm_mon, mond_time_control.current_time.tm_mon); - assert_int_equal(test_time.tm_year, mond_time_control.current_time.tm_year); -} - -void test_monitor_step_time_no_old_agents_success(void **state) { - // Setting an arbitrary date 02-Nov-20 12:20:01 - time_t tm = 1604319601; - struct tm test_time; - localtime_r(&tm, &test_time); - - mond.delete_old_agents = 0; - mond.monitor_agents = 1; - mond_time_control.disconnect_counter = 0; - mond_time_control.alert_counter = 0; - mond_time_control.delete_counter = 0; - will_return(__wrap_time, 1604319601); - - monitor_step_time(); - - assert_int_equal(1, mond_time_control.disconnect_counter); - assert_int_equal(1, mond_time_control.alert_counter); - assert_int_equal(0, mond_time_control.delete_counter); - - assert_int_equal(test_time.tm_sec, mond_time_control.current_time.tm_sec); - assert_int_equal(test_time.tm_min, mond_time_control.current_time.tm_min); - assert_int_equal(test_time.tm_hour, mond_time_control.current_time.tm_hour); - assert_int_equal(test_time.tm_mday, mond_time_control.current_time.tm_mday); - assert_int_equal(test_time.tm_mon, mond_time_control.current_time.tm_mon); - assert_int_equal(test_time.tm_year, mond_time_control.current_time.tm_year); -} - -/* Tests monitor_update_date */ - -void test_monitor_update_date_success(void **state) { - // Setting an arbitrary date 02-Nov-20 12:30:01 - time_t tm = 1604320201; - localtime_r(&tm, &mond_time_control.current_time); - - mond_time_control.today = 0; - mond_time_control.thismonth= 0; - mond_time_control.thisyear = 0; - - monitor_update_date(); - - assert_int_equal(mond_time_control.today, mond_time_control.current_time.tm_mday); - assert_int_equal(mond_time_control.thismonth, mond_time_control.current_time.tm_mon); - assert_int_equal(mond_time_control.thisyear, mond_time_control.current_time.tm_year + 1900); -} - -/* Tests check_disconnection_trigger */ - -void test_check_disconnection_trigger_true(void **state) { - int result = 0; - mond_time_control.disconnect_counter = 100; - mond.global.agents_disconnection_time = 10; - - result = check_disconnection_trigger(); - - assert_int_equal(result, 1); -} - -void test_check_disconnection_trigger_false(void **state) { - int result = 0; - mond_time_control.disconnect_counter = 1; - mond.global.agents_disconnection_time = 10; - - result = check_disconnection_trigger(); - - assert_int_equal(result, 0); -} - -/* Tests check_alert_trigger */ - -void test_check_alert_trigger_true(void **state) { - int result = 0; - mond_time_control.alert_counter = 100; - mond.global.agents_disconnection_alert_time = 10; - mond.monitor_agents = 1; - - result = check_alert_trigger(); - - assert_int_equal(result, 1); -} - -void test_check_alert_trigger_false(void **state) { - int result = 0; - mond_time_control.alert_counter = 1; - mond.global.agents_disconnection_alert_time = 10; - - result = check_alert_trigger(); - - assert_int_equal(result, 0); -} - -/* Tests check_deletion_trigger */ - -void test_check_deletion_trigger_true(void **state) { - int result = 0; - mond_time_control.delete_counter = 200; - mond.delete_old_agents = 2; - mond.monitor_agents = 1; - - result = check_deletion_trigger(); - - assert_int_equal(result, 1); -} - -void test_check_deletion_trigger_false(void **state) { - int result = 0; - mond_time_control.delete_counter = 100; - mond.delete_old_agents = 2; - - result = check_deletion_trigger(); - - assert_int_equal(result, 0); -} - -void test_check_deletion_trigger_no_old_agents_false(void **state) { - int result = 0; - mond_time_control.delete_counter = 0; - mond.delete_old_agents = 0; - - result = check_deletion_trigger(); - - assert_int_equal(result, 0); -} - -/* Tests check_logs_time_trigger */ - -void test_check_logs_time_trigger_true(void **state) { - int result = 0; - mond_time_control.today = 5; - mond_time_control.current_time.tm_mday = 6; - - result = check_logs_time_trigger(); - - assert_int_equal(result, 1); -} - -void test_check_logs_time_trigger_false(void **state) { - int result = 0; - mond_time_control.today = 5; - mond_time_control.current_time.tm_mday = 5; - - result = check_logs_time_trigger(); - - assert_int_equal(result, 0); -} - -/* Tests monitor_queue_connect */ - -void test_monitor_queue_connect_fail(void **state) { - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, -1); - - monitor_queue_connect(); - - assert_int_equal(mond.a_queue, -1); -} - -void test_monitor_queue_connect_success(void **state) { - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 1); - expect_string(__wrap_SendMSG, message, OS_MG_STARTED); - expect_string(__wrap_SendMSG, locmsg, ARGV0); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - monitor_queue_connect(); - - assert_int_equal(mond.a_queue, 1); -} - -void test_monitor_queue_connect_msg_fail(void **state) { - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 1); - expect_string(__wrap_SendMSG, message, OS_MG_STARTED); - expect_string(__wrap_SendMSG, locmsg, ARGV0); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, -1); - expect_string(__wrap__merror, formatted_msg, QUEUE_SEND); - - monitor_queue_connect(); - - assert_int_equal(mond.a_queue, -1); -} - -/* Tests getMonitorInternalOptions */ - -void test_getMonitorInternalOptions_success(void **state) { - cJSON *root = NULL; - cJSON *object = NULL; - - // Arbitrary configuration - mond.day_wait = 2; - mond.compress = 1; - mond.sign = 0; - mond.monitor_agents = 1; - mond.keep_log_days = 10; - mond.rotate_log = 1; - mond.size_rotate = 0; - mond.daily_rotations = 100; - mond.delete_old_agents = 3; - - root = getMonitorInternalOptions(); - - if (root) { - object = cJSON_GetObjectItem(root->child, "day_wait"); - assert_int_equal(object->valueint, mond.day_wait); - object = cJSON_GetObjectItem(root->child, "compress"); - assert_int_equal(object->valueint, mond.compress); - object = cJSON_GetObjectItem(root->child, "sign"); - assert_int_equal(object->valueint, mond.sign); - object = cJSON_GetObjectItem(root->child, "monitor_agents"); - assert_int_equal(object->valueint, mond.monitor_agents); - object = cJSON_GetObjectItem(root->child, "keep_log_days"); - assert_int_equal(object->valueint, mond.keep_log_days); - object = cJSON_GetObjectItem(root->child, "rotate_log"); - assert_int_equal(object->valueint, mond.rotate_log); - object = cJSON_GetObjectItem(root->child, "size_rotate"); - assert_int_equal(object->valueint, mond.size_rotate); - object = cJSON_GetObjectItem(root->child, "daily_rotations"); - assert_int_equal(object->valueint, mond.daily_rotations); - object = cJSON_GetObjectItem(root->child, "delete_old_agents"); - assert_int_equal(object->valueint, mond.delete_old_agents); - } - - cJSON_Delete(root); -} - -/* Tests getMonitorGlobalOptions */ - -void test_getMonitorGlobalOptions_success(void **state) { - cJSON *root = NULL; - cJSON *object = NULL; - - // Arbitrary configuration - mond.global.agents_disconnection_time = 20; - mond.global.agents_disconnection_alert_time = 100; - - root = getMonitorGlobalOptions(); - - if (root) { - object = cJSON_GetObjectItem(root->child, "agents_disconnection_time"); - assert_int_equal(object->valueint, mond.global.agents_disconnection_time); - object = cJSON_GetObjectItem(root->child, "agents_disconnection_alert_time"); - assert_int_equal(object->valueint, mond.global.agents_disconnection_alert_time); - } - - cJSON_Delete(root); -} - -/* Tests getReportsOptions */ - -void test_getReportsOptions_success(void **state) { - cJSON *root = NULL; - report_config **reports_array = NULL; - report_config *report = NULL; - char **email_array = NULL; - char *expected_output = "{\"reports\":[{\"title\":\"Title\",\"group\":\"Group\",\"rule\":\"Rule\",\ -\"level\":\"Level\",\"srcip\":\"SourceIP\",\"user\":\"User\",\"showlogs\":\"yes\",\"email_to\":[\"emailto_test\"]}]}"; - char *result = NULL; - - os_calloc(2, sizeof(report_config*), reports_array); - os_calloc(1, sizeof(report_config), report); - os_calloc(2, sizeof(char*), email_array); - - reports_array[0] = report; - reports_array[1] = NULL; - os_strdup("emailto_test", email_array[0]); - email_array[1] = NULL; - - // Arbitrary configuration - report->title = "Title"; - report->r_filter.group = "Group"; - report->r_filter.rule = "Rule"; - report->r_filter.level = "Level"; - report->r_filter.srcip = "SourceIP"; - report->r_filter.user = "User"; - report->r_filter.show_alerts = 1; - report->emailto = email_array; - mond.reports = reports_array; - - root = getReportsOptions(); - - result = cJSON_PrintUnformatted(root); - assert_string_equal(expected_output, result); - - cJSON_Delete(root); - os_free(report); - os_free(reports_array); - os_free(email_array[0]); - os_free(email_array); - os_free(result); -} - -/* Tests ReadConfig */ - -void test_MonitordConfig_success(void **state) { - int result = 0; - char *cfg = "/config_path"; - int no_agents = 0; - short day_wait = -1; - - will_return_count(__wrap_getDefine_Int, 1, -1); - - expect_value(__wrap_ReadConfig, modules, CREPORTS); - expect_string(__wrap_ReadConfig, cfgfile, cfg); - will_return(__wrap_ReadConfig, 0); - expect_value(__wrap_ReadConfig, modules, CGLOBAL); - expect_string(__wrap_ReadConfig, cfgfile, cfg); - will_return(__wrap_ReadConfig, 0); - - result = MonitordConfig(cfg, &mond, no_agents, day_wait); - - assert_int_equal(result, OS_SUCCESS); - assert_int_equal(mond.global.agents_disconnection_time, 600); - assert_int_equal(mond.global.agents_disconnection_alert_time, 0); - - assert_null(mond.agents); - assert_null(mond.smtpserver); - assert_null(mond.emailfrom); - assert_null(mond.emailidsname); - - assert_int_equal(mond.day_wait, 1); - assert_int_equal(mond.compress, 1); - assert_int_equal(mond.sign, 1); - assert_int_equal(mond.monitor_agents, 1); - assert_int_equal(mond.rotate_log, 1); - assert_int_equal(mond.keep_log_days, 1); - assert_int_equal(mond.size_rotate, 1 * 1024 * 1024); - assert_int_equal(mond.daily_rotations, 1); - assert_int_equal(mond.delete_old_agents, 1); -} - -void test_MonitordConfig_fail(void **state) { - char *cfg = "/config_path"; - int no_agents = 0; - short day_wait = -1; - - will_return_count(__wrap_getDefine_Int, 1, -1); - - expect_value(__wrap_ReadConfig, modules, CREPORTS); - expect_string(__wrap_ReadConfig, cfgfile, cfg); - will_return(__wrap_ReadConfig, -1); - - expect_string(__wrap__merror_exit, formatted_msg, "(1202): Configuration error at '/config_path'."); - - expect_assert_failure(MonitordConfig(cfg, &mond, no_agents, day_wait)); -} - -int main() -{ - const struct CMUnitTest tests[] = - { - /* Tests monitor_init_time */ - cmocka_unit_test_setup_teardown(test_monitor_init_time_success, setup_monitord, teardown_monitord), - /* Tests monitor_step_time */ - cmocka_unit_test_setup_teardown(test_monitor_step_time_success, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_step_time_no_old_agents_success, setup_monitord, teardown_monitord), - /* Tests monitor_update_date */ - cmocka_unit_test_setup_teardown(test_monitor_update_date_success, setup_monitord, teardown_monitord), - /* Tests check_disconnection_trigger */ - cmocka_unit_test_setup_teardown(test_check_disconnection_trigger_true, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_check_disconnection_trigger_false, setup_monitord, teardown_monitord), - /* Tests check_alert_trigger */ - cmocka_unit_test_setup_teardown(test_check_alert_trigger_true, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_check_alert_trigger_false, setup_monitord, teardown_monitord), - /* Tests check_deletion_trigger */ - cmocka_unit_test_setup_teardown(test_check_deletion_trigger_true, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_check_deletion_trigger_false, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_check_deletion_trigger_no_old_agents_false, setup_monitord, teardown_monitord), - /* Tests check_logs_time_trigger */ - cmocka_unit_test_setup_teardown(test_check_logs_time_trigger_true, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_check_logs_time_trigger_false, setup_monitord, teardown_monitord), - /* Tests monitor_queue_connect */ - cmocka_unit_test_setup_teardown(test_monitor_queue_connect_fail, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_queue_connect_success, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_monitor_queue_connect_msg_fail, setup_monitord, teardown_monitord), - /* Tests getMonitorInternalOptions */ - cmocka_unit_test_setup_teardown(test_getMonitorInternalOptions_success, setup_monitord, teardown_monitord), - /* Tests getMonitorGlobalOptions */ - cmocka_unit_test_setup_teardown(test_getMonitorGlobalOptions_success, setup_monitord, teardown_monitord), - /* Tests getReportsOptions */ - cmocka_unit_test_setup_teardown(test_getReportsOptions_success, setup_monitord, teardown_monitord), - /* Tests MonitordConfig */ - cmocka_unit_test_setup_teardown(test_MonitordConfig_success, setup_monitord, teardown_monitord), - cmocka_unit_test_setup_teardown(test_MonitordConfig_fail, setup_monitord, teardown_monitord), - - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_auth/CMakeLists.txt b/src/unit_tests/os_auth/CMakeLists.txt deleted file mode 100644 index e341480d140..00000000000 --- a/src/unit_tests/os_auth/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -# Generate os_auth library -file(GLOB os_auth_files - ${SRC_FOLDER}/os_auth/*.o - ${SRC_FOLDER}/addagent/*.o) -list(REMOVE_ITEM os_auth_files ${SRC_FOLDER}/os_auth/main-server.o) -list(REMOVE_ITEM os_auth_files ${SRC_FOLDER}/addagent/main.o) - -add_library(OS_AUTH_O STATIC ${os_auth_files}) - -set_source_files_properties( - ${os_auth_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - OS_AUTH_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(OS_AUTH_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) -include_directories(${SRC_FOLDER}/os_auth) -# Generate Analysisd tests -list(APPEND os_auth_names "test_auth_parse") -list(APPEND os_auth_flags "${DEBUG_OP_WRAPPERS} -Wl,--wrap,OS_IsValidIP") -list(APPEND os_auth_names "test_auth_validate") -list(APPEND os_auth_flags "${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,opendir -Wl,--wrap,closedir -Wl,--wrap,OS_RemoveAgentGroup -Wl,--wrap,add_remove \ - -Wl,--wrap,wdb_get_agent_info -Wl,--wrap,difftime -Wl,--wrap,OS_IsValidIP") -list(APPEND os_auth_names "test_auth_add") -list(APPEND os_auth_flags "${DEBUG_OP_WRAPPERS} -Wl,--wrap,OS_IsValidIP") -list(APPEND os_auth_names "test_ssl") -list(APPEND os_auth_flags "-Wl,--wrap,SSL_read -Wl,--wrap=SSL_new") -list(APPEND os_auth_names "test_auth_key_request") -list(APPEND os_auth_flags "-Wl,--wrap,_merror -Wl,--wrap,_mwarn -Wl,--wrap,_minfo -Wl,--wrap,_mdebug1 -Wl,--wrap,_mdebug2 \ - -Wl,--wrap,wm_exec -Wl,--wrap,wpopenv -Wl,--wrap,fgets -Wl,--wrap,popen \ - -Wl,--wrap,cJSON_GetObjectItem -Wl,--wrap,close -Wl,-wrap,send -Wl,--wrap,cJSON_ParseWithOpts \ - -Wl,--wrap,recv -Wl,--wrap,setsockopt -Wl,--wrap,fcntl -Wl,--wrap,connect -Wl,--wrap,socket \ - -Wl,--wrap,w_request_agent_add_clustered -Wl,--wrap,sleep -Wl,--wrap,cJSON_Delete -Wl,--wrap,local_add \ - -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgetpos -Wl,--wrap,fopen -Wl,--wrap,fread -Wl,--wrap,fseek \ - -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap=fgetc -Wl,--wrap,getpid -Wl,--wrap,wfopen \ - -Wl,--wrap,external_socket_connect ${HASH_OP_WRAPPERS}") -list(APPEND os_auth_names "test_auth") -list(APPEND os_auth_flags "${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,os_random -Wl,--wrap,GetRandomNoise -Wl,--wrap,getuname -Wl,--wrap,time -Wl,--wrap,wfopen") -list(APPEND os_auth_names "test_generate_cert") -list (APPEND os_auth_flags "-Wl,--wrap,PEM_write_PrivateKey -Wl,--wrap,PEM_write_X509 -Wl,--wrap,RSA_generate_key_ex \ - -Wl,--wrap,X509_sign -Wl,--wrap,_merror -Wl,--wrap,wfopen \ - -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgetpos -Wl,--wrap,fread \ - -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fgetc -Wl,--wrap,fgets \ - -Wl,--wrap,RSA_new -Wl,--wrap,EVP_PKEY_new -Wl,--wrap,X509_new -Wl,--wrap,popen") -list(APPEND os_auth_names "test_authd-config") -list(APPEND os_auth_flags "${DEBUG_OP_WRAPPERS}") - -list(LENGTH os_auth_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET os_auth_names ${counter} os_auth_test_name) - list(GET os_auth_flags ${counter} os_auth_test_flags) - - add_executable(${os_auth_test_name} ${os_auth_test_name}.c) - - target_link_libraries( - ${os_auth_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - OS_AUTH_O - ${TEST_DEPS} - ) - - if(NOT os_auth_test_flags STREQUAL " ") - target_link_libraries( - ${os_auth_test_name} - ${os_auth_test_flags} - ) - endif() - add_test(NAME ${os_auth_test_name} COMMAND ${os_auth_test_name}) -endforeach() diff --git a/src/unit_tests/os_auth/test_auth.c b/src/unit_tests/os_auth/test_auth.c deleted file mode 100644 index 352531b04a5..00000000000 --- a/src/unit_tests/os_auth/test_auth.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "os_err.h" -#include "shared.h" -#include "../../os_auth/auth.h" -#include "../../headers/sec.h" -#include "../../addagent/manage_agents.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_auth/os_auth_wrappers.h" -#include "../wrappers/wazuh/shared/randombytes_wrappers.h" - -/* tests */ - -static void test_w_generate_random_pass_success(void **state) { - char* result = NULL; - - will_return(__wrap_os_random, 146557); - will_return(__wrap_os_random, 314159); - will_return(__wrap_GetRandomNoise, strdup("Wazuh")); - will_return(__wrap_GetRandomNoise, strdup("The Open Source Security Platform")); - will_return(__wrap_time, 1655254875); - will_return_always(__wrap_getuname, "Linux |ubuntu-focal |5.4.0-92-generic |#103-Ubuntu SMP Fri Nov 26 16:13:00 UTC 2021 " - "|x86_64 [Ubuntu|ubuntu: 20.04.2 LTS (Focal Fossa)] - Wazuh v4.3.4"); - - result = w_generate_random_pass(); - - assert_string_equal(result, "6e0d9a4188ac9de8fa695bd96e276090"); - os_free(result); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_w_generate_random_pass_success), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_auth/test_auth_add.c b/src/unit_tests/os_auth/test_auth_add.c deleted file mode 100644 index f078910ec09..00000000000 --- a/src/unit_tests/os_auth/test_auth_add.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../os_auth/auth.h" -#include "../../addagent/manage_agents.h" -#include "../../headers/sec.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -void keys_init(keystore *keys, key_mode_t key_mode, int save_removed) { - /* Initialize hashes */ - keys->keytree_id = rbtree_init(); - keys->keytree_ip = rbtree_init(); - keys->keytree_sock = rbtree_init(); - - if (!(keys->keytree_id && keys->keytree_ip && keys->keytree_sock)) { - merror_exit(MEM_ERROR, errno, strerror(errno)); - } - - /* Initialize structure */ - os_calloc(1, sizeof(keyentry*), keys->keyentries); - keys->keysize = 0; - keys->id_counter = 0; - keys->flags.key_mode = key_mode; - keys->flags.save_removed = save_removed; - - /* Add additional entry for sender == keysize */ - os_calloc(1, sizeof(keyentry), keys->keyentries[keys->keysize]); - w_mutex_init(&keys->keyentries[keys->keysize]->mutex, NULL); -} - -//Params used on enrollment -typedef struct _enrollment_param { - char* ip; - char* name; - char* groups; -} enrollment_param; - -//Error responses -typedef struct _enrollment_response { - w_err_t err; - char* response; -} enrollment_response; - - -extern struct keynode *queue_insert; -extern struct keynode *queue_remove; -extern struct keynode * volatile *insert_tail; -extern struct keynode * volatile *remove_tail; - -char* new_id = NULL; -char* new_key = NULL; - -/* setup/teardowns */ -static int setup_group(void **state) { - keys_init(&keys, 0, !config.flags.clear_removed); - - /* Initialize queues */ - insert_tail = &queue_insert; - remove_tail = &queue_remove; - - return 0; -} - -static int teardown_group(void **state) { - OS_FreeKeys(&keys); - - return 0; -} - -static int teardown_add_agent(void **state) { - os_free(new_id); - os_free(new_key); - - return 0; -} - - -/* tests */ - -static void test_w_auth_add_agent(void **state) { - char response[2048] = {0}; - w_err_t err; - - expect_any(__wrap_OS_IsValidIP, ip_address); - expect_any(__wrap_OS_IsValidIP, final_ip); - will_return(__wrap_OS_IsValidIP, -1); - - /* Successful new agent */ - err = w_auth_add_agent(response, "192.0.0.0", "agent1", &new_id, &new_key); - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(response, ""); - assert_non_null(new_id); - assert_non_null(new_key); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_teardown(test_w_auth_add_agent, teardown_add_agent), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/os_auth/test_auth_key_request.c b/src/unit_tests/os_auth/test_auth_key_request.c deleted file mode 100644 index c6b117664dc..00000000000 --- a/src/unit_tests/os_auth/test_auth_key_request.c +++ /dev/null @@ -1,958 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../os_auth/auth.h" -#include "../../os_auth/key_request.h" -#include "../../addagent/manage_agents.h" -#include "../../headers/sec.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/exec_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/linux/socket_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/wazuh/os_auth/os_auth_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" - -#define BUFFERSIZE 1024 -#define QUEUE_SIZE 5 - -volatile int running = 1; - -// Additional authd_sigblock definition to avoid including main-server.o - -void authd_sigblock() { - sigset_t sigset; - sigemptyset(&sigset); - sigaddset(&sigset, SIGTERM); - sigaddset(&sigset, SIGHUP); - sigaddset(&sigset, SIGINT); - pthread_sigmask(SIG_BLOCK, &sigset, NULL); -} - -// setup/teardowns - -static int test_setup(void **state) { - authd_key_request_t *init_data = NULL; - os_calloc(1, sizeof(authd_key_request_t), init_data); - - init_data->timeout = 1; - init_data->threads = 1; - init_data->queue_size = BUFFERSIZE; - - config.key_request.timeout = 1; - config.key_request.socket = "/tmp/tmp_file_XXXXX"; - - os_strdup("/tmp/tmp_file-XXXXXX", init_data->socket); - - test_mode = 1; - *state = init_data; - - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - authd_key_request_t *data = (authd_key_request_t *)*state; - unlink(data->socket); - os_free(data->socket); - os_free(data); - - config.key_request.timeout = 0; - config.key_request.socket = ""; - - test_mode = 0; - - return OS_SUCCESS; -} - -// Test get_agent_info_from_json() - -void test_get_agent_info_from_json_error_malformed(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - char *error_msg = NULL; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Malformed JSON output received. No 'error' field found."); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_null(ret); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_message_malformed(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - char *error_msg = NULL; - - field->valueint = 1; - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Malformed JSON output received. No 'message' field found."); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_null(ret); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_error_valuestring(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - cJSON *message = cJSON_CreateNumber(2); - char *error_msg = NULL; - - field->valueint = 1; - message->valuestring = strdup("test"); - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, message); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_string_equal(message->valuestring, error_msg); - assert_null(ret); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(message); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_agent_data_not_found(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - char *error_msg = NULL; - - field->valueint = 0; - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent data not found."); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_null(ret); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_agent_id_not_found(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(2); - char *error_msg = NULL; - - field->valueint = 0; - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent ID not found."); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_null(ret); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_agent_name_not_found(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(2); - cJSON *id = cJSON_CreateNumber(3); - char *error_msg = NULL; - - field->valueint = 0; - id->valuestring = strdup("001"); - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent name not found."); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_null(ret); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_agent_ip_not_found(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(2); - cJSON *id = cJSON_CreateNumber(3); - cJSON *name = cJSON_CreateNumber(4); - char *error_msg = NULL; - - field->valueint = 0; - id->valuestring = strdup("001"); - name->valuestring = strdup("test"); - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, name); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent address not found."); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_null(ret); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(name); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_agent_key_not_found(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(1); - cJSON *id = cJSON_CreateNumber(1); - cJSON *name = cJSON_CreateNumber(1); - cJSON *ip = cJSON_CreateNumber(1); - char *error_msg = NULL; - - field->valueint = 0; - id->valuestring = strdup("001"); - name->valuestring = strdup("test"); - ip->valuestring = strdup("127.0.0.1"); - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, name); - will_return(__wrap_cJSON_GetObjectItem, ip); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent key not found."); - - void *ret = get_agent_info_from_json(input_raw_json, &error_msg); - assert_null(ret); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(name); - __real_cJSON_Delete(ip); - __real_cJSON_Delete(input_raw_json); -} - -void test_get_agent_info_from_json_agent_success(void **state) { - cJSON *input_raw_json = cJSON_CreateObject(); - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(1); - cJSON *id = cJSON_CreateNumber(1); - cJSON *name = cJSON_CreateNumber(1); - cJSON *ip = cJSON_CreateNumber(1); - cJSON *key = cJSON_CreateNumber(1); - char *error_msg = NULL; - - field->valueint = 0; - id->valuestring = strdup("001"); - name->valuestring = strdup("test"); - ip->valuestring = strdup("127.0.0.1"); - key->valuestring = strdup("key"); - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, name); - will_return(__wrap_cJSON_GetObjectItem, ip); - will_return(__wrap_cJSON_GetObjectItem, key); - - key_request_agent_info *ret = get_agent_info_from_json(input_raw_json, &error_msg); - - assert_string_equal(ret->id, id->valuestring); - assert_string_equal(ret->name, name->valuestring); - assert_string_equal(ret->ip, ip->valuestring); - assert_string_equal(ret->key, key->valuestring); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(name); - __real_cJSON_Delete(ip); - __real_cJSON_Delete(key); - __real_cJSON_Delete(input_raw_json); - - key_request_agent_info_destroy(ret); -} - -// Test key_request_socket_output() - -void test_key_request_socket_output_not_connect(void **state) { - char debug_msg[128]; - char warn_msg[128]; - - will_return(__wrap_external_socket_connect, -1); - snprintf(debug_msg, OS_SIZE_128, "Could not connect to external socket: %s (%d)", strerror(errno), errno); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg); - expect_value(__wrap_sleep, seconds, 1); - - will_return(__wrap_external_socket_connect, -1); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg); - expect_value(__wrap_sleep, seconds, 2); - - will_return(__wrap_external_socket_connect, -1); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg); - expect_value(__wrap_sleep, seconds, 3); - - snprintf(warn_msg, OS_SIZE_128, "Could not connect to external integration: %s (%d). Discarding request.", strerror(errno), errno); - expect_string(__wrap__mwarn, formatted_msg, warn_msg); - - char *ret = key_request_socket_output(K_TYPE_ID, "001"); - assert_null(ret); -} - -void test_key_request_socket_output_long_request(void **state) { - char buffer_request[127]; - - memset(buffer_request, 'a', 126); - buffer_request[126] = '\0'; - - will_return(__wrap_external_socket_connect, 4); - expect_string(__wrap__mdebug1, formatted_msg, "Request is too long for socket."); - - char *ret = key_request_socket_output(K_TYPE_ID, buffer_request); - assert_null(ret); -} - -void test_key_request_socket_output_send_fail(void **state) { - will_return(__wrap_external_socket_connect, 4); - will_return(__wrap_send, -1); - - char *ret = key_request_socket_output(K_TYPE_ID, NULL); - assert_null(ret); -} - -void test_key_request_socket_output_no_data_received(void **state) { - will_return(__wrap_external_socket_connect, 4); - - will_return(__wrap_send, 0); - will_return(__wrap_recv, -1); - expect_string(__wrap__mdebug1, formatted_msg, "No data received from external socket."); - - char *ret = key_request_socket_output(K_TYPE_ID, NULL); - assert_null(ret); -} - -void test_key_request_socket_output_empty_string_received(void **state) { - will_return(__wrap_external_socket_connect, 4); - - will_return(__wrap_send, 0); - will_return(__wrap_recv, 0); - - char *ret = key_request_socket_output(K_TYPE_ID, NULL); - assert_null(ret); -} - -void test_key_request_socket_output_success(void **state) { - will_return(__wrap_external_socket_connect, 4); - - will_return(__wrap_send, 0); - will_return(__wrap_recv, 12); - - char *ret = key_request_socket_output(K_TYPE_ID, NULL); - assert_string_equal(ret, "Hello World!"); - os_free(ret); -} - -// Test key_request_dispatch() - -void test_key_request_dispatch_long_id(void **state) { - char *buffer = "id:000000001"; - - expect_string(__wrap__mdebug1, formatted_msg, "Agent ID is too long."); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, -1); -} - - -void test_key_request_dispatch_long_ip(void **state) { - char *buffer = "ip:00000000000000000000"; - - expect_string(__wrap__mdebug1, formatted_msg, "Agent IP is too long."); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, -1); -} - -void test_key_request_dispatch_invalid_request(void **state) { - char *buffer = "bad:000000001"; - - expect_string(__wrap__merror, formatted_msg, "Invalid request 'bad:000000001' received in Agent key request."); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, -1); -} - -void test_key_request_dispatch_bad_socket_output(void **state) { - authd_key_request_t *data = (authd_key_request_t *)*state; - char *buffer = "id:001"; - cJSON *error = cJSON_CreateNumber(1); - - data->exec_path = NULL; - - will_return(__wrap_external_socket_connect, 4); - will_return(__wrap_send, -1); - - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, -1); - - __real_cJSON_Delete(error); -} - -void test_key_request_dispatch_error_parsing_json(void **state) { - char *buffer = "id:001"; - - will_return(__wrap_external_socket_connect, 4); - will_return(__wrap_send, 0); - will_return(__wrap_recv, 12); - expect_string(__wrap__mdebug2, formatted_msg, "Socket output: Hello World!"); - - will_return(__wrap_cJSON_ParseWithOpts, NULL); - will_return(__wrap_cJSON_ParseWithOpts, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error parsing JSON event ()"); - - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, 0); -} - -void test_key_request_dispatch_error_parsing_agent_json(void **state) { - authd_key_request_t *data = (authd_key_request_t *)*state; - char *buffer = "id:001"; - cJSON *field = cJSON_CreateNumber(1); - cJSON *msg = cJSON_CreateNumber(2); - - field->valueint = 1; - msg->valuestring = strdup("Test"); - - will_return(__wrap_external_socket_connect, 4); - will_return(__wrap_send, 0); - will_return(__wrap_recv, 12); - expect_string(__wrap__mdebug2, formatted_msg, "Socket output: Hello World!"); - - will_return(__wrap_cJSON_ParseWithOpts, NULL); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *)1); - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, msg); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not get a key from ID 001. Error: 'Test'"); - expect_function_call(__wrap_cJSON_Delete); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, -1); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(msg); -} - -void test_key_request_dispatch_exec_output_error(void **state) { - char *buffer = "id:001"; - - config.key_request.socket = 0; - config.key_request.exec_path = "python3 /tmp/test.py"; - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 001"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 1); - - expect_string(__wrap__mwarn, formatted_msg, "Timeout received while running key request integration (python3 /tmp/test.py)"); - - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, -1); -} - -void test_key_request_dispatch_success(void **state) { - authd_key_request_t *data_state = (authd_key_request_t *)*state; - char *buffer = "id:001"; - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(2); - cJSON *id = cJSON_CreateNumber(3); - cJSON *name = cJSON_CreateNumber(4); - cJSON *ip = cJSON_CreateNumber(5); - cJSON *key = cJSON_CreateNumber(6); - - config.worker_node = 1; - - will_return(__wrap_external_socket_connect, 4); - will_return(__wrap_send, 0); - will_return(__wrap_recv, 12); - expect_string(__wrap__mdebug2, formatted_msg, "Socket output: Hello World!"); - - field->valueint = 0; - id->valuestring = strdup("001"); - name->valuestring = strdup("test"); - ip->valuestring = strdup("127.0.0.1"); - key->valuestring = strdup("key"); - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, name); - will_return(__wrap_cJSON_GetObjectItem, ip); - will_return(__wrap_cJSON_GetObjectItem, key); - - will_return(__wrap_cJSON_ParseWithOpts, NULL); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *)1); - - expect_string(__wrap__mdebug1, formatted_msg, "Forwarding agent key request response to the master node for agent '001'"); - will_return(__wrap_w_request_agent_add_clustered, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent key request response forwarded to the master node for agent '001'"); - expect_function_call(__wrap_cJSON_Delete); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, 0); - - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(name); - __real_cJSON_Delete(ip); - __real_cJSON_Delete(key); - config.worker_node = 0; -} - -void test_key_request_dispatch_success_add_agent(void **state) { - char *buffer = "id:001"; - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(2); - cJSON *id = cJSON_CreateNumber(3); - cJSON *name = cJSON_CreateNumber(4); - cJSON *ip = cJSON_CreateNumber(5); - cJSON *key = cJSON_CreateNumber(6); - - config.worker_node = 0; - field->valueint = 0; - id->valuestring = strdup("001"); - name->valuestring = strdup("test"); - ip->valuestring = strdup("127.0.0.1"); - key->valuestring = strdup("key"); - - will_return(__wrap_external_socket_connect, 4); - will_return(__wrap_send, 0); - will_return(__wrap_recv, 12); - expect_string(__wrap__mdebug2, formatted_msg, "Socket output: Hello World!"); - - will_return(__wrap_cJSON_ParseWithOpts, NULL); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *)1); - - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, name); - will_return(__wrap_cJSON_GetObjectItem, ip); - will_return(__wrap_cJSON_GetObjectItem, key); - - expect_string(__wrap__mdebug1, formatted_msg, "Requesting local addition for agent '001' from the agent key request."); - - cJSON * response = NULL; - cJSON * data_json = NULL; - response = cJSON_CreateObject(); - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddItemToObject(response, "data", data_json = cJSON_CreateObject()); - cJSON_AddStringToObject(data_json, "id", id->valuestring); - cJSON_AddStringToObject(data_json, "name", name->valuestring); - cJSON_AddStringToObject(data_json, "ip", ip->valuestring); - cJSON_AddStringToObject(data_json, "key", key->valuestring); - - expect_string(__wrap_local_add, id, id->valuestring); - expect_string(__wrap_local_add, name, name->valuestring); - expect_string(__wrap_local_add, ip, ip->valuestring); - expect_string(__wrap_local_add, key, key->valuestring); - will_return(__wrap_local_add, response); - expect_string(__wrap__mdebug2, formatted_msg, "Agent key request addition response: '{\"error\":0,\"data\":{\"id\":\"001\",\"name\":\"test\",\"ip\":\"127.0.0.1\",\"key\":\"key\"}}'"); - - expect_function_call(__wrap_cJSON_Delete); - expect_function_call(__wrap_cJSON_Delete); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, 0); - - __real_cJSON_Delete(response); - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(name); - __real_cJSON_Delete(ip); - __real_cJSON_Delete(key); - -} - -void test_key_request_dispatch_success_exec_output(void **state) { - char *buffer = "id:001"; - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(2); - cJSON *id = cJSON_CreateNumber(3); - cJSON *name = cJSON_CreateNumber(4); - cJSON *ip = cJSON_CreateNumber(5); - cJSON *key = cJSON_CreateNumber(6); - - config.worker_node = 0; - field->valueint = 0; - id->valuestring = strdup("001"); - name->valuestring = strdup("test"); - ip->valuestring = strdup("127.0.0.1"); - key->valuestring = strdup("key"); - - config.key_request.socket = 0; - config.key_request.exec_path = "python3 /tmp/test.py"; - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 001"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Exec output: Output command"); - - will_return(__wrap_cJSON_ParseWithOpts, NULL); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *)1); - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, name); - will_return(__wrap_cJSON_GetObjectItem, ip); - will_return(__wrap_cJSON_GetObjectItem, key); - - expect_string(__wrap__mdebug1, formatted_msg, "Requesting local addition for agent '001' from the agent key request."); - - cJSON * response = NULL; - cJSON * data_json = NULL; - response = cJSON_CreateObject(); - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddItemToObject(response, "data", data_json = cJSON_CreateObject()); - cJSON_AddStringToObject(data_json, "id", id->valuestring); - cJSON_AddStringToObject(data_json, "name", name->valuestring); - cJSON_AddStringToObject(data_json, "ip", ip->valuestring); - cJSON_AddStringToObject(data_json, "key", key->valuestring); - - expect_string(__wrap_local_add, id, id->valuestring); - expect_string(__wrap_local_add, name, name->valuestring); - expect_string(__wrap_local_add, ip, ip->valuestring); - expect_string(__wrap_local_add, key, key->valuestring); - will_return(__wrap_local_add, response); - expect_string(__wrap__mdebug2, formatted_msg, "Agent key request addition response: '{\"error\":0,\"data\":{\"id\":\"001\",\"name\":\"test\",\"ip\":\"127.0.0.1\",\"key\":\"key\"}}'"); - - expect_function_call(__wrap_cJSON_Delete); - expect_function_call(__wrap_cJSON_Delete); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, 0); - - __real_cJSON_Delete(response); - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(name); - __real_cJSON_Delete(ip); - __real_cJSON_Delete(key); - -} - -void test_key_request_dispatch_error_socket_success_exec_output(void **state) { - char *buffer = "id:001"; - cJSON *field = cJSON_CreateNumber(1); - cJSON *data = cJSON_CreateNumber(2); - cJSON *id = cJSON_CreateNumber(3); - cJSON *name = cJSON_CreateNumber(4); - cJSON *ip = cJSON_CreateNumber(5); - cJSON *key = cJSON_CreateNumber(6); - - config.worker_node = 0; - field->valueint = 0; - id->valuestring = strdup("001"); - name->valuestring = strdup("test"); - ip->valuestring = strdup("127.0.0.1"); - key->valuestring = strdup("key"); - - config.key_request.exec_path = "python3 /tmp/test.py"; - - will_return(__wrap_external_socket_connect, 4); - will_return(__wrap_send, 0); - will_return(__wrap_recv, 0); - expect_string(__wrap__minfo, formatted_msg, "Socket connect fail. Trying to run 'exec_path'"); - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 001"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Exec output: Output command"); - - will_return(__wrap_cJSON_ParseWithOpts, NULL); - will_return(__wrap_cJSON_ParseWithOpts, (cJSON *)1); - will_return(__wrap_cJSON_GetObjectItem, field); - will_return(__wrap_cJSON_GetObjectItem, data); - will_return(__wrap_cJSON_GetObjectItem, id); - will_return(__wrap_cJSON_GetObjectItem, name); - will_return(__wrap_cJSON_GetObjectItem, ip); - will_return(__wrap_cJSON_GetObjectItem, key); - - expect_string(__wrap__mdebug1, formatted_msg, "Requesting local addition for agent '001' from the agent key request."); - - cJSON * response = NULL; - cJSON * data_json = NULL; - response = cJSON_CreateObject(); - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddItemToObject(response, "data", data_json = cJSON_CreateObject()); - cJSON_AddStringToObject(data_json, "id", id->valuestring); - cJSON_AddStringToObject(data_json, "name", name->valuestring); - cJSON_AddStringToObject(data_json, "ip", ip->valuestring); - cJSON_AddStringToObject(data_json, "key", key->valuestring); - - expect_string(__wrap_local_add, id, id->valuestring); - expect_string(__wrap_local_add, name, name->valuestring); - expect_string(__wrap_local_add, ip, ip->valuestring); - expect_string(__wrap_local_add, key, key->valuestring); - will_return(__wrap_local_add, response); - expect_string(__wrap__mdebug2, formatted_msg, "Agent key request addition response: '{\"error\":0,\"data\":{\"id\":\"001\",\"name\":\"test\",\"ip\":\"127.0.0.1\",\"key\":\"key\"}}'"); - - expect_function_call(__wrap_cJSON_Delete); - expect_function_call(__wrap_cJSON_Delete); - expect_value(__wrap_OSHash_Delete_ex, self, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, buffer); - will_return(__wrap_OSHash_Delete_ex, 0); - - int ret = key_request_dispatch(buffer); - assert_int_equal(ret, 0); - - __real_cJSON_Delete(response); - __real_cJSON_Delete(field); - __real_cJSON_Delete(data); - __real_cJSON_Delete(id); - __real_cJSON_Delete(name); - __real_cJSON_Delete(ip); - __real_cJSON_Delete(key); - -} - -// Test key_request_exec_output() - -void test_key_request_exec_output_too_long_request(void **state) { - request_type_t type = K_TYPE_ID; - char *request = "000"; - char exec_path[OS_MAXSTR]; - - memset(exec_path, 'a', OS_MAXSTR); - exec_path[OS_MAXSTR - 1] = '\0'; - config.key_request.exec_path = exec_path; - - expect_string(__wrap__mdebug1, formatted_msg, "Request is too long."); - - char *ret = key_request_exec_output(type,request); - assert_null(ret); -} - -void test_key_request_exec_output_result_code_no_zero(void **state) { - char *exec_path = "python3 /tmp/test.py"; - config.key_request.exec_path = exec_path; - request_type_t type = K_TYPE_ID; - char *request = "000"; - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 000"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, 1); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mwarn, formatted_msg, "Key request integration (python3 /tmp/test.py) returned code 1."); - - char *ret = key_request_exec_output(type,request); - assert_null(ret); -} - -void test_key_request_exec_output_timeout_error(void **state) { - char *exec_path = "python3 /tmp/test.py"; - config.key_request.exec_path = exec_path; - request_type_t type = K_TYPE_ID; - char *request = "000"; - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 000"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 1); - - expect_string(__wrap__mwarn, formatted_msg, "Timeout received while running key request integration (python3 /tmp/test.py)"); - - char *ret = key_request_exec_output(type,request); - assert_null(ret); -} - -void test_key_request_exec_output_path_invalid(void **state) { - char *exec_path = "python3 /tmp/test.py"; - config.key_request.exec_path = exec_path; - request_type_t type = K_TYPE_ID; - char *request = "000"; - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 000"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, EXECVE_ERROR); - will_return(__wrap_wm_exec, -1); - - expect_string(__wrap__mwarn, formatted_msg, "Cannot run key request integration (python3 /tmp/test.py): path is invalid or file has insufficient permissions."); - - char *ret = key_request_exec_output(type,request); - assert_null(ret); -} - -void test_key_request_exec_output_error_executing(void **state) { - char *exec_path = "python3 /tmp/test.py"; - config.key_request.exec_path = exec_path; - request_type_t type = K_TYPE_ID; - char *request = "000"; - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 000"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, -1); - - expect_string(__wrap__mwarn, formatted_msg, "Error executing [python3 /tmp/test.py]"); - - char *ret = key_request_exec_output(type,request); - assert_null(ret); -} - -void test_key_request_exec_output_success(void **state) { - char *exec_path = "python3 /tmp/test.py"; - config.key_request.exec_path = exec_path; - request_type_t type = K_TYPE_ID; - char *request = "000"; - - expect_string(__wrap_wm_exec, command, "python3 /tmp/test.py id 000"); - expect_value(__wrap_wm_exec, secs, 1); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Output command"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - char *ret = key_request_exec_output(type,request); - assert_string_equal(ret, "Output command"); - os_free(ret); -} - -// main - -int main(void) { - struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_error_malformed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_message_malformed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_error_valuestring, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_agent_data_not_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_agent_id_not_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_agent_name_not_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_agent_ip_not_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_agent_key_not_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_get_agent_info_from_json_agent_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_socket_output_not_connect, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_socket_output_long_request, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_socket_output_send_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_socket_output_no_data_received, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_socket_output_empty_string_received, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_socket_output_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_long_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_long_ip, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_invalid_request, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_bad_socket_output, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_error_parsing_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_error_parsing_agent_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_exec_output_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_success_add_agent, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_success_exec_output, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_dispatch_error_socket_success_exec_output, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_exec_output_too_long_request, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_exec_output_result_code_no_zero, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_exec_output_timeout_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_exec_output_path_invalid, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_exec_output_error_executing, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_key_request_exec_output_success, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_auth/test_auth_parse.c b/src/unit_tests/os_auth/test_auth_parse.c deleted file mode 100644 index 9d08f4c02a8..00000000000 --- a/src/unit_tests/os_auth/test_auth_parse.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../os_auth/auth.h" -#include "../../addagent/manage_agents.h" - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -//Expected log messages to be checked on mocked log functions -typedef struct _mocked_log { - char* merror; - char* mwarn; - char* minfo; - char* mdebug; -} mocked_log; - -//Sets all the expected log messages -void set_expected_log (mocked_log* log) { - if (log->merror) { - expect_string(__wrap__merror, formatted_msg, log->merror); - } - if (log->mwarn) { - expect_string(__wrap__mwarn, formatted_msg, log->mwarn); - } - if (log->minfo) { - expect_string(__wrap__minfo, formatted_msg, log->minfo); - } - if (log->mdebug) { - expect_string(__wrap__mdebug1, formatted_msg, log->mdebug); - } -} - -//Params used on enrollment -typedef struct _enrollment_param { - char* ip; - char* name; - char* groups; - char* key; -} enrollment_param; - -//Error responses -typedef struct _enrollment_response { - w_err_t err; - char* response; -} enrollment_response; - -//parser arguments -typedef struct _parse_evaluator { - char* buffer; - char* src_ip; - char* pass; - enrollment_param expected_params; - enrollment_response expected_response; - mocked_log expected_log; -} parse_evaluator; - -parse_evaluator parse_values_default_cfg [] = { - { "OSSEC A:'agent1'", "192.0.0.1", NULL, {"192.0.0.1", "agent1", NULL, NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent1) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent2' G:'Group1'", "192.0.0.1", NULL, {"192.0.0.1", "agent2", "Group1", NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent2) from: 192.0.0.1", "Group(s) is: Group1"} }, - { "OSSEC A:'agent3' G:'Group1,Group2'", "192.0.0.1", NULL, {"192.0.0.1", "agent3", "Group1,Group2", NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent3) from: 192.0.0.1", "Group(s) is: Group1,Group2"} }, - { "OSSEC A:'agent4' G:'Group1,Group2,Group1'", "192.0.0.1", NULL, {"192.0.0.1", "agent4", "Group1,Group2", NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent4) from: 192.0.0.1", "Group(s) is: Group1,Group2"} }, - { "OSSEC PASS: pass123 OSSEC A:'agent5'", "192.0.0.1", "pass123", {"192.0.0.1", "agent5", NULL, NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent5) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent6' IP:'192.0.0.2'", "192.0.0.1", NULL, {"192.0.0.2", "agent6", NULL, NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent6) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent7' K:'07f05add1049244e7e71ad0f54f24d8094cd8f8b'", "192.0.0.1", NULL, {"192.0.0.1", "agent7", NULL, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent7) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent8' IP:'192.0.0.3' K:'ABC123'", "192.0.0.1", NULL, {"192.0.0.3", "agent8", NULL, "ABC123"}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent8) from: 192.0.0.1", NULL} }, - { "OSSEC PASS: pass123 OSSEC A:'agent9' IP:'192.0.0.3' K:'ABC123'", "192.0.0.1", "pass123", {"192.0.0.3", "agent9", NULL, "ABC123"}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent9) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent10' G:'Group1,Group2' IP:'192.0.0.3' K:'ABC123'", "192.0.0.1", NULL, {"192.0.0.3", "agent10", "Group1,Group2", "ABC123"}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent10) from: 192.0.0.1", "Group(s) is: Group1,Group2"} }, - { "OSSEC A:'agent11' V:'v4.5.0'", "192.0.0.1", NULL, {"192.0.0.1", "agent11", NULL, NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent11) from: 192.0.0.1", NULL} }, - - { "OSSEC A:'agent0'", "192.0.0.1", "pass123", {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Invalid password"}, {"Invalid password provided by 192.0.0.1. Closing connection.", NULL, NULL, NULL} }, - { "OSSEC PASS: pass124 OSSEC A:'agent0'", "192.0.0.1", "pass123", {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Invalid password"}, {"Invalid password provided by 192.0.0.1. Closing connection.", NULL, NULL, NULL} }, - { "OSSEC PASS: pass124 OSSEC A:'agent0'", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Invalid request for new agent"}, {"Invalid request for new agent from: 192.0.0.1", NULL, NULL, NULL} }, - { "OSSEC A:''", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Invalid agent name: "}, {"Invalid agent name: from 192.0.0.1", NULL, "Received request for a new agent () from: 192.0.0.1", NULL} }, - { "OSSEC A:'inv;agent'", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Invalid agent name: inv;agent"}, {"Invalid agent name: inv;agent from 192.0.0.1", NULL, "Received request for a new agent (inv;agent) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent3' G:'Group1,Group2", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Unterminated group field"}, {"Unterminated group field", NULL, "Received request for a new agent (agent3) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent3' G:'Group1,Group2' IP:'192.0.0.3 K:'ABC123'", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Unterminated IP field"}, {"Unterminated IP field", NULL, "Received request for a new agent (agent3) from: 192.0.0.1", "Group(s) is: Group1,Group2"} }, - { "OSSEC A:'agent3' G:'Group1,Group2' IP:'192.0.0.3' K:'ABC123", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Unterminated key field"}, {"Unterminated key field", NULL, "Received request for a new agent (agent3) from: 192.0.0.1", "Group(s) is: Group1,Group2"} }, - { "OSSEC A:'agent3' V:'v4.5.0", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Unterminated version field"}, {"Unterminated version field", NULL, "Received request for a new agent (agent3) from: 192.0.0.1", NULL} }, - { "OSSEC A:'agent4' V:'v4.6.0'", "192.0.0.1", NULL, {NULL, NULL, NULL, NULL}, {OS_INVALID,"ERROR: Agent version must be lower or equal to manager version"}, {"Incompatible version for new agent from: 192.0.0.1", NULL, "Received request for a new agent (agent4) from: 192.0.0.1", NULL} }, - - {0} -}; - -parse_evaluator parse_values_without_use_src_ip_cfg [] = { - {"OSSEC A:'agent1'", "192.0.0.1", NULL, {"any", "agent1", NULL, NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent1) from: 192.0.0.1", NULL} }, - {"OSSEC A:'agent2' IP:'192.0.0.2'", "192.0.0.1", NULL, {"192.0.0.2", "agent2", NULL, NULL}, {OS_SUCCESS,""}, {NULL, NULL, "Received request for a new agent (agent2) from: 192.0.0.1", NULL} }, - - {0} -}; - -parse_evaluator* parse_values = NULL; - -/* setup/teardowns */ -int setup_parse_default(void **state) { - config.flags.use_source_ip = 1; - parse_values = parse_values_default_cfg; - return 0; -} - -int setup_parse_use_src_ip_cfg_0(void **state) { - config.flags.use_source_ip = 0; - parse_values = parse_values_without_use_src_ip_cfg; - return 0; -} - -/* tests */ -extern w_err_t w_auth_parse_data(const char* buf, - char *response, - const char *authpass, - char *ip, - char **agentname, - char **groups, - char **key_hash); - -static void test_w_auth_parse_data(void **state) { - char response[2048] = {0}; - char ip[IPSIZE + 1]; - char *agentname = NULL; - char *groups = NULL; - char *key_hash = NULL; - w_err_t err; - - unsigned int max = config.flags.use_source_ip == 1 ? 5 : 1; - for (unsigned int a = 0; a < max; a++) { - expect_any(__wrap_OS_IsValidIP, ip_address); - expect_any(__wrap_OS_IsValidIP, final_ip); - will_return(__wrap_OS_IsValidIP, -2); - } - - for (unsigned i=0; parse_values[i].buffer; i++) { - set_expected_log(&parse_values[i].expected_log); - response[0] = '\0'; - strncpy(ip, parse_values[i].src_ip, IPSIZE); - err = w_auth_parse_data(parse_values[i].buffer, response, parse_values[i].pass, ip, &agentname, &groups, &key_hash); - - assert_int_equal(err, parse_values[i].expected_response.err); - if (err == OS_SUCCESS) { - assert_string_equal(ip, parse_values[i].expected_params.ip); - assert_string_equal(agentname, parse_values[i].expected_params.name); - if (groups) { - assert_string_equal(groups, parse_values[i].expected_params.groups); - } else { - assert_null(parse_values[i].expected_params.groups); - } - if (key_hash) { - assert_string_equal(key_hash, parse_values[i].expected_params.key); - } else { - assert_null(parse_values[i].expected_params.key); - } - } else { - assert_string_equal(response, parse_values[i].expected_response.response); - } - - os_free(agentname); - os_free(groups); - os_free(key_hash); - } -} - -int main(void) { - const struct CMUnitTest tests[] = { - /* w_auth_parse_data tests*/ - cmocka_unit_test_setup(test_w_auth_parse_data, setup_parse_default), - cmocka_unit_test_setup(test_w_auth_parse_data, setup_parse_use_src_ip_cfg_0), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_auth/test_auth_validate.c b/src/unit_tests/os_auth/test_auth_validate.c deleted file mode 100644 index d27d91c4460..00000000000 --- a/src/unit_tests/os_auth/test_auth_validate.c +++ /dev/null @@ -1,535 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "os_err.h" -#include "shared.h" -#include "../../os_auth/auth.h" -#include "../../headers/sec.h" -#include "../../addagent/manage_agents.h" - -#include "../wrappers/posix/dirent_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_auth/os_auth_wrappers.h" - -#define EXISTENT_AGENT1 "ExistentAgent1" -#define EXISTENT_AGENT2 "ExistentAgent2" -#define EXISTENT_AGENT3 "ExistentAgent3" -#define NEW_AGENT1 "Agent1" -#define NEW_AGENT2 "Agent2" -#define EXISTENT_IP1 "192.0.0.255" -#define EXISTENT_IP2 "192.0.0.254" -#define NEW_IP1 "192.0.0.0" -#define NEW_IP2 "192.0.0.1" -#define ANY_IP "any" -#define EXISTENT_GROUP1 "ExistentGroup1" -#define EXISTENT_GROUP2 "ExistentGroup2" -#define UNKNOWN_GROUP "UnknownGroup" -#define AGENT1_ID "001" - -double __wrap_difftime (time_t __time1, time_t __time0) { - return mock(); -} - -void keys_init(keystore *keys, key_mode_t key_mode, int save_removed) { - /* Initialize hashes */ - keys->keytree_id = rbtree_init(); - keys->keytree_ip = rbtree_init(); - keys->keytree_sock = rbtree_init(); - - if (!(keys->keytree_id && keys->keytree_ip && keys->keytree_sock)) { - merror_exit(MEM_ERROR, errno, strerror(errno)); - } - - /* Initialize structure */ - os_calloc(1, sizeof(keyentry*), keys->keyentries); - keys->keysize = 0; - keys->id_counter = 0; - keys->flags.key_mode = key_mode; - keys->flags.save_removed = save_removed; - - /* Add additional entry for sender == keysize */ - os_calloc(1, sizeof(keyentry), keys->keyentries[keys->keysize]); - w_mutex_init(&keys->keyentries[keys->keysize]->mutex, NULL); -} - -void keyentry_init (keyentry *key, char *name, char *id, char *ip, char *raw_key) { - os_calloc(1, sizeof(os_ip), key->ip); - key->ip->ip = ip ? strdup(ip) : NULL; - key->name = name ? strdup(name) : NULL; - key->id = id ? strdup(id) : NULL; - key->raw_key = raw_key ? strdup(raw_key) : NULL; -} - -void free_keyentry (keyentry *key) { - os_free(key->ip->ip); - os_free(key->ip); - os_free(key->name); - os_free(key->id); - os_free(key->raw_key); -} - -//Params used on enrollment -typedef struct _enrollment_param { - char* ip; - char* name; - char* groups; -} enrollment_param; - -//Error responses -typedef struct _enrollment_response { - w_err_t err; - char* response; -} enrollment_response; - -extern struct keynode *queue_insert; -extern struct keynode *queue_remove; -extern struct keynode * volatile *insert_tail; -extern struct keynode * volatile *remove_tail; - -/* setup/teardowns */ -static int setup_group(void **state) { - - for (unsigned int a = 0; a < 3; a++) { - expect_any(__wrap_OS_IsValidIP, ip_address); - expect_any(__wrap_OS_IsValidIP, final_ip); - will_return(__wrap_OS_IsValidIP, -1); - } - - keys_init(&keys, 0, !config.flags.clear_removed); - OS_AddNewAgent(&keys, NULL, EXISTENT_AGENT1, EXISTENT_IP1, NULL); - OS_AddNewAgent(&keys, NULL, EXISTENT_AGENT2, EXISTENT_IP2, NULL); - OS_AddNewAgent(&keys, NULL, EXISTENT_AGENT3, ANY_IP, NULL); - - if (gethostname(shost, sizeof(shost) - 1) < 0) { - strncpy(shost, "localhost", sizeof(shost) - 1); - shost[sizeof(shost) - 1] = '\0'; - } - - /* Initialize queues */ - insert_tail = &queue_insert; - remove_tail = &queue_remove; - - return 0; -} - -static int teardown_group(void **state) { - OS_FreeKeys(&keys); - - struct keynode *cur = NULL; - struct keynode *next = NULL; - - for (cur = queue_remove; cur; cur = next) { - next = cur->next; - os_free(cur->id); - os_free(cur->name); - os_free(cur->ip); - os_free(cur); - } - - return 0; -} - -int setup_validate_force_disabled(void **state) { - config.force_options.enabled = 0; - return 0; -} - -int setup_validate_force_enabled(void **state) { - config.force_options.enabled = 1; - return 0; -} - -/* tests */ -static void test_w_auth_validate_data(void **state) { - char response[2048] = {0}; - w_err_t err; - - /* New agent / IP*/ - response[0] = '\0'; - err = w_auth_validate_data(response, NEW_IP1, NEW_AGENT1, NULL, NULL); - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(response, ""); - - /* any IP*/ - response[0] = '\0'; - err = w_auth_validate_data(response, ANY_IP, NEW_AGENT1, NULL, NULL); - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(response, ""); - - /* Existent IP */ - response[0] = '\0'; - expect_string(__wrap__mwarn, formatted_msg, "Duplicate IP '"EXISTENT_IP1"', rejecting enrollment. " - "Agent '001' won't be removed because the force option is disabled."); - err = w_auth_validate_data(response, EXISTENT_IP1, NEW_AGENT1, NULL, NULL); - assert_int_equal(err, OS_INVALID); - assert_string_equal(response, "ERROR: Duplicate IP: "EXISTENT_IP1""); - - /* Existent Agent Name */ - response[0] = '\0'; - expect_string(__wrap__mwarn, formatted_msg, "Duplicate name '"EXISTENT_AGENT1"', rejecting enrollment. " - "Agent '001' won't be removed because the force option is disabled."); - err = w_auth_validate_data(response, NEW_IP1, EXISTENT_AGENT1, NULL, NULL); - assert_int_equal(err, OS_INVALID); - assert_string_equal(response, "ERROR: Duplicate agent name: "EXISTENT_AGENT1""); - - /* Manager name */ - char host_name[512]; - if (gethostname(host_name, sizeof(shost) - 1) < 0) { - strncpy(host_name, "localhost", sizeof(host_name) - 1); - host_name[sizeof(host_name) - 1] = '\0'; - } - char err_response[2048]; - snprintf(err_response, 2048, "ERROR: Invalid agent name: %s", host_name) ; - char merror_message[2048]; - snprintf(merror_message, 2048, "Invalid agent name %s (same as manager)", host_name); - expect_string(__wrap__merror, formatted_msg, merror_message); - err = w_auth_validate_data(response,NEW_IP1, host_name, NULL, NULL); - assert_int_equal(err, OS_INVALID); - assert_string_equal(response, err_response); - - /* Check no agent was deleted*/ - assert_true(keys.keysize == 3); - int index = 0; - index = OS_IsAllowedName(&keys, EXISTENT_AGENT1); - assert_true(index >= 0); - index = OS_IsAllowedName(&keys, EXISTENT_AGENT2); - assert_true(index >= 0); -} - -static void test_w_auth_validate_data_replace_agent(void **state) { - char response[2048] = {0}; - w_err_t err; - char *connection_status = "active"; - time_t date_add = 1632255744; - time_t disconnection_time = 0; - cJSON *j_agent_info_array = NULL; - cJSON *j_agent_info = NULL; - - /* Duplicate IP*/ - j_agent_info_array = cJSON_CreateArray(); - j_agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(j_agent_info, "connection_status", connection_status); - cJSON_AddNumberToObject(j_agent_info, "disconnection_time", disconnection_time); - cJSON_AddNumberToObject(j_agent_info, "date_add", date_add); - cJSON_AddItemToArray(j_agent_info_array, j_agent_info); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info_array); - - response[0] = '\0'; - expect_string(__wrap__minfo, formatted_msg, "Duplicate IP '"EXISTENT_IP1"'. " - "Removing old agent '"EXISTENT_AGENT1"' (id '001')."); - err = w_auth_validate_data(response, EXISTENT_IP1, NEW_AGENT1, NULL, NULL); - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(response, ""); - - /* Duplicate Name*/ - j_agent_info_array = cJSON_CreateArray(); - j_agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(j_agent_info, "connection_status", connection_status); - cJSON_AddNumberToObject(j_agent_info, "disconnection_time", disconnection_time); - cJSON_AddNumberToObject(j_agent_info, "date_add", date_add); - cJSON_AddItemToArray(j_agent_info_array, j_agent_info); - - expect_value(__wrap_wdb_get_agent_info, id, 2); - will_return(__wrap_wdb_get_agent_info, j_agent_info_array); - - response[0] = '\0'; - expect_string(__wrap__minfo, formatted_msg, "Duplicate name. " - "Removing old agent '"EXISTENT_AGENT2"' (id '002')."); - err = w_auth_validate_data(response, NEW_IP2, EXISTENT_AGENT2, NULL, NULL); - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(response, ""); - - /* Check agents were deleted*/ - int index = 0; - index = OS_IsAllowedIP(&keys, EXISTENT_IP1); - assert_true(index < 0); - index = OS_IsAllowedName(&keys, EXISTENT_AGENT2); - assert_true(index < 0); -} - -static void test_w_auth_validate_groups(void **state) { - w_err_t err; - char response[2048] = {0}; - - /* Existent group */ - will_return(__wrap_opendir, 1); - response[0] = '\0'; - err = w_auth_validate_groups(EXISTENT_GROUP1, response); - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(response, ""); - - /* Non existent group*/ - will_return(__wrap_opendir, 0); - expect_string(__wrap__merror, formatted_msg, "Invalid group: "UNKNOWN_GROUP); - response[0] = '\0'; - err = w_auth_validate_groups(UNKNOWN_GROUP, response); - assert_int_equal(err, OS_INVALID); - assert_string_equal(response, "ERROR: Invalid group: "UNKNOWN_GROUP""); - - /* Existent multigroups */ - will_return(__wrap_opendir, 1); - will_return(__wrap_opendir, 1); - response[0] = '\0'; - err = w_auth_validate_groups(EXISTENT_GROUP1","EXISTENT_GROUP2, response); - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(response, ""); - - /* One Non Existent on multigroups */ - will_return(__wrap_opendir, 1); - will_return(__wrap_opendir, 1); - will_return(__wrap_opendir, 0); - expect_string(__wrap__merror, formatted_msg, "Invalid group: "UNKNOWN_GROUP); - response[0] = '\0'; - err = w_auth_validate_groups(EXISTENT_GROUP1","EXISTENT_GROUP2","UNKNOWN_GROUP, response); - assert_int_equal(err, OS_INVALID); - assert_string_equal(response, "ERROR: Invalid group: "UNKNOWN_GROUP""); -} - -static void test_w_auth_replace_agent_force_disabled(void **state) { - w_err_t err; - keyentry key; - keyentry_init(&key, NEW_AGENT1, AGENT1_ID, NEW_IP1, NULL); - char* str_result = NULL; - - err = w_auth_replace_agent(&key, NULL, &config.force_options, &str_result); - - assert_int_equal(err, OS_INVALID); - assert_string_equal(str_result, "Agent '001' won't be removed because the force option is disabled."); - free_keyentry(&key); - os_free(str_result); -} - -static void test_w_auth_replace_agent_agent_info_failed(void **state) { - w_err_t err; - keyentry key; - keyentry_init(&key, NEW_AGENT1, AGENT1_ID, NEW_IP1, NULL); - char* str_result = NULL; - - config.force_options.enabled = 1; - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, NULL); - - err = w_auth_replace_agent(&key, NULL, &config.force_options, &str_result); - - config.force_options.enabled = 0; - assert_int_equal(err, OS_INVALID); - assert_string_equal(str_result, "Failed to get agent-info for agent '001'"); - free_keyentry(&key); - os_free(str_result); -} - -static void test_w_auth_replace_agent_not_disconnected(void **state) { - w_err_t err; - keyentry key; - keyentry_init(&key, NEW_AGENT1, AGENT1_ID, NEW_IP1, NULL); - char *connection_status = "active"; - char* str_result = NULL; - time_t date_add = 1632255744; - time_t disconnection_time = 0; - cJSON *j_agent_info_array = NULL; - cJSON *j_agent_info = NULL; - - j_agent_info_array = cJSON_CreateArray(); - j_agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(j_agent_info, "connection_status", connection_status); - cJSON_AddNumberToObject(j_agent_info, "disconnection_time", disconnection_time); - cJSON_AddNumberToObject(j_agent_info, "date_add", date_add); - cJSON_AddItemToArray(j_agent_info_array, j_agent_info); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info_array); - - // time since disconnected - will_return(__wrap_difftime, 10); - - config.force_options.disconnected_time_enabled = true; - config.force_options.disconnected_time = 100; - - err = w_auth_replace_agent(&key, NULL, &config.force_options, &str_result); - - assert_int_equal(err, OS_INVALID); - assert_string_equal(str_result, "Agent '001' can't be replaced since it is not disconnected."); - free_keyentry(&key); - os_free(str_result); -} - -static void test_w_auth_replace_agent_not_disconnected_long_enough(void **state) { - w_err_t err; - keyentry key; - keyentry_init(&key, NEW_AGENT1, AGENT1_ID, NEW_IP1, NULL); - char *connection_status = "disconnected"; - char* str_result = NULL; - time_t date_add = 1632255744; - time_t disconnection_time = 1632258049; - cJSON *j_agent_info_array = NULL; - cJSON *j_agent_info = NULL; - - j_agent_info_array = cJSON_CreateArray(); - j_agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(j_agent_info, "connection_status", connection_status); - cJSON_AddNumberToObject(j_agent_info, "disconnection_time", disconnection_time); - cJSON_AddNumberToObject(j_agent_info, "date_add", date_add); - cJSON_AddItemToArray(j_agent_info_array, j_agent_info); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info_array); - - // time since disconnected - will_return(__wrap_difftime, 10); - - config.force_options.disconnected_time_enabled = true; - config.force_options.disconnected_time = 100; - - err = w_auth_replace_agent(&key, NULL, &config.force_options, &str_result); - - config.force_options.disconnected_time_enabled = false; - config.force_options.disconnected_time = 0; - - assert_int_equal(err, OS_INVALID); - assert_string_equal(str_result, "Agent '001' has not been disconnected long enough to be replaced."); - free_keyentry(&key); - os_free(str_result); -} - -static void test_w_auth_replace_agent_not_old_enough(void **state) { - w_err_t err; - keyentry key; - keyentry_init(&key, NEW_AGENT1, AGENT1_ID, NEW_IP1, NULL); - char *connection_status = "active"; - char* str_result = NULL; - time_t date_add = 1632255744; - time_t disconnection_time = 0; - cJSON *j_agent_info_array = NULL; - cJSON *j_agent_info = NULL; - - j_agent_info_array = cJSON_CreateArray(); - j_agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(j_agent_info, "connection_status", connection_status); - cJSON_AddNumberToObject(j_agent_info, "disconnection_time", disconnection_time); - cJSON_AddNumberToObject(j_agent_info, "date_add", date_add); - cJSON_AddItemToArray(j_agent_info_array, j_agent_info); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info_array); - - config.force_options.disconnected_time_enabled = false; - - // time since registration - will_return(__wrap_difftime, 10); - - config.force_options.after_registration_time = 100; - - err = w_auth_replace_agent(&key, NULL, &config.force_options, &str_result); - - config.force_options.after_registration_time = 0; - - assert_int_equal(err, OS_INVALID); - assert_string_equal(str_result, "Agent '001' doesn't comply with the registration time to be removed."); - free_keyentry(&key); - os_free(str_result); -} - -static void test_w_auth_replace_agent_existent_key_hash(void **state) { - w_err_t err; - keyentry key; - keyentry_init(&key, NEW_AGENT1, AGENT1_ID, NEW_IP1, "1234"); - // This is the SHA1 hash of the string: IdNameKey - char *key_hash = "15153d246b71789195b48778875af94f9378ecf9"; - char *connection_status = "never_connected"; - char* str_result = NULL; - time_t date_add = 1632255744; - time_t disconnection_time = 0; - cJSON *j_agent_info_array = NULL; - cJSON *j_agent_info = NULL; - - j_agent_info_array = cJSON_CreateArray(); - j_agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(j_agent_info, "connection_status", connection_status); - cJSON_AddNumberToObject(j_agent_info, "disconnection_time", disconnection_time); - cJSON_AddNumberToObject(j_agent_info, "date_add", date_add); - cJSON_AddItemToArray(j_agent_info_array, j_agent_info); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info_array); - - config.force_options.disconnected_time_enabled = false; - config.force_options.after_registration_time = 0; - config.force_options.key_mismatch = true; - - err = w_auth_replace_agent(&key, key_hash, &config.force_options, &str_result); - - config.force_options.key_mismatch = false; - - assert_int_equal(err, OS_INVALID); - assert_string_equal(str_result, "Agent '001' key already exists on the manager."); - free_keyentry(&key); - os_free(str_result); -} - -static void test_w_auth_replace_agent_success(void **state) { - w_err_t err; - keyentry key; - keyentry_init(&key, NEW_AGENT1, AGENT1_ID, NEW_IP1, NULL); - char *connection_status = "disconnected"; - char* str_result = NULL; - time_t date_add = 1632255744; - time_t disconnection_time = 1632258049; - cJSON *j_agent_info_array = NULL; - cJSON *j_agent_info = NULL; - - j_agent_info_array = cJSON_CreateArray(); - j_agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(j_agent_info, "connection_status", connection_status); - cJSON_AddNumberToObject(j_agent_info, "disconnection_time", disconnection_time); - cJSON_AddNumberToObject(j_agent_info, "date_add", date_add); - cJSON_AddItemToArray(j_agent_info_array, j_agent_info); - - expect_value(__wrap_wdb_get_agent_info, id, 1); - will_return(__wrap_wdb_get_agent_info, j_agent_info_array); - - will_return(__wrap_difftime, 10); - - config.force_options.disconnected_time_enabled = false; - config.force_options.after_registration_time = 1; - - err = w_auth_replace_agent(&key, NULL, &config.force_options, &str_result); - - config.force_options.after_registration_time = 0; - - assert_int_equal(err, OS_SUCCESS); - assert_string_equal(str_result, "Removing old agent '"NEW_AGENT1"' (id '001')."); - free_keyentry(&key); - os_free(str_result); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_w_auth_validate_groups), - cmocka_unit_test_setup(test_w_auth_validate_data, setup_validate_force_disabled), - cmocka_unit_test_setup(test_w_auth_validate_data_replace_agent, setup_validate_force_enabled), - cmocka_unit_test_setup(test_w_auth_replace_agent_force_disabled, setup_validate_force_disabled), - cmocka_unit_test_setup(test_w_auth_replace_agent_agent_info_failed, setup_validate_force_disabled), - cmocka_unit_test_setup(test_w_auth_replace_agent_not_disconnected_long_enough, setup_validate_force_enabled), - cmocka_unit_test_setup(test_w_auth_replace_agent_not_disconnected, setup_validate_force_enabled), - cmocka_unit_test_setup(test_w_auth_replace_agent_not_old_enough, setup_validate_force_enabled), - cmocka_unit_test_setup(test_w_auth_replace_agent_existent_key_hash, setup_validate_force_enabled), - cmocka_unit_test_setup(test_w_auth_replace_agent_success, setup_validate_force_enabled), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/os_auth/test_authd-config.c b/src/unit_tests/os_auth/test_authd-config.c deleted file mode 100644 index 0f6300de7ae..00000000000 --- a/src/unit_tests/os_auth/test_authd-config.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../os_auth/auth.h" -#include "../../headers/shared.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - - -void w_authd_parse_agents(XML_NODE node, authd_config_t * config); - - -/* setup/teardown */ - - -/* wraps */ - - -/* tests */ - -// Test w_authd_parse_agents - -authd_config_t config = {0}; - -static void test_w_authd_parse_agents_no(void **state) { - config.allow_higher_versions = AUTHD_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("allow_higher_versions", node[0]->element); - os_strdup("no", node[0]->content); - node[1] = NULL; - - w_authd_parse_agents(node, &config); - assert_false(config.allow_higher_versions); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -static void test_w_authd_parse_agents_yes(void **state) { - config.allow_higher_versions = AUTHD_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - - XML_NODE node; - - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("allow_higher_versions", node[0]->element); - os_strdup("yes", node[0]->content); - node[1] = NULL; - - w_authd_parse_agents(node, &config); - assert_true(config.allow_higher_versions); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -static void test_w_authd_parse_agents_invalid_value(void **state) { - config.allow_higher_versions = AUTHD_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - - XML_NODE node; - - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("allow_higher_versions", node[0]->element); - os_strdup("invalid_value", node[0]->content); - node[1] = NULL; - - expect_string(__wrap__mwarn, formatted_msg, - "(9001): Ignored invalid value 'invalid_value' for 'allow_higher_versions'."); - w_authd_parse_agents(node, &config); - assert_int_equal(config.allow_higher_versions, AUTHD_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -static void test_w_authd_parse_agents_invalid_element(void **state) { - config.allow_higher_versions = AUTHD_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - - XML_NODE node; - - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("invalid_element", node[0]->element); // Use an invalid element name - os_strdup("no", node[0]->content); - node[1] = NULL; - - expect_string(__wrap__mwarn, formatted_msg, - "(1230): Invalid element in the configuration: 'invalid_element'."); - w_authd_parse_agents(node, &config); - assert_int_equal(config.allow_higher_versions, AUTHD_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests - cmocka_unit_test(test_w_authd_parse_agents_no), - cmocka_unit_test(test_w_authd_parse_agents_yes), - cmocka_unit_test(test_w_authd_parse_agents_invalid_value), - cmocka_unit_test(test_w_authd_parse_agents_invalid_element), - - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_auth/test_generate_cert.c b/src/unit_tests/os_auth/test_generate_cert.c deleted file mode 100644 index 774abe67f0b..00000000000 --- a/src/unit_tests/os_auth/test_generate_cert.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "generate_cert.h" - -static int setup_group(void **state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - - -static void test_generate_cert_success(void **state) { - FILE key_file = {0}; - FILE cert_file = {0}; - - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 1); - will_return(__wrap_X509_sign, 1); - - expect_string(__wrap_wfopen, path, "key_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, &key_file); - - will_return(__wrap_PEM_write_PrivateKey, 1); - - expect_value(__wrap_fclose, _File, &key_file); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_wfopen, path, "cert_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, &cert_file); - - will_return(__wrap_PEM_write_X509, 1); - expect_value(__wrap_fclose, _File, &cert_file); - - will_return(__wrap_fclose, 0); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - assert_int_equal(ret_value, 0); -} - -static void test_generate_cert_success_typo(void **state) { - FILE key_file = {0}; - FILE cert_file = {0}; - - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 1); - will_return(__wrap_X509_sign, 1); - - expect_string(__wrap_wfopen, mode, "wb"); - expect_string(__wrap_wfopen, path, "key_path"); - will_return(__wrap_wfopen, &key_file); - - will_return(__wrap_PEM_write_PrivateKey, 1); - - expect_value(__wrap_fclose, _File, &key_file); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_wfopen, path, "cert_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, &cert_file); - - will_return(__wrap_PEM_write_X509, 1); - expect_value(__wrap_fclose, _File, &cert_file); - - will_return(__wrap_fclose, 0); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/asdfg/"); - assert_int_equal(ret_value, 0); -} - -static void test_save_key_fail(void **state) { - FILE key_file = {0}; - FILE cert_file = {0}; - - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 1); - will_return(__wrap_X509_sign, 1); - - expect_string(__wrap_wfopen, path, "key_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, &key_file); - - will_return(__wrap_PEM_write_PrivateKey, 0); - expect_string(__wrap__merror, formatted_msg, "Cannot dump private key."); - - expect_value(__wrap_fclose, _File, &key_file); - will_return(__wrap_fclose, 0); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - - assert_int_equal(ret_value, 1); -} - -static void test_save_key_fail_fopen(void **state) { - FILE key_file = {0}; - - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 1); - will_return(__wrap_X509_sign, 1); - - expect_string(__wrap_wfopen, path, "key_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, NULL); - - expect_string(__wrap__merror, formatted_msg, "Cannot open key_path."); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - - assert_int_equal(ret_value, 1); -} - -static void test_save_cert_fail(void **state) { - FILE key_file = {0}; - FILE cert_file = {0}; - - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 1); - will_return(__wrap_X509_sign, 1); - - expect_string(__wrap_wfopen, path, "key_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, &key_file); - - will_return(__wrap_PEM_write_PrivateKey, 1); - - expect_value(__wrap_fclose, _File, &key_file); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_wfopen, path, "cert_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, &cert_file); - - will_return(__wrap_PEM_write_X509, 0); - expect_string(__wrap__merror, formatted_msg, "Cannot dump certificate."); - expect_value(__wrap_fclose, _File, &cert_file); - will_return(__wrap_fclose, 0); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - assert_int_equal(ret_value, 1); -} - -static void test_save_cert_fail_fopen(void **state) { - FILE key_file = {0}; - FILE cert_file = {0}; - - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 1); - will_return(__wrap_X509_sign, 1); - - expect_string(__wrap_wfopen, path, "key_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, &key_file); - - will_return(__wrap_PEM_write_PrivateKey, 1); - - expect_value(__wrap_fclose, _File, &key_file); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_wfopen, path, "cert_path"); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, NULL); - expect_string(__wrap__merror, formatted_msg, "Cannot open cert_path."); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - assert_int_equal(ret_value, 1); -} - -static void test_generate_cert_key_null(void **state) { - will_return(__wrap_EVP_PKEY_new, 0); - will_return(__wrap_EVP_PKEY_new, NULL); - - will_return(__wrap_X509_new, 1); - - expect_string(__wrap__merror, formatted_msg, "Cannot create EVP_PKEY or EVP_PKEY_CTX structure."); - expect_string(__wrap__merror, formatted_msg, "Cannot generate key to sign the certificate."); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - assert_int_equal(ret_value, 1); -} - -static void test_generate_cert_pkey_null(void **state) { - will_return(__wrap_EVP_PKEY_new, 0); - will_return(__wrap_EVP_PKEY_new, NULL); - - will_return(__wrap_X509_new, 1); - - expect_string(__wrap__merror, formatted_msg, "Cannot create EVP_PKEY or EVP_PKEY_CTX structure."); - expect_string(__wrap__merror, formatted_msg, "Cannot generate key to sign the certificate."); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - assert_int_equal(ret_value, 1); -} - -static void test_generate_cert_x509_null(void **state) { - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 0); - will_return(__wrap_X509_new, NULL); - - expect_string(__wrap__merror, formatted_msg, "Cannot generate certificate."); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - assert_int_equal(ret_value, 1); -} - -static void test_generate_cert_sign_fail(void **state) { - FILE key_file = {0}; - FILE cert_file = {0}; - - will_return(__wrap_EVP_PKEY_new, 1); - - will_return(__wrap_X509_new, 1); - will_return(__wrap_X509_sign, 0); - - expect_string(__wrap__merror, formatted_msg, "Error signing certificate."); - - int ret_value = generate_cert(1024, 2048, "key_path", "cert_path", "/C=US/ST=California/CN=Wazuh/"); - assert_int_equal(ret_value, 1); -} -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_generate_cert_success), - cmocka_unit_test(test_generate_cert_success_typo), - cmocka_unit_test(test_save_key_fail), - cmocka_unit_test(test_save_key_fail_fopen), - cmocka_unit_test(test_save_cert_fail), - cmocka_unit_test(test_save_cert_fail_fopen), - cmocka_unit_test(test_generate_cert_key_null), - cmocka_unit_test(test_generate_cert_pkey_null), - cmocka_unit_test(test_generate_cert_sign_fail), - cmocka_unit_test(test_generate_cert_x509_null), - - - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/os_auth/test_ssl.c b/src/unit_tests/os_auth/test_ssl.c deleted file mode 100644 index c82d84c8542..00000000000 --- a/src/unit_tests/os_auth/test_ssl.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../os_auth/auth.h" - -#include "../wrappers/externals/openssl/ssl_lib_wrappers.h" - -/*************************/ -/* setup/teardown */ - -void test_wrap_SSL_read_error_code(void **state) { - char buffer[OS_SIZE_4096]; - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer); - expect_value(__wrap_SSL_read, num, OS_SIZE_4096); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, -1); - - int ret =wrap_SSL_read(NULL, buffer, OS_SIZE_4096); - assert_int_equal(ret, -1); -} - -void test_wrap_SSL_read_success(void **state) { - char buffer[OS_SIZE_4096]; - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer); - expect_value(__wrap_SSL_read, num, OS_SIZE_4096); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, 256); - - int ret =wrap_SSL_read(NULL, buffer, OS_SIZE_4096); - assert_int_equal(ret, 256); -} - -void test_wrap_SSL_read_full_single_record(void **state) { - char buffer[OS_SIZE_65536 + OS_SIZE_4096]; - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer); - expect_value(__wrap_SSL_read, num, OS_SIZE_65536 + OS_SIZE_4096); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, MAX_SSL_PACKET_SIZE); // One record - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer + MAX_SSL_PACKET_SIZE); - expect_value(__wrap_SSL_read, num, OS_SIZE_65536 + OS_SIZE_4096 - MAX_SSL_PACKET_SIZE); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, -1); // One record - - int ret =wrap_SSL_read(NULL, buffer, OS_SIZE_65536 + OS_SIZE_4096); - assert_int_equal(ret, MAX_SSL_PACKET_SIZE); -} - -void test_wrap_SSL_read_multi_record(void **state) { - char buffer[OS_SIZE_65536 + OS_SIZE_4096]; - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer); - expect_value(__wrap_SSL_read, num, OS_SIZE_65536 + OS_SIZE_4096); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, MAX_SSL_PACKET_SIZE); // One record - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer + MAX_SSL_PACKET_SIZE); - expect_value(__wrap_SSL_read, num, OS_SIZE_65536 + OS_SIZE_4096 - MAX_SSL_PACKET_SIZE); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, MAX_SSL_PACKET_SIZE); // Second record - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer + (2* MAX_SSL_PACKET_SIZE)); - expect_value(__wrap_SSL_read, num, OS_SIZE_65536 + OS_SIZE_4096 - (2* MAX_SSL_PACKET_SIZE) ); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, MAX_SSL_PACKET_SIZE); // Third record - - expect_any(__wrap_SSL_read, ssl); - expect_value(__wrap_SSL_read, buf, buffer + (3* MAX_SSL_PACKET_SIZE)); - expect_value(__wrap_SSL_read, num, OS_SIZE_65536 + OS_SIZE_4096 - (3* MAX_SSL_PACKET_SIZE) ); - will_return(__wrap_SSL_read, ""); - will_return(__wrap_SSL_read, 1024); // Part of fourth record - - int ret = wrap_SSL_read(NULL, buffer, OS_SIZE_65536 + OS_SIZE_4096); - assert_int_equal(ret, (3* MAX_SSL_PACKET_SIZE) + 1024); -} - -/*************************/ -int main(void) { - - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_wrap_SSL_read_error_code), - cmocka_unit_test(test_wrap_SSL_read_success), - cmocka_unit_test(test_wrap_SSL_read_full_single_record), - cmocka_unit_test(test_wrap_SSL_read_multi_record), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_crypto/md5_sha1/CMakeLists.txt b/src/unit_tests/os_crypto/md5_sha1/CMakeLists.txt deleted file mode 100644 index ca953290b24..00000000000 --- a/src/unit_tests/os_crypto/md5_sha1/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -cmake_minimum_required(VERSION 3.10) - -list(APPEND md5_sha1_tests_names "test_md5_sha1_op") -list(APPEND md5_sha1_tests_flags "-Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fread \ - -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,popen \ - -Wl,--wrap,fgets -Wl,--wrap,fgetpos -Wl,--wrap,fgetc -Wl,--wrap,snprintf") - -# Compiling tests -list(LENGTH md5_sha1_tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET md5_sha1_tests_names ${counter} test_name) - list(GET md5_sha1_tests_flags ${counter} test_flags) - add_executable(${test_name} ${test_name}.c) - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - endif() - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/os_crypto/md5_sha1/test_md5_sha1_op.c b/src/unit_tests/os_crypto/md5_sha1/test_md5_sha1_op.c deleted file mode 100644 index f021e20be65..00000000000 --- a/src/unit_tests/os_crypto/md5_sha1/test_md5_sha1_op.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../headers/shared.h" -#include "../../os_crypto/md5_sha1/md5_sha1_op.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdio_wrappers.h" - -/* setups/teardowns */ -static int setup_group(void **state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - -// Tests - -void test_md5_sha1_file(void **state) -{ - const char *string = "teststring"; - const char *string_md5 = "d67c5cbf5b01c9f91932e3b8def5e5f8"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - - /* create tmp file */ - char file_name[256]; - strncpy(file_name, "/tmp/tmp_file-XXXXXX", 256); - int fd = mkstemp(file_name); - - write(fd, string, strlen(string)); - close(fd); - - os_md5 md5buffer; - os_sha1 sha1buffer; - - assert_int_equal(OS_MD5_SHA1_File(file_name, NULL, md5buffer, sha1buffer, OS_TEXT), 0); - - assert_string_equal(md5buffer, string_md5); - assert_string_equal(sha1buffer, string_sha1); -} - -void test_md5_sha1_cmd_file(void **state) -{ - const char *string = "teststring"; - const char *string_md5 = "d67c5cbf5b01c9f91932e3b8def5e5f8"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - - /* create tmp file */ - char file_name[256]; - strncpy(file_name, "/tmp/tmp_file-XXXXXX", 256); - int fd = mkstemp(file_name); - - write(fd, string, strlen(string)); - close(fd); - - os_md5 md5buffer; - os_sha1 sha1buffer; - - assert_int_equal(OS_MD5_SHA1_File(file_name, "cat ", md5buffer, sha1buffer, OS_TEXT), 0); - - assert_string_equal(md5buffer, string_md5); - assert_string_equal(sha1buffer, string_sha1); -} - -void test_md5_sha1_cmd_file_fail(void **state) -{ - os_md5 md5buffer; - os_sha1 sha1buffer; - - assert_int_equal(OS_MD5_SHA1_File("not_existing_file", NULL, md5buffer, sha1buffer, OS_TEXT), -1); -} - -void test_md5_sha1_cmd_file_snprintf_fail(void **state) -{ - const char *string = "teststring"; - - /* create tmp file */ - char file_name[256]; - strncpy(file_name, "/tmp/tmp_file-XXXXXX", 256); - int fd = mkstemp(file_name); - - write(fd, string, strlen(string)); - close(fd); - - os_md5 md5buffer; - os_sha1 sha1buffer; - - expect_value(__wrap_snprintf, __maxlen, OS_MAXSTR); - expect_string(__wrap_snprintf, __format, "%s %s"); - - will_return(__wrap_snprintf, -1); - - assert_int_equal(OS_MD5_SHA1_File(file_name, "cat ", md5buffer, sha1buffer, OS_TEXT), -1); -} - -void test_md5_sha1_cmd_file_popen_fail(void **state) -{ - const char *string = "teststring"; - - /* create tmp file */ - char file_name[256]; - strncpy(file_name, "/tmp/tmp_file-XXXXXX", 256); - int fd = mkstemp(file_name); - - write(fd, string, strlen(string)); - close(fd); - - os_md5 md5buffer; - os_sha1 sha1buffer; - - expect_value(__wrap_snprintf, __maxlen, OS_MAXSTR); - expect_string(__wrap_snprintf, __format, "%s %s"); - - will_return(__wrap_snprintf, 25); - - expect_popen("", "r", NULL); - - assert_int_equal(OS_MD5_SHA1_File(file_name, "cat ", md5buffer, sha1buffer, OS_TEXT), -1); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_md5_sha1_file), - cmocka_unit_test(test_md5_sha1_cmd_file), - cmocka_unit_test(test_md5_sha1_cmd_file_fail), - cmocka_unit_test_setup_teardown(test_md5_sha1_cmd_file_snprintf_fail, setup_group, teardown_group), - cmocka_unit_test_setup_teardown(test_md5_sha1_cmd_file_popen_fail, setup_group, teardown_group), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_crypto/md5_sha1_sha256/CMakeLists.txt b/src/unit_tests/os_crypto/md5_sha1_sha256/CMakeLists.txt deleted file mode 100644 index d1071d3d0f4..00000000000 --- a/src/unit_tests/os_crypto/md5_sha1_sha256/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -cmake_minimum_required(VERSION 3.10) - -list(APPEND md5_sha1_tests_names "test_md5_sha1_sha256_op") -list(APPEND md5_sha1_tests_flags "-Wl,--wrap,_mwarn -Wl,--wrap,wpopenv,--wrap,wpclose,--wrap,fread,--wrap,fclose,--wrap,fflush,--wrap,fgets,--wrap,fgetpos \ - -Wl,--wrap,fseek,--wrap,fwrite,--wrap,remove,--wrap,fgetc,--wrap,fopen,--wrap,wfopen -Wl,--wrap,popen") - -# Compiling tests -list(LENGTH md5_sha1_tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET md5_sha1_tests_names ${counter} test_name) - list(GET md5_sha1_tests_flags ${counter} test_flags) - add_executable(${test_name} ${test_name}.c) - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - endif() - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/os_crypto/md5_sha1_sha256/test_md5_sha1_sha256_op.c b/src/unit_tests/os_crypto/md5_sha1_sha256/test_md5_sha1_sha256_op.c deleted file mode 100644 index 78c4e43651a..00000000000 --- a/src/unit_tests/os_crypto/md5_sha1_sha256/test_md5_sha1_sha256_op.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../headers/shared.h" -#include "../os_crypto/md5_sha1/md5_sha1_op.h" -#include "../os_crypto/md5_sha1_sha256/md5_sha1_sha256_op.h" - -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/wazuh/shared/file_op_wrappers.h" - -static int setup_group(void ** state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void ** state) { - test_mode = 0; - return 0; -} - -// Tests - -void test_md5_sha1_sha256_file(void **state) -{ - char *string = "teststring"; - const char *string_md5 = "d67c5cbf5b01c9f91932e3b8def5e5f8"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - const char *string_sha256 = "3c8727e019a42b444667a587b6001251becadabbb36bfed8087a92c18882d111"; - - /* create tmp file */ - char file_name[256] = "/tmp/tmp_file-XXXXXX"; - - FILE * fp = 0x1; - expect_wfopen(file_name, "r", fp); - expect_fread(string, strlen(string)); - expect_fread(string, 0); - expect_fclose(fp, 0); - - os_md5 md5buffer; - os_sha1 sha1buffer; - os_sha256 sha256buffer; - - assert_int_equal(OS_MD5_SHA1_SHA256_File(file_name, NULL, md5buffer, sha1buffer, sha256buffer, OS_TEXT, 20), 0); - - assert_string_equal(md5buffer, string_md5); - assert_string_equal(sha1buffer, string_sha1); -} - -void test_md5_sha1_sha256_cmd_file(void **state) -{ - char *string = "teststring"; - const char *string_md5 = "d67c5cbf5b01c9f91932e3b8def5e5f8"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - const char *string_sha256 = "3c8727e019a42b444667a587b6001251becadabbb36bfed8087a92c18882d111"; - - char file_name[256] = "/tmp/tmp_file-XXXXXX"; - - os_md5 md5buffer; - os_sha1 sha1buffer; - os_sha256 sha256buffer; - char *command [] = {"cat", NULL}; - - wfd_t wfd = { NULL, NULL, 0 }; - will_return(__wrap_wpopenv, &wfd); - expect_fread(string, strlen(string)); - expect_fread(string, 0); - will_return(__wrap_wpclose, 0); - - assert_int_equal(OS_MD5_SHA1_SHA256_File(file_name, command, md5buffer, sha1buffer, sha256buffer, OS_TEXT, 20), 0); - - assert_string_equal(md5buffer, string_md5); - assert_string_equal(sha1buffer, string_sha1); - assert_string_equal(sha1buffer, string_sha1); - -} - -void test_md5_sha1_sha256_cmd_file_fail(void **state) -{ - os_md5 md5buffer; - os_sha1 sha1buffer; - os_sha256 sha256buffer; - - char *command [] = {"cat", NULL}; - - will_return(__wrap_wpopenv, NULL); - - assert_int_equal(OS_MD5_SHA1_SHA256_File("file_name", command, md5buffer, sha1buffer, sha256buffer, OS_TEXT, 20), -1); -} - -void test_md5_sha1_sha256_file_fail(void **state) -{ - os_md5 md5buffer; - os_sha1 sha1buffer; - os_sha256 sha256buffer; - - expect_wfopen("file_name", "r", NULL); - - assert_int_equal(OS_MD5_SHA1_SHA256_File("file_name", NULL, md5buffer, sha1buffer, sha256buffer, OS_TEXT, 20), -1); -} - -void test_md5_sha1_sha256_cmd_file_max_size_fail(void **state) -{ - char *string = "teststring"; - const char *string_md5 = "d67c5cbf5b01c9f91932e3b8def5e5f8"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - const char *string_sha256 = "3c8727e019a42b444667a587b6001251becadabbb36bfed8087a92c18882d111"; - - /* create tmp file */ - char file_name[256] = "/tmp/tmp_file-XXXXXX"; - - FILE * fp = 0x1; - expect_fread(string, strlen(string)); - - os_md5 md5buffer; - os_sha1 sha1buffer; - os_sha256 sha256buffer; - - char *command [] = {"cat", NULL}; - - wfd_t wfd = { NULL, NULL, 0 }; - will_return(__wrap_wpopenv, &wfd); - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mwarn, formatted_msg, "'/tmp/tmp_file-XXXXXX' filesize is larger than the maximum allowed (0 MB). File skipped."); - - assert_int_equal(OS_MD5_SHA1_SHA256_File(file_name, command, md5buffer, sha1buffer, sha256buffer, OS_TEXT, 1), -1); -} - -void test_md5_sha1_sha256_file_max_size_fail(void **state) -{ - char *string = "teststring"; - const char *string_md5 = "d67c5cbf5b01c9f91932e3b8def5e5f8"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - const char *string_sha256 = "3c8727e019a42b444667a587b6001251becadabbb36bfed8087a92c18882d111"; - - /* create tmp file */ - char file_name[256] = "/tmp/tmp_file-XXXXXX"; - - FILE * fp = 0x1; - expect_wfopen(file_name, "r", fp); - expect_fread(string, strlen(string)); - expect_fclose(fp, 0); - - os_md5 md5buffer; - os_sha1 sha1buffer; - os_sha256 sha256buffer; - - expect_string(__wrap__mwarn, formatted_msg, "'/tmp/tmp_file-XXXXXX' filesize is larger than the maximum allowed (0 MB). File skipped."); - - assert_int_equal(OS_MD5_SHA1_SHA256_File(file_name, NULL, md5buffer, sha1buffer, sha256buffer, OS_TEXT, 1), -1); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_md5_sha1_sha256_file), - cmocka_unit_test(test_md5_sha1_sha256_cmd_file), - cmocka_unit_test(test_md5_sha1_sha256_cmd_file_fail), - cmocka_unit_test(test_md5_sha1_sha256_file_fail), - cmocka_unit_test(test_md5_sha1_sha256_cmd_file_max_size_fail), - cmocka_unit_test(test_md5_sha1_sha256_file_max_size_fail), - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/os_crypto/sha1/CMakeLists.txt b/src/unit_tests/os_crypto/sha1/CMakeLists.txt deleted file mode 100644 index 332f1f31272..00000000000 --- a/src/unit_tests/os_crypto/sha1/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -cmake_minimum_required(VERSION 3.10) - -list(APPEND os_crypto_sha1_tests_names "test_sha1_op") -list(APPEND os_crypto_sha1_tests_flags "-Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fread \ - -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fprintf \ - -Wl,--wrap,fgets -Wl,--wrap,fgetpos -Wl,--wrap,fgetc -Wl,--wrap,wfopen -Wl,--wrap,popen") - -# Compiling tests -list(LENGTH os_crypto_sha1_tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET os_crypto_sha1_tests_names ${counter} test_name) - list(GET os_crypto_sha1_tests_flags ${counter} test_flags) - add_executable(${test_name} ${test_name}.c) - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - endif() - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/os_crypto/sha1/test_sha1_op.c b/src/unit_tests/os_crypto/sha1/test_sha1_op.c deleted file mode 100644 index 317a6b04610..00000000000 --- a/src/unit_tests/os_crypto/sha1/test_sha1_op.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../headers/shared.h" -#include "../../os_crypto/sha1/sha1_op.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/common.h" - -int OS_SHA1_File_Nbytes(const char *fname, EVP_MD_CTX **c, os_sha1 output, int mode, int64_t nbytes); - -/* setups/teardowns */ -static int setup_group(void **state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - -/* test */ - -/* OS_SHA1_File_Nbytes */ - -void OS_SHA1_File_Nbytes_context_null (void **state) -{ - const char *path = "/home/test_file"; - EVP_MD_CTX *context = NULL; - os_sha1 output; - ssize_t nbytes = 4096; - - int mode = OS_BINARY; - - assert_int_equal(OS_SHA1_File_Nbytes(path, &context, output, mode, nbytes), -3); -} - -void OS_SHA1_File_Nbytes_unable_open_file (void **state) -{ - const char *path = "/home/test_file"; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - os_sha1 output; - ssize_t nbytes = 4096; - - int mode = OS_BINARY; - - expect_value(__wrap_wfopen, path, path); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, NULL); - - assert_int_equal(OS_SHA1_File_Nbytes(path, &context, output, mode, nbytes), -1); - - EVP_MD_CTX_free(context); -} - -void OS_SHA1_File_Nbytes_ok (void **state) -{ - const char *path = "/home/test_file"; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - os_sha1 output; - ssize_t nbytes = 4000; - - int mode = OS_BINARY; - - expect_value(__wrap_wfopen, path, path); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test"); - will_return(__wrap_fread, 0); - - will_return(__wrap_fread, "test"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 1); - - assert_int_equal(OS_SHA1_File_Nbytes(path, &context, output, mode, nbytes), 0); - - EVP_MD_CTX_free(context); -} - -void OS_SHA1_File_Nbytes_num_bytes_exceded (void **state) -{ - const char *path = "/home/test_file"; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - os_sha1 output; - ssize_t nbytes = 6; - - int mode = OS_BINARY; - - expect_value(__wrap_wfopen, path, path); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 1); - - assert_int_equal(OS_SHA1_File_Nbytes(path, &context, output, mode, nbytes), 0); - - EVP_MD_CTX_free(context); -} - -/* OS_SHA1_Stream */ - -void OS_SHA1_Stream_ok (void **state) -{ - char *buf = "hello"; - os_sha1 output; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - - EVP_DigestInit(context, EVP_sha1()); - - OS_SHA1_Stream(context, output, buf); - - EVP_MD_CTX_free(context); -} - -void OS_SHA1_Stream_buf_null (void **state) -{ - char *buf = NULL; - os_sha1 output; - EVP_MD_CTX *context = EVP_MD_CTX_new(); - - EVP_DigestInit(context, EVP_sha1()); - - OS_SHA1_Stream(context, output, buf); - EVP_MD_CTX_free(context); -} - -void test_sha1_string(void **state) -{ - const char *string = "teststring"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - os_sha1 buffer; - - assert_int_equal(OS_SHA1_Str(string, strlen(string), buffer), 0); - - assert_string_equal(buffer, string_sha1); -} - -void test_sha1_string2(void **state) -{ - const char *string = "teststring"; - const char *string_sha1 = "b8473b86d4c2072ca9b08bd28e373e8253e865c4"; - os_sha1 buffer; - - assert_int_equal(OS_SHA1_Str2(string, strlen(string), buffer), 0); - - assert_string_equal(buffer, string_sha1); -} - -void test_sha1_file(void **state) -{ - const char *string = "teststring"; - const char *string_sha1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; - os_sha1 buffer; - - char file_name[256]; - strncpy(file_name, "/tmp/tmp_file-XXXXXX", 256); - - expect_string(__wrap_wfopen, path, file_name); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, string); - will_return(__wrap_fread, 0); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 1); - - assert_int_equal(OS_SHA1_File(file_name, buffer, OS_TEXT), 0); - - assert_string_equal(buffer, string_sha1); -} - -void test_sha1_file_fail(void **state) -{ - os_sha1 buffer; - - char file_name[256]; - strncpy(file_name, "not_existing_file", 256); - - expect_string(__wrap_wfopen, path, file_name); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 0); - - assert_int_equal(OS_SHA1_File(file_name, buffer, OS_TEXT), -1); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Tests OS_SHA1_File_Nbytes - cmocka_unit_test(OS_SHA1_File_Nbytes_context_null), - cmocka_unit_test(OS_SHA1_File_Nbytes_unable_open_file), - cmocka_unit_test(OS_SHA1_File_Nbytes_ok), - cmocka_unit_test(OS_SHA1_File_Nbytes_num_bytes_exceded), - // Tests OS_SHA1_Stream - cmocka_unit_test(OS_SHA1_Stream_ok), - cmocka_unit_test(OS_SHA1_Stream_buf_null), - // Tests OS_SHA1_File - cmocka_unit_test(test_sha1_string), - cmocka_unit_test(test_sha1_string2), - cmocka_unit_test(test_sha1_file), - cmocka_unit_test(test_sha1_file_fail), - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/os_csyslogd/CMakeLists.txt b/src/unit_tests/os_csyslogd/CMakeLists.txt deleted file mode 100644 index 97a2feb0775..00000000000 --- a/src/unit_tests/os_csyslogd/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ - -file(GLOB os_csyslogd_files ${SRC_FOLDER}/os_csyslogd/*.o) -list(REMOVE_ITEM os_csyslogd_files ${SRC_FOLDER}/os_csyslogd/main.o) - - -add_library(CSYSLOGD_O STATIC ${os_csyslogd_files}) - -set_source_files_properties( - ${os_csyslogd_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - CSYSLOGD_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(CSYSLOGD_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - - -# Generate tests src/unit_tests/csyslogd/test_csyslogd.c -list(APPEND os_csyslogd_names "test_csyslogd") -list(APPEND os_csyslogd_flags "-Wl,--wrap,jqueue_open -Wl,--wrap,jqueue_next -Wl,--wrap,FOREVER -Wl,--wrap,time ${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,os_random -Wl,--wrap,wpopenv -Wl,--wrap,wpclose -Wl,--wrap,fprintf -Wl,--wrap,File_DateofChange ${STDIO_OP_WRAPPERS} \ - -Wl,--wrap,merror -Wl,--wrap,minfo -Wl,--wrap,mdebug1 -Wl,--wrap,mdebug2 -Wl,--wrap,merror -Wl,--wrap,wfopen \ - -Wl,--wrap,w_ftell -Wl,--wrap,fgets -Wl,--wrap,OS_Alert_SendSyslog_JSON -Wl,--wrap,OS_Alert_SendSyslog\ - -Wl,--wrap,OS_IsValidIP -Wl,--wrap,OS_ConnectUDP -Wl,--wrap,time -Wl,--wrap,Read_FileMon -Wl,--wrap,Init_FileQueue -Wl,--wrap,sleep \ - -Wl,--wrap,popen") - -# Compiling tests -list(LENGTH os_csyslogd_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET os_csyslogd_names ${counter} csyslogd_test_name) - list(GET os_csyslogd_flags ${counter} csyslogd_test_flags) - - add_executable(${csyslogd_test_name} ${csyslogd_test_name}.c) - - target_link_libraries( - ${csyslogd_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - CSYSLOGD_O - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${csyslogd_test_name} - ${csyslogd_test_flags} - ) - endif() - add_test(NAME ${csyslogd_test_name} COMMAND ${csyslogd_test_name}) -endforeach() diff --git a/src/unit_tests/os_csyslogd/test_csyslogd.c b/src/unit_tests/os_csyslogd/test_csyslogd.c deleted file mode 100644 index b0e3609baaa..00000000000 --- a/src/unit_tests/os_csyslogd/test_csyslogd.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * November, 2020. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../external/cJSON/cJSON.h" - -#include "../headers/shared.h" -#include "../headers/read-alert.h" -#include "../../os_csyslogd/csyslogd.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/json_queue_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/linux/socket_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/posix/time_wrappers.h" -#include "../wrappers/externals/pcre2/pcre2_wrappers.h" -#include "../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" - -#define MAX_FOREVER_ITS (10) - -int __wrap_OS_Alert_SendSyslog_JSON(__attribute__((unused)) cJSON *json_data, __attribute__((unused)) SyslogConfig *syslog_config) { - return mock_type(int); -} - -int __wrap_OS_Alert_SendSyslog(__attribute__((unused))alert_data *al_data, __attribute__((unused))SyslogConfig *syslog_config) { - return mock_type(int); -} - -alert_data *__wrap_Read_FileMon(__attribute__((unused))file_queue *fileq, __attribute__((unused))const struct tm *p, __attribute__((unused))unsigned int timeout) { - return mock_type(alert_data*); -} - -int __wrap_Init_FileQueue(__attribute__((unused))file_queue *fileq, __attribute__((unused))const struct tm *p, __attribute__((unused))int flags) { - return mock_type(int); -} - -void __wrap_sleep(__attribute__((unused))unsigned int seconds) { - check_expected(seconds); - return; -} - -static SyslogConfig *makeSyslogConfig(unsigned int format) { - - SyslogConfig *pRet; - - os_calloc(1, sizeof(SyslogConfig), pRet); - - pRet->port = 1514; - pRet->format = format; - pRet->level = 7; - pRet->server = "127.0.0.1"; - - return pRet; -} - -static int test_csyslogd_json_setup(void **state) { - - SyslogConfig *pSyslogConfig = makeSyslogConfig(JSON_CSYSLOG); - - if (pSyslogConfig) { - state[0] = pSyslogConfig; - return OS_SUCCESS; - } - - return OS_INVALID; -} - -static int test_csyslogd_log_setup(void **state) { - - SyslogConfig *pSyslogConfig = makeSyslogConfig(DEFAULT_CSYSLOG); - if (pSyslogConfig) { - state[0] = pSyslogConfig; - return OS_SUCCESS; - } - - return OS_INVALID; -} - -static int test_csyslogd_teardown(void **state) { - - SyslogConfig *pSyslogConfig = state[0]; - os_free(pSyslogConfig); - return OS_SUCCESS; -} - -static void test_csyslogd_json_CSyslogD(void **state) { - - cJSON *pJSON = NULL; - SyslogConfig *pSyslogConfig[2]; - - pSyslogConfig[0] = state[0]; - - char *ip = pSyslogConfig[0]->server; - int port = pSyslogConfig[0]->port; - - pSyslogConfig[1] = NULL; - - will_return(__wrap_jqueue_open, 0); - expect_string(__wrap__mdebug1, formatted_msg, "JSON file queue connected."); - - char strDbgResolving[128]; - sprintf(strDbgResolving, "Resolving server hostname: %s", ip); - expect_string(__wrap__mdebug2, formatted_msg, strDbgResolving); - - expect_string(__wrap_OS_IsValidIP, ip_address, ip); - expect_value(__wrap_OS_IsValidIP, final_ip, NULL); - will_return(__wrap_OS_IsValidIP, 1); - - will_return(__wrap_OS_ConnectUDP, 21); - - char strDbgForwarding[128]; - sprintf(strDbgForwarding, "Forwarding alerts via syslog to: '%s:%d'.", ip, port); - expect_string(__wrap__minfo, formatted_msg, strDbgForwarding); - - for (int i = 0; i < MAX_FOREVER_ITS; i++) { - will_return(__wrap_time, 62168472000); - - expect_string(__wrap__mdebug2, formatted_msg, "jqueue_next()"); - - pJSON = cJSON_Parse((char*)("{\"alert\":\"valid jason description\"}\n")); - will_return(__wrap_jqueue_next, pJSON); - - will_return(__wrap_OS_Alert_SendSyslog_JSON, 1); - will_return(__wrap_FOREVER, 1); - } - - will_return(__wrap_FOREVER, 0); - - OS_CSyslogD(pSyslogConfig); -} - -void makeAlertData(alert_data *al_data) { - - os_strdup("Alert ID", al_data->alertid); - os_strdup("Date", al_data->date); - os_strdup("Location", al_data->location); - os_strdup("a comment...", al_data->comment); - os_strdup("syscheck", al_data->group); - os_strdup("sript() {break;}", al_data->srcip); - os_strdup("dstip", al_data->dstip); - os_strdup("user@mock", al_data->user); - os_strdup("mock_data", al_data->filename); - os_strdup("1111", al_data->old_md5); - os_strdup("2222", al_data->new_md5); - os_strdup("AAAA", al_data->old_sha1); - os_strdup("BBBB", al_data->new_sha1); - os_strdup("qqqq", al_data->old_sha256); - os_strdup("QQQQ", al_data->new_sha256); - os_strdup("32", al_data->file_size); - os_strdup("mock owner", al_data->owner_chg); - os_strdup("mock group chg", al_data->group_chg); - os_strdup("mock perm chg", al_data->perm_chg); - - os_calloc(2, sizeof(char *), al_data->log); - os_strdup("this is a mock data log entry...", al_data->log[0]); - al_data->log[1] = NULL; -} - -static void test_csyslogd_log_CSyslogD(void **state) { - - alert_data *al_data = NULL; - SyslogConfig *pSyslogConfig[2]; - - pSyslogConfig[0] = state[0]; - - char *ip = pSyslogConfig[0]->server; - int port = pSyslogConfig[0]->port; - - pSyslogConfig[1] = NULL; - - will_return(__wrap_time, 62168472000); - will_return(__wrap_Init_FileQueue, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "File queue connected."); - - char strDbgResolving[128]; - sprintf(strDbgResolving, "Resolving server hostname: %s", ip); - expect_string(__wrap__mdebug2, formatted_msg, strDbgResolving); - - expect_string(__wrap_OS_IsValidIP, ip_address, ip); - expect_value(__wrap_OS_IsValidIP, final_ip, NULL); - will_return(__wrap_OS_IsValidIP, 1); - - will_return(__wrap_OS_ConnectUDP, 21); - - char strDbgForwarding[128]; - sprintf(strDbgForwarding, "Forwarding alerts via syslog to: '%s:%d'.", ip, port); - expect_string(__wrap__minfo, formatted_msg, strDbgForwarding); - - for (int i = 0; i < MAX_FOREVER_ITS; i++) { - will_return(__wrap_time, 62168472000); - expect_string(__wrap__mdebug2, formatted_msg, "Read_FileMon()"); - - os_calloc(1, sizeof(alert_data), al_data); - makeAlertData(al_data); - - will_return(__wrap_Read_FileMon, al_data); - will_return(__wrap_OS_Alert_SendSyslog, 1); - - will_return(__wrap_FOREVER, 1); - } - - will_return(__wrap_FOREVER, 0); - - OS_CSyslogD(pSyslogConfig); -} - -static void test_csyslogd_log_CSyslogD_max_tries(void **state) { - - SyslogConfig *pSyslogConfig[2]; - - pSyslogConfig[0] = state[0]; - - char *ip = pSyslogConfig[0]->server; - int port = pSyslogConfig[0]->port; - - pSyslogConfig[1] = NULL; - - alert_data *al_data; - os_calloc(1, sizeof(alert_data), al_data); - makeAlertData(al_data); - - will_return(__wrap_time, 62168472000); - - for (int tries = 0; tries < OS_CSYSLOGD_MAX_TRIES; tries++) { - will_return(__wrap_Init_FileQueue, -1); - expect_value(__wrap_sleep, seconds, 1); - } - - char strMaxTries[128]; - sprintf(strMaxTries, "Could not open queue after %d tries.", OS_CSYSLOGD_MAX_TRIES); - expect_string(__wrap__merror, formatted_msg, strMaxTries); - expect_string(__wrap__merror, formatted_msg, "No configurations available. Exiting."); - - OS_CSyslogD(pSyslogConfig); - - FreeAlertData(al_data); -} - -static void test_csyslogd_json_CSyslogD_max_tries(void **state) { - - SyslogConfig *pSyslogConfig[2]; - - pSyslogConfig[0] = state[0]; - - char *ip = pSyslogConfig[0]->server; - int port = pSyslogConfig[0]->port; - - pSyslogConfig[1] = NULL; - - - for (int tries = 1; tries < OS_CSYSLOGD_MAX_TRIES; tries++) { - will_return(__wrap_jqueue_open, -1); - expect_value(__wrap_sleep, seconds, 1); - } - - char strMaxTries[128]; - sprintf(strMaxTries, "Could not open JSON queue after %d tries.", OS_CSYSLOGD_MAX_TRIES); - expect_string(__wrap__merror, formatted_msg, strMaxTries); - expect_string(__wrap__merror, formatted_msg, "No configurations available. Exiting."); - - OS_CSyslogD(pSyslogConfig); -} - -static void test_csyslogd_json_unableUDP_CSyslogD(void **state) { - - cJSON *pJSON = NULL; - SyslogConfig *pSyslogConfig[2]; - - pSyslogConfig[0] = state[0]; - - char *ip = pSyslogConfig[0]->server; - int port = pSyslogConfig[0]->port; - - pSyslogConfig[1] = NULL; - - will_return(__wrap_jqueue_open, 0); - expect_string(__wrap__mdebug1, formatted_msg, "JSON file queue connected."); - - char strDbgResolving[128]; - sprintf(strDbgResolving, "Resolving server hostname: %s", ip); - expect_string(__wrap__mdebug2, formatted_msg, strDbgResolving); - - expect_string(__wrap_OS_IsValidIP, ip_address, ip); - expect_value(__wrap_OS_IsValidIP, final_ip, NULL); - will_return(__wrap_OS_IsValidIP, 1); - - will_return(__wrap_OS_ConnectUDP, OS_SOCKTERR); - errno = EINVAL; - - char strUnable[256]; - sprintf(strUnable, CONNS_ERROR, ip, port, "udp", strerror(errno)); - expect_string(__wrap__merror, formatted_msg, strUnable); - - for (int i = 0; i < MAX_FOREVER_ITS; i++) { - will_return(__wrap_time, 62168472000); - - expect_string(__wrap__mdebug2, formatted_msg, "jqueue_next()"); - - pJSON = cJSON_Parse((char*)("{\"alert\":\"valid jason description\"}\n")); - will_return(__wrap_jqueue_next, pJSON); - - will_return(__wrap_OS_Alert_SendSyslog_JSON, 1); - will_return(__wrap_FOREVER, 1); - } - - will_return(__wrap_FOREVER, 0); - - OS_CSyslogD(pSyslogConfig); -} - -static void test_csyslogd_json_log_no_dataCSyslogD(void **state) { - - SyslogConfig *pSyslogConfig[2]; - - pSyslogConfig[0] = state[0]; - - char *ip = pSyslogConfig[0]->server; - int port = pSyslogConfig[0]->port; - - pSyslogConfig[1] = NULL; - - will_return(__wrap_jqueue_open, 0); - expect_string(__wrap__mdebug1, formatted_msg, "JSON file queue connected."); - - char strDbgResolving[128]; - sprintf(strDbgResolving, "Resolving server hostname: %s", ip); - expect_string(__wrap__mdebug2, formatted_msg, strDbgResolving); - - expect_string(__wrap_OS_IsValidIP, ip_address, ip); - expect_value(__wrap_OS_IsValidIP, final_ip, NULL); - will_return(__wrap_OS_IsValidIP, 1); - - will_return(__wrap_OS_ConnectUDP, 21); - - char strDbgForwarding[128]; - sprintf(strDbgForwarding, "Forwarding alerts via syslog to: '%s:%d'.", ip, port); - expect_string(__wrap__minfo, formatted_msg, strDbgForwarding); - - for (int i = 0; i < MAX_FOREVER_ITS; i++) { - will_return(__wrap_time, 62168472000); - expect_string(__wrap__mdebug2, formatted_msg, "jqueue_next()"); - will_return(__wrap_jqueue_next, NULL); - expect_value(__wrap_sleep, seconds, 1); - will_return(__wrap_FOREVER, 1); - } - - will_return(__wrap_FOREVER, 0); - - OS_CSyslogD(pSyslogConfig); -} - -int main() { - - const struct CMUnitTest tests[] = - { - cmocka_unit_test_setup_teardown(test_csyslogd_json_CSyslogD, test_csyslogd_json_setup, test_csyslogd_teardown), - cmocka_unit_test_setup_teardown(test_csyslogd_log_CSyslogD, test_csyslogd_log_setup, test_csyslogd_teardown), - cmocka_unit_test_setup_teardown(test_csyslogd_log_CSyslogD_max_tries,test_csyslogd_log_setup, test_csyslogd_teardown), - cmocka_unit_test_setup_teardown(test_csyslogd_json_CSyslogD_max_tries, test_csyslogd_json_setup, test_csyslogd_teardown), - cmocka_unit_test_setup_teardown(test_csyslogd_json_unableUDP_CSyslogD, test_csyslogd_json_setup, test_csyslogd_teardown), - cmocka_unit_test_setup_teardown(test_csyslogd_json_log_no_dataCSyslogD, test_csyslogd_json_setup, test_csyslogd_teardown) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_execd/CMakeLists.txt b/src/unit_tests/os_execd/CMakeLists.txt deleted file mode 100644 index 46795cf724a..00000000000 --- a/src/unit_tests/os_execd/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -# Generate execd library -file(GLOB execd_files - ${SRC_FOLDER}/os_execd/*.o - ${SRC_FOLDER}/active-response/*.o) - -add_library(EXECD_O STATIC ${execd_files}) - -set_source_files_properties( - ${execd_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - EXECD_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(EXECD_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate Execd tests -if(${TARGET} STREQUAL "winagent") - list(APPEND execd_names "test_win_execd") - list(APPEND execd_flags "-Wl,--wrap,ReadExecConfig -Wl,--wrap,GetCommandbyName -Wl,--wrap,wpopenv -Wl,--wrap,wpclose -Wl,--wrap,fwrite \ - -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fread -Wl,--wrap,fseek \ - -Wl,--wrap,remove -Wl,--wrap,fgetpos -Wl,--wrap=fgetc -Wl,--wrap,fwrite -Wl,--wrap,wfopen \ - -Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap=is_fim_shutdown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown \ - -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS}") - - list(APPEND execd_names "test_get_command_by_name") - list(APPEND execd_flags "-Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap=is_fim_shutdown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown \ - ${DEBUG_OP_WRAPPERS}") -else() - list(APPEND execd_names "test_execd") - list(APPEND execd_flags "-Wl,--wrap,time -Wl,--wrap,select -Wl,--wrap,OS_RecvUnix -Wl,--wrap,wfopen \ - -Wl,--wrap,ReadExecConfig -Wl,--wrap,GetCommandbyName -Wl,--wrap,wpopenv -Wl,--wrap,wpclose -Wl,--wrap,fwrite \ - -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fread -Wl,--wrap,fseek \ - -Wl,--wrap,remove -Wl,--wrap,fgetpos -Wl,--wrap=fgetc -Wl,--wrap,fwrite \ - -Wl,--wrap,fprintf -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS}") - - list(APPEND execd_names "test_get_command_by_name") - list(APPEND execd_flags "${DEBUG_OP_WRAPPERS}") -endif() - -list(LENGTH execd_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET execd_names ${counter} execd_test_name) - list(GET execd_flags ${counter} execd_test_flags) - - add_executable(${execd_test_name} ${execd_test_name}.c) - - target_link_libraries( - ${execd_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - EXECD_O - ${TEST_DEPS} - ) - - if(${TARGET} STREQUAL "winagent") - target_link_libraries(${execd_test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - - if(NOT execd_test_flags STREQUAL " ") - target_link_libraries( - ${execd_test_name} - ${execd_test_flags} - ) - endif() - add_test(NAME ${execd_test_name} COMMAND ${execd_test_name}) -endforeach() diff --git a/src/unit_tests/os_execd/test_execd.c b/src/unit_tests/os_execd/test_execd.c deleted file mode 100644 index 31b7d45e4a3..00000000000 --- a/src/unit_tests/os_execd/test_execd.c +++ /dev/null @@ -1,1144 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "list_op.h" -#include "../os_regex/os_regex.h" -#include "../os_net/os_net.h" -#include "../wazuh_modules/wmodules.h" -#include "../external/cJSON/cJSON.h" -#include "../os_execd/execd.h" - -#include "../wrappers/common.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/posix/select_wrappers.h" -#include "../wrappers/wazuh/os_execd/exec_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/exec_op_wrappers.h" - -extern int test_mode; -extern OSList *timeout_list; - -void ExecdStart(int q); - -/* Setup/Teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -static int test_setup_file(void **state) { - wfd_t* wfd = NULL; - os_calloc(1, sizeof(wfd_t), wfd); - wfd->file_in = (FILE *)1; - wfd->file_out = (FILE *)2; - timeout_list = OSList_Create(); - *state = wfd; - return 0; -} - -static int test_setup_file_timeout(void **state) { - wfd_t* wfd = NULL; - os_calloc(1, sizeof(wfd_t), wfd); - wfd->file_in = (FILE *)1; - wfd->file_out = (FILE *)2; - timeout_list = OSList_Create(); - timeout_data *timeout_entry; - os_calloc(1, sizeof(timeout_data), timeout_entry); - os_calloc(2, sizeof(char *), timeout_entry->command); - os_strdup("restart-wazuh10", timeout_entry->command[0]); - timeout_entry->command[1] = NULL; - os_strdup("restart-wazuh-10.0.0.1-root", timeout_entry->rkey); - timeout_entry->time_of_addition = 123456789; - timeout_entry->time_to_block = 10; - OSList_AddData(timeout_list, timeout_entry); - *state = wfd; - return 0; -} - -static int test_teardown_file(void **state) { - wfd_t* wfd = *state; - os_free(wfd); - FreeTimeoutList(); - return 0; -} - -/* Tests */ - -static void test_ExecdStart_ok(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: '{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}'"); - - will_return(__wrap_time, now); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fprintf, __stream, wfd->file_in); - expect_string(__wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(__wrap_fprintf, 0); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, "{" - "\"version\":1," - "\"origin\":{" - "\"name\":\"restart-wazuh\"," - "\"module\":\"active-response\"" - "}," - "\"command\":\"check_keys\"," - "\"parameters\":{" - "\"keys\":[\"10.0.0.1\", \"root\"]" - "}" - "}\n"); - - expect_value(__wrap_fprintf, __stream, wfd->file_in); - expect_string(__wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"continue\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(__wrap_fprintf, 0); - - will_return(__wrap_wpclose, 0); - - ExecdStart(queue); -} - -static void test_ExecdStart_timeout_not_repeated(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh10\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 10; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: '{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh10\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}'"); - - will_return(__wrap_time, now); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh10"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fprintf, __stream, wfd->file_in); - expect_string(__wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(__wrap_fprintf, 0); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, "{" - "\"version\":1," - "\"origin\":{" - "\"name\":\"restart-wazuh\"," - "\"module\":\"active-response\"" - "}," - "\"command\":\"check_keys\"," - "\"parameters\":{" - "\"keys\":[\"10.0.0.2\", \"root\"]" - "}" - "}\n"); - - expect_value(__wrap_fprintf, __stream, wfd->file_in); - expect_string(__wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"continue\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(__wrap_fprintf, 0); - - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Adding command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"delete\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}' to the timeout list, with a timeout of '10s'."); - - ExecdStart(queue); -} - -static void test_ExecdStart_timeout_repeated(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh10\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 10; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: '{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh10\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}'"); - - will_return(__wrap_time, now); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh10"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fprintf, __stream, wfd->file_in); - expect_string(__wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(__wrap_fprintf, 0); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, "{" - "\"version\":1," - "\"origin\":{" - "\"name\":\"restart-wazuh\"," - "\"module\":\"active-response\"" - "}," - "\"command\":\"check_keys\"," - "\"parameters\":{" - "\"keys\":[\"10.0.0.1\", \"root\"]" - "}" - "}\n"); - - expect_value(__wrap_fprintf, __stream, wfd->file_in); - expect_string(__wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"abort\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(__wrap_fprintf, 0); - - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Command already received, updating time of addition to now."); - - ExecdStart(queue); -} - -static void test_ExecdStart_wpopenv_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: '{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}'"); - - will_return(__wrap_time, now); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1317): Could not launch command Success (0)"); - - ExecdStart(queue); -} - -static void test_ExecdStart_fgets_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: '{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}'"); - - will_return(__wrap_time, now); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fprintf, __stream, wfd->file_in); - expect_string(__wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(__wrap_fprintf, 0); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Active response won't be added to timeout list. Message not received with alert keys from script 'restart-wazuh'"); - - will_return(__wrap_wpclose, 0); - - ExecdStart(queue); -} - -static void test_ExecdStart_get_command_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: '{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}'"); - - will_return(__wrap_time, now); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, NULL); - - will_return(__wrap_ReadExecConfig, 0); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1311): Invalid command name 'restart-wazuh0' provided."); - - ExecdStart(queue); -} - -static void test_ExecdStart_get_name_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{}"; - char *message2 = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: '{}'"); - - will_return(__wrap_time, now); - - expect_string(__wrap__merror, formatted_msg, "(1316): Invalid AR command: '{}'"); - - ExecdStart(queue); -} - -static void test_ExecdStart_json_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "unknown"; - char *message2 = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - will_return(__wrap_time, now); - - will_return(__wrap_select, 1); - - expect_value(__wrap_OS_RecvUnix, socket, queue); - expect_value(__wrap_OS_RecvUnix, sizet, OS_MAXSTR); - will_return(__wrap_OS_RecvUnix, message); - will_return(__wrap_OS_RecvUnix, strlen(message)); - - expect_string(__wrap__mdebug2, formatted_msg, "Received message: 'unknown'"); - - will_return(__wrap_time, now); - - expect_string(__wrap__merror, formatted_msg, "(1315): Invalid JSON message: 'unknown'"); - - ExecdStart(queue); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_ExecdStart_ok, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_ExecdStart_timeout_not_repeated, test_setup_file_timeout, test_teardown_file), - cmocka_unit_test_setup_teardown(test_ExecdStart_timeout_repeated, test_setup_file_timeout, test_teardown_file), - cmocka_unit_test_setup_teardown(test_ExecdStart_wpopenv_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_ExecdStart_fgets_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_ExecdStart_get_command_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_ExecdStart_get_name_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_ExecdStart_json_err, test_setup_file, test_teardown_file), - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/os_execd/test_get_command_by_name.c b/src/unit_tests/os_execd/test_get_command_by_name.c deleted file mode 100644 index d41f96be748..00000000000 --- a/src/unit_tests/os_execd/test_get_command_by_name.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../os_execd/execd.h" - -static void test_custom_command(void **state) { - (void)state; - - int timeout = 100; - char * r = GetCommandbyName("!custom.sh", &timeout); - - assert_int_equal(timeout, 0); - assert_string_equal(r, AR_BINDIR "/custom.sh"); -} - -static void test_path_traversal(void **state) { - (void)state; - int timeout = 100; - - expect_string(__wrap__mwarn, formatted_msg, "Active response command '../custom.sh' vulnerable to directory traversal attack. Ignoring."); - - char * r = GetCommandbyName("!../custom.sh", &timeout); - assert_null(r); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_custom_command), - cmocka_unit_test(test_path_traversal), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_execd/test_win_execd.c b/src/unit_tests/os_execd/test_win_execd.c deleted file mode 100644 index 846faf0d928..00000000000 --- a/src/unit_tests/os_execd/test_win_execd.c +++ /dev/null @@ -1,825 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "list_op.h" -#include "../os_regex/os_regex.h" -#include "../os_net/os_net.h" -#include "../os_execd/execd.h" - -#include "../wrappers/common.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/wazuh/os_execd/exec_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/exec_op_wrappers.h" -#include "../wrappers/windows/libc/stdio_wrappers.h" - -extern int test_mode; -extern OSList *timeout_list; - -/* Setup/Teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -static int test_setup_file(void **state) { - wfd_t* wfd = NULL; - os_calloc(1, sizeof(wfd_t), wfd); - wfd->file_in = (FILE *)1; - wfd->file_out = (FILE *)2; - timeout_list = OSList_Create(); - *state = wfd; - return 0; -} - -static int test_setup_file_timeout(void **state) { - wfd_t* wfd = NULL; - os_calloc(1, sizeof(wfd_t), wfd); - wfd->file_in = (FILE *)1; - wfd->file_out = (FILE *)2; - timeout_list = OSList_Create(); - timeout_data *timeout_entry; - os_calloc(1, sizeof(timeout_data), timeout_entry); - os_calloc(2, sizeof(char *), timeout_entry->command); - os_strdup("restart-wazuh10", timeout_entry->command[0]); - timeout_entry->command[1] = NULL; - os_strdup("restart-wazuh-10.0.0.1-root", timeout_entry->rkey); - timeout_entry->time_of_addition = 123456789; - timeout_entry->time_to_block = 10; - OSList_AddData(timeout_list, timeout_entry); - *state = wfd; - return 0; -} - -static int test_teardown_file(void **state) { - wfd_t* wfd = *state; - os_free(wfd); - FreeTimeoutList(); - return 0; -} - -/* Tests */ - -static void test_WinExecdRun_ok(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(wrap_fprintf, __stream, wfd->file_in); - expect_string(wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, wfd->file_out); - will_return(wrap_fgets, "{" - "\"version\":1," - "\"origin\":{" - "\"name\":\"restart-wazuh\"," - "\"module\":\"active-response\"" - "}," - "\"command\":\"check_keys\"," - "\"parameters\":{" - "\"keys\":[\"10.0.0.1\", \"root\"]" - "}" - "}\n"); - - expect_value(wrap_fprintf, __stream, wfd->file_in); - expect_string(wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"continue\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(wrap_fprintf, 0); - - will_return(__wrap_wpclose, 0); - - ExecdRun(message); -} - -static void test_WinExecdRun_timeout_not_repeated(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh10\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 10; - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh10"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(wrap_fprintf, __stream, wfd->file_in); - expect_string(wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, wfd->file_out); - will_return(wrap_fgets, "{" - "\"version\":1," - "\"origin\":{" - "\"name\":\"restart-wazuh\"," - "\"module\":\"active-response\"" - "}," - "\"command\":\"check_keys\"," - "\"parameters\":{" - "\"keys\":[\"10.0.0.2\", \"root\"]" - "}" - "}\n"); - - expect_value(wrap_fprintf, __stream, wfd->file_in); - expect_string(wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"continue\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(wrap_fprintf, 0); - - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Adding command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"delete\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}' to the timeout list, with a timeout of '10s'."); - - ExecdRun(message); -} - -static void test_WinExecdRun_timeout_repeated(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh10\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 10; - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh10"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(wrap_fprintf, __stream, wfd->file_in); - expect_string(wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, wfd->file_out); - will_return(wrap_fgets, "{" - "\"version\":1," - "\"origin\":{" - "\"name\":\"restart-wazuh\"," - "\"module\":\"active-response\"" - "}," - "\"command\":\"check_keys\"," - "\"parameters\":{" - "\"keys\":[\"10.0.0.1\", \"root\"]" - "}" - "}\n"); - - expect_value(wrap_fprintf, __stream, wfd->file_in); - expect_string(wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"abort\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(wrap_fprintf, 0); - - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Command already received, updating time of addition to now."); - - ExecdRun(message); -} - -static void test_WinExecdRun_wpopenv_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1317): Could not launch command Success (0)"); - - ExecdRun(message); -} - -static void test_WinExecdRun_fgets_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, "restart-wazuh"); - - expect_string(__wrap__mdebug1, formatted_msg, "Executing command 'restart-wazuh {" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}'"); - - will_return(__wrap_wpopenv, wfd); - - expect_value(wrap_fprintf, __stream, wfd->file_in); - expect_string(wrap_fprintf, formatted_msg, "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-execd\"" - "}," - "\"command\":\"add\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}," - "\"program\":\"restart-wazuh\"" - "}" - "}\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, wfd->file_out); - will_return(wrap_fgets, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Active response won't be added to timeout list. Message not received with alert keys from script 'restart-wazuh'"); - - will_return(__wrap_wpclose, 0); - - ExecdRun(message); -} - -static void test_WinExecdRun_get_command_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{" - "\"version\":\"1\"," - "\"origin\":{" - "\"name\":\"node01\"," - "\"module\":\"wazuh-analysisd\"" - "}," - "\"command\":\"restart-wazuh0\"," - "\"parameters\":{" - "\"extra_args\":[]," - "\"alert\":{" - "\"timestamp\":\"2021-01-05T15:23:00.547+0000\"," - "\"rule\":{" - "\"level\":5," - "\"description\":\"File added to the system.\"," - "\"id\":\"554\"" - "}," - "\"id\":\"1609860180.513333\"," - "\"full_log\":\"File '/home/vagrant/file/n41.txt' added\\nMode: realtime\\n\"," - "\"syscheck\":{" - "\"path\":\"/home/vagrant/file/n41.txt\"," - "\"mode\":\"realtime\"," - "\"event\":\"added\"" - "}," - "\"location\":\"syscheck\"" - "}" - "}" - "}"; - int timeout = 0; - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, NULL); - - will_return(__wrap_ReadExecConfig, 0); - - expect_string(__wrap_GetCommandbyName, name, "restart-wazuh0"); - will_return(__wrap_GetCommandbyName, timeout); - will_return(__wrap_GetCommandbyName, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1311): Invalid command name 'restart-wazuh0' provided."); - - ExecdRun(message); -} - -static void test_WinExecdRun_get_name_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "{}"; - int timeout = 0; - - expect_string(__wrap__merror, formatted_msg, "(1316): Invalid AR command: '{}'"); - - ExecdRun(message); -} - -static void test_WinExecdRun_json_err(void **state) { - wfd_t * wfd = *state; - int queue = 1; - int now = 123456789; - char *message = "unknown"; - int timeout = 0; - - expect_string(__wrap__merror, formatted_msg, "(1315): Invalid JSON message: 'unknown'"); - - ExecdRun(message); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_WinExecdRun_ok, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_WinExecdRun_timeout_not_repeated, test_setup_file_timeout, test_teardown_file), - cmocka_unit_test_setup_teardown(test_WinExecdRun_timeout_repeated, test_setup_file_timeout, test_teardown_file), - cmocka_unit_test_setup_teardown(test_WinExecdRun_wpopenv_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_WinExecdRun_fgets_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_WinExecdRun_get_command_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_WinExecdRun_get_name_err, test_setup_file, test_teardown_file), - cmocka_unit_test_setup_teardown(test_WinExecdRun_json_err, test_setup_file, test_teardown_file), - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/os_integrator/CMakeLists.txt b/src/unit_tests/os_integrator/CMakeLists.txt deleted file mode 100644 index 92802480230..00000000000 --- a/src/unit_tests/os_integrator/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -# Generate os_integrator library -file(GLOB os_integrator_files - ${SRC_FOLDER}/os_integrator/*.o) - -add_library(OS_INTEGRATOR_O STATIC ${os_integrator_files}) - -set_source_files_properties( - ${os_integrator_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - OS_INTEGRATOR_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(OS_INTEGRATOR_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -list(APPEND os_integrator_names "test_integrator") -list(APPEND os_integrator_flags "-Wl,--wrap,jqueue_open -Wl,--wrap,jqueue_next -Wl,--wrap,FOREVER -Wl,--wrap,time ${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,os_random -Wl,--wrap,wpopenv -Wl,--wrap,wpclose -Wl,--wrap,fprintf -Wl,--wrap,unlink,--wrap,getpid \ - -Wl,--wrap,File_DateofChange -Wl,--wrap,wfopen -Wl,--wrap,popen ${STDIO_OP_WRAPPERS}") - -list(LENGTH os_integrator_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET os_integrator_names ${counter} os_integrator_test_name) - list(GET os_integrator_flags ${counter} os_integrator_test_flags) - - add_executable(${os_integrator_test_name} ${os_integrator_test_name}.c) - - target_link_libraries( - ${os_integrator_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - OS_INTEGRATOR_O - ${TEST_DEPS} - ) - if(NOT os_integrator_test_flags STREQUAL " ") - target_link_libraries( - ${os_integrator_test_name} - ${os_integrator_test_flags} - ) - endif() - add_test(NAME ${os_integrator_test_name} COMMAND ${os_integrator_test_name}) -endforeach() diff --git a/src/unit_tests/os_integrator/test_integrator.c b/src/unit_tests/os_integrator/test_integrator.c deleted file mode 100644 index 7ce3c937e87..00000000000 --- a/src/unit_tests/os_integrator/test_integrator.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../headers/shared.h" -#include "../os_integrator/integrator.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" - -static int test_setup(void **state) { - test_mode = 1; - - IntegratorConfig *virustotal_config = calloc(1, sizeof(IntegratorConfig)); - IntegratorConfig *pagerduty_config = calloc(1, sizeof(IntegratorConfig)); - - virustotal_config->name = "virustotal"; - virustotal_config->apikey = "123456"; - virustotal_config->group = "syscheck"; - virustotal_config->alert_format = "json"; - virustotal_config->enabled = 1; - - pagerduty_config->name = "pagerduty"; - pagerduty_config->apikey = "123456"; - pagerduty_config->group = "syscheck"; - pagerduty_config->enabled = 1; - pagerduty_config->max_log = 165; - pagerduty_config->alert_format = "json"; - pagerduty_config->options = "{\"location\":\"syscheck-X\"}"; - - state[0] = virustotal_config; - state[1] = pagerduty_config; - - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - test_mode = 0; - - (void) state; - - IntegratorConfig *virustotal_config = state[0]; - IntegratorConfig *pagerduty_config = state[1]; - - os_free(virustotal_config->path); - os_free(pagerduty_config->path); - - os_free(virustotal_config); - os_free(pagerduty_config); - - return OS_SUCCESS; -} - -void test_OS_IntegratorD(void **state) { - IntegratorConfig *integrator_config[3]; - integrator_config[0] = state[0]; - integrator_config[1] = state[1]; - integrator_config[2] = NULL; - - wfd_t *wfd = NULL; - os_calloc(1, sizeof(wfd_t), wfd); - wfd->file_out = (FILE *)1; - - const char *al_string = "{\"timestamp\":\"2022-09-09T23:43:15.168+0200\",\"rule\":{\"level\":7,\"description\":\"Integrity checksum changed.\",\"id\":\"550\",\"mitre\":{\"id\":[\"T1565.001\"],\"tactic\":[\"Impact\"],\"technique\":[\"Stored Data Manipulation\"]},\"firedtimes\":2,\"mail\":false,\"groups\":[\"ossec\",\"syscheck\",\"syscheck_entry_modified\",\"syscheck_file\"],\"pci_dss\":[\"11.5\"],\"gpg13\":[\"4.11\"],\"gdpr\":[\"II_5.1.f\"],\"hipaa\":[\"164.312.c.1\",\"164.312.c.2\"],\"nist_800_53\":[\"SI.7\"],\"tsc\":[\"PI1.4\",\"PI1.5\",\"CC6.1\",\"CC6.8\",\"CC7.2\",\"CC7.3\"]},\"agent\":{\"id\":\"000\",\"name\":\"jellyfish\"},\"manager\":{\"name\":\"jellyfish\"},\"id\":\"1662759795.647670\",\"cluster\":{\"name\":\"wazuh\",\"node\":\"node01\"},\"full_log\":\"File '/tmp/test/test.txt' modified\nMode: realtime\nChanged attributes: size,mtime,md5,sha1,sha256\nSize changed from '54' to '57'\nOld modification time was: '1662759745', now it is '1662759795'\nOld md5sum was: '1e6f0765ec3e57572afde86319d460bf'\nNew md5sum is : '5192496b8adc2f0d705ca01bf3b4adba'\nOld sha1sum was: '652c1e4a301df0d1e7236689cb1e0bd071f2ea14'\nNew sha1sum is : 'dc090d4e165df77333ccf6adaf0d4f96541fb22b'\nOld sha256sum was: '1b32b746fe70a01ddd274f6b71bfaffd8a7fcd8023e18516078f31184da1135c'\nNew sha256sum is : '5583bbc9f63d24e44bbe34298d2f8421da25cdaada00e6c9ac765a16ded4204b'\n\",\"syscheck\":{\"path\":\"/tmp/test/test.txt\",\"mode\":\"realtime\",\"size_before\":\"54\",\"size_after\":\"57\",\"perm_after\":\"rw-r--r--\",\"uid_after\":\"0\",\"gid_after\":\"0\",\"md5_before\":\"1e6f0765ec3e57572afde86319d460bf\",\"md5_after\":\"5192496b8adc2f0d705ca01bf3b4adba\",\"sha1_before\":\"652c1e4a301df0d1e7236689cb1e0bd071f2ea14\",\"sha1_after\":\"dc090d4e165df77333ccf6adaf0d4f96541fb22b\",\"sha256_before\":\"1b32b746fe70a01ddd274f6b71bfaffd8a7fcd8023e18516078f31184da1135c\",\"sha256_after\":\"5583bbc9f63d24e44bbe34298d2f8421da25cdaada00e6c9ac765a16ded4204b\",\"uname_after\":\"root\",\"gname_after\":\"root\",\"mtime_before\":\"2022-09-09T23:42:25\",\"mtime_after\":\"2022-09-09T23:43:15\",\"inode_after\":2362547,\"changed_attributes\":[\"size\",\"mtime\",\"md5\",\"sha1\",\"sha256\"],\"event\":\"modified\"},\"decoder\":{\"name\":\"syscheck_integrity_changed\"},\"location\":\"syscheck\"}"; - const char *op_string = "{\"location\":\"syscheck-X\"}"; - - cJSON *al_json = NULL; - cJSON *op_json = NULL; - al_json = cJSON_Parse(al_string); - op_json = cJSON_Parse(op_string); - char *unformatted = cJSON_PrintUnformatted(al_json); - char *op_unformatted = cJSON_PrintUnformatted(op_json); - char alert_to_virustotal[2048]; - char alert_to_pagerduty[2048]; - char options_to_pd[512]; - snprintf(alert_to_virustotal, 2048, "%s\n",unformatted); - snprintf(alert_to_pagerduty, 2048, "%s\n",unformatted); - snprintf(options_to_pd, 512, "%s\n",op_unformatted); - - const char *virustotal_file = "/tmp/virustotal-1111-2222.alert"; - const char *pagerduty_file = "/tmp/pagerduty-1111-2222.alert"; - - const char *pd_options = "/tmp/pagerduty-1111-2222.options"; - - will_return(__wrap_jqueue_open, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "JSON file queue connected."); - - expect_string(__wrap_File_DateofChange, file, "integrations/virustotal"); - will_return(__wrap_File_DateofChange, 1); - - expect_string(__wrap__minfo, formatted_msg, "Enabling integration for: 'virustotal'."); - - expect_string(__wrap_File_DateofChange, file, "integrations/pagerduty"); - will_return(__wrap_File_DateofChange, 1); - - expect_string(__wrap__minfo, formatted_msg, "Enabling integration for: 'pagerduty'."); - - will_return(__wrap_FOREVER, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "jqueue_next()"); - - will_return(__wrap_jqueue_next, al_json); - - expect_string(__wrap__mdebug1, formatted_msg, "Sending new alert."); - - will_return(__wrap_time, 1111); - - will_return(__wrap_os_random, 2222); - - expect_string(__wrap_wfopen, path, virustotal_file); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)1); - - expect_fprintf((FILE *)1, alert_to_virustotal, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "File /tmp/virustotal-1111-2222.alert was written."); - - expect_fclose((FILE *)1, 0); - - will_return(__wrap_time, 1111); - will_return(__wrap_os_random, 2222); - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "test"); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, 0); - - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Command ran successfully."); - - expect_string(__wrap_unlink, file, virustotal_file); - will_return(__wrap_unlink, 0); - - will_return(__wrap_time, 1111); - will_return(__wrap_os_random, 2222); - - expect_string(__wrap_wfopen, path, pagerduty_file); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)1); - - expect_fprintf((FILE *)1, alert_to_pagerduty, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "File /tmp/pagerduty-1111-2222.alert was written."); - - expect_fclose((FILE *)1, 0); - - expect_string(__wrap_wfopen, path, pd_options); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)1); - - expect_fprintf((FILE *)1, options_to_pd, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "File /tmp/pagerduty-1111-2222.options was written."); - - expect_fclose((FILE *)1, 0); - - will_return(__wrap_wpopenv, wfd); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "test"); - - expect_value(__wrap_fgets, __stream, wfd->file_out); - will_return(__wrap_fgets, 0); - - will_return(__wrap_wpclose, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Command ran successfully."); - - expect_string(__wrap_unlink, file, pagerduty_file); - will_return(__wrap_unlink, 0); - expect_string(__wrap_unlink, file, pd_options); - will_return(__wrap_unlink, 0); - - will_return(__wrap_FOREVER, NULL); - - OS_IntegratorD(integrator_config); - - os_free(wfd); - os_free(unformatted); - os_free(op_unformatted); - cJSON_Delete(op_json); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_OS_IntegratorD, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_maild/CMakeLists.txt b/src/unit_tests/os_maild/CMakeLists.txt deleted file mode 100644 index 02ff68db48d..00000000000 --- a/src/unit_tests/os_maild/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Generate os_maild library -file(GLOB os_maild_files - ${SRC_FOLDER}/os_maild/*.o) -list(REMOVE_ITEM os_maild_files ${SRC_FOLDER}/os_maild/maild.o) - -add_library(OS_MAILD_O STATIC ${os_maild_files}) - -set_source_files_properties( - ${os_maild_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - OS_MAILD_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(OS_MAILD_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -# Include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate tests -list(APPEND os_maild_names "test_printtable") -list(APPEND os_maild_flags "${DEBUG_OP_WRAPPERS}") - -list(LENGTH os_maild_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET os_maild_names ${counter} os_maild_test_name) - list(GET os_maild_flags ${counter} os_maild_test_flags) - - add_executable(${os_maild_test_name} ${os_maild_test_name}.c) - - target_link_libraries( - ${os_maild_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - OS_MAILD_O - ${TEST_DEPS} - ) - - if(NOT os_maild_test_flags STREQUAL " ") - target_link_libraries( - ${os_maild_test_name} - ${os_maild_test_flags} - ) - endif() - add_test(NAME ${os_maild_test_name} COMMAND ${os_maild_test_name}) -endforeach() diff --git a/src/unit_tests/os_maild/test_printtable.c b/src/unit_tests/os_maild/test_printtable.c deleted file mode 100644 index b8e3584ac20..00000000000 --- a/src/unit_tests/os_maild/test_printtable.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../os_maild/maild.h" - -#define BODY_SIZE_INVARIANT (OS_MAXSTR - 3) - -/* Global variables */ -unsigned int mail_timeout; -unsigned int _g_subject_level; -char _g_subject[SUBJECT_SIZE + 2]; - -static void test_printtable_final_node(void **state) { - char logs[OS_MAXSTR + 1] = ""; - char tab[256] = "\t"; - size_t body_size = BODY_SIZE_INVARIANT; - cJSON *al_json = cJSON_Parse("{\"text\":\"Hello world.\"}"); - - PrintTable(al_json, logs, &body_size, tab, 2); - cJSON_Delete(al_json); - - assert_int_equal(strlen(logs) + body_size, BODY_SIZE_INVARIANT); -} - -static void test_printtable_array(void **state) { - char logs[OS_MAXSTR + 1] = ""; - char tab[256] = "\t"; - size_t body_size = BODY_SIZE_INVARIANT; - cJSON *al_json = cJSON_Parse("{\"array\":[1,2,3]}"); - - PrintTable(al_json, logs, &body_size, tab, 2); - cJSON_Delete(al_json); - - assert_int_equal(strlen(logs) + body_size, BODY_SIZE_INVARIANT); -} - -static void test_printtable_nested(void **state) { - char logs[OS_MAXSTR + 1] = ""; - char tab[256] = "\t"; - size_t body_size = BODY_SIZE_INVARIANT; - cJSON *al_json = cJSON_Parse("{\"data\":{\"text\":\"Hello world.\"}}"); - - PrintTable(al_json, logs, &body_size, tab, 2); - cJSON_Delete(al_json); - - assert_int_equal(strlen(logs) + body_size, BODY_SIZE_INVARIANT); -} - -static void test_printtable_nested_next(void **state) { - char logs[OS_MAXSTR + 1] = ""; - char tab[256] = "\t"; - size_t body_size = BODY_SIZE_INVARIANT; - cJSON *al_json = cJSON_Parse("{\"nothing\":{},\"data\":{\"text\":\"Hello world.\"}}"); - - PrintTable(al_json, logs, &body_size, tab, 2); - cJSON_Delete(al_json); - - assert_int_equal(strlen(logs) + body_size, BODY_SIZE_INVARIANT); -} - -static void test_printtable_max_tabs(void **state) { - char logs[OS_MAXSTR + 1] = ""; - char tab[256] = "\t"; - size_t body_size = BODY_SIZE_INVARIANT; - cJSON *al_json = cJSON_Parse("{\"first\":{\"second\":{\"third\":{\"fourth\":{\"fiveth\":{\"sixth-a\":\"Hello\"},\"sixth-b\":\"World\"}}}}}"); - - PrintTable(al_json, logs, &body_size, tab, 2); - cJSON_Delete(al_json); - - assert_int_equal(strlen(logs) + body_size, BODY_SIZE_INVARIANT); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_printtable_final_node), - cmocka_unit_test(test_printtable_array), - cmocka_unit_test(test_printtable_nested), - cmocka_unit_test(test_printtable_nested_next), - cmocka_unit_test(test_printtable_max_tabs), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/os_net/CMakeLists.txt b/src/unit_tests/os_net/CMakeLists.txt deleted file mode 100644 index b7e69a170bd..00000000000 --- a/src/unit_tests/os_net/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -# Generate os_net library -file(GLOB os_net_files - ${SRC_FOLDER}/os_net/*.o) - -add_library(OS_NET_O STATIC ${os_net_files}) - -set_source_files_properties( - ${os_net_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - OS_NET_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(OS_NET_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate os_net tests -list(APPEND os_net_names "test_os_net") -list(APPEND os_net_flags "-Wl,--wrap,socket -Wl,--wrap,listen -Wl,--wrap,bind -Wl,--wrap,setsockopt \ - -Wl,--wrap,getsockopt -Wl,--wrap,connect -Wl,--wrap,accept -Wl,--wrap,send \ - -Wl,--wrap,recv -Wl,--wrap,recvfrom -Wl,--wrap,chmod -Wl,--wrap,chown -Wl,--wrap,getuid -Wl,--wrap,getgid -Wl,--wrap,stat -Wl,--wrap,fcntl \ - -Wl,--wrap,getaddrinfo -Wl,--wrap,OS_IsValidIP -Wl,--wrap,OS_GetIPv4FromIPv6 -Wl,--wrap,OS_ExpandIPv6 \ - -Wl,--wrap,sleep -Wl,--wrap,getpid ${DEBUG_OP_WRAPPERS}") - -# Compiling tests -list(LENGTH os_net_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET os_net_names ${counter} test_name) - list(GET os_net_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - OS_NET_O - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/os_net/test_os_net.c b/src/unit_tests/os_net/test_os_net.c deleted file mode 100644 index a45d07a0d75..00000000000 --- a/src/unit_tests/os_net/test_os_net.c +++ /dev/null @@ -1,1070 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "os_err.h" -#include "sym_load.h" -#include "../../data_provider/include/sysInfo.h" -#include "../../headers/shared.h" -#include "../../os_net/os_net.h" - -#include "../wrappers/common.h" -#include "../wrappers/linux/socket_wrappers.h" -#include "../wrappers/posix/stat_wrappers.h" -#include "../wrappers/wazuh/shared/validate_op_wrappers.h" - -#define IPV4 "127.0.0.1" -#define IPV6 "::1" -#define IPV6_LINK_LOCAL "FE80:0000:0000:0000:ABCD:ABCD:ABCD:ABCD" -#define PORT 4321 -#define SENDSTRING "Hello World!\n" -#define BUFFERSIZE 1024 - -int __wrap_getuid(void) { - return mock(); -} - -int __wrap_getgid(void) { - return mock(); -} - -// Structs - -typedef struct test_struct { - int server_root_socket; - int server_client_socket; - int client_socket; - int server_socket; - int timeout; - char *ret; - char *msg; - char socket_path[256]; - struct addrinfo *addr; -} test_struct_t; - -// Setup / Teardown - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - - os_calloc(1, sizeof(struct addrinfo), init_data->addr); - os_calloc(1, sizeof(struct sockaddr), init_data->addr->ai_addr); - init_data->timeout = 1; - - strncpy(init_data->socket_path, "/tmp/tmp_file-XXXXXX", 256); - - *state = init_data; - - test_mode = 1; - - return OS_SUCCESS; -} - -static int test_teardown(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - unlink(data->socket_path); - - os_free(data->addr->ai_addr); - os_free(data->addr); - - os_free(data->msg); - os_free(data->ret); - os_free(data); - - test_mode = 0; - - return OS_SUCCESS; -} - -// Tests - -void test_bind_TCP_port_ipv4(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_bind, 1); - will_return(__wrap_setsockopt, 0); - will_return(__wrap_listen, 0); - - data->server_root_socket = OS_Bindporttcp(PORT, IPV4, 0); - assert_return_code(data->server_root_socket, 0); -} - -void test_bind_TCP_port_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_bind, 1); - will_return(__wrap_setsockopt, 0); - will_return(__wrap_listen, 0); - - data->server_root_socket = OS_Bindporttcp(PORT, NULL, 0); - assert_return_code(data->server_root_socket, 0); -} - -void test_bind_TCP_port_ipv6(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_bind, 1); - will_return(__wrap_setsockopt, 0); - will_return(__wrap_listen, 0); - - data->server_root_socket = OS_Bindporttcp(PORT, IPV6, 1); - assert_return_code(data->server_root_socket, 0); -} - -void test_connect_TCP_ipv4(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 4); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - data->client_socket = OS_ConnectTCP(PORT, IPV4, 0, 0); - assert_return_code(data->client_socket , 0); -} - -void test_connect_TCP_ipv6(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - data->client_socket = OS_ConnectTCP(PORT, IPV6, 1, 0); - assert_return_code(data->client_socket , 0); -} - -void test_connect_TCP_ipv6_link_local_no_interface(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - expect_string(__wrap__minfo, formatted_msg, "No network interface provided to use with link-local IPv6 address."); - - data->client_socket = OS_ConnectTCP(PORT, IPV6_LINK_LOCAL, 1, 0); - assert_return_code(data->client_socket , 0); -} - -void test_connect_TCP_ipv6_link_local_with_interface(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - data->client_socket = OS_ConnectTCP(PORT, IPV6_LINK_LOCAL, 1, 1); - assert_return_code(data->client_socket , 0); -} - -void test_accept_TCP(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char ipbuffer[BUFFERSIZE]; - - data->server_root_socket = 0; - will_return(__wrap_accept, AF_INET); - will_return(__wrap_accept, 0); - - data->server_client_socket = OS_AcceptTCP(data->server_root_socket, ipbuffer, BUFFERSIZE); - assert_return_code(data->server_client_socket, 0); - - assert_string_equal(ipbuffer, "0.0.0.0"); -} - -void test_invalid_accept_TCP(void **state) { - char buffer[BUFFERSIZE]; - - will_return(__wrap_accept, AF_INET); - will_return(__wrap_accept, -1); - - assert_int_equal(OS_AcceptTCP(-1, buffer, BUFFERSIZE), -1); -} - -void test_send_TCP(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->client_socket = 3; - will_return(__wrap_send, 1); - - assert_int_equal(OS_SendTCP(data->client_socket, SENDSTRING), 0); -} - -void test_invalid_send_TCP(void **state) { - will_return(__wrap_send, -6); - assert_int_equal(OS_SendTCP(-1, SENDSTRING), OS_SOCKTERR); -} - -void test_send_secure_TCP(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char ipbuffer[BUFFERSIZE]; - - data->client_socket = 3; - will_return(__wrap_send, 17); - - assert_int_equal(OS_SendSecureTCP(data->client_socket, strlen(SENDSTRING), SENDSTRING), 0); -} - -void test_send_TCP_by_size(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->server_client_socket = 4; - will_return(__wrap_send, 6); - - assert_int_equal(OS_SendTCPbySize(data->server_client_socket, 5, SENDSTRING), 0); -} - -void test_invalid_send_TCP_by_size(void **state) { - will_return(__wrap_send, -6); - - assert_int_equal(OS_SendTCPbySize(-1, strlen(SENDSTRING), SENDSTRING), OS_SOCKTERR); -} - -void test_recv_TCP_buffer(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char buffer[BUFFERSIZE]; - - data->server_client_socket = 4; - will_return(__wrap_recv, 13); - - assert_int_equal(OS_RecvTCPBuffer(data->server_client_socket, buffer, BUFFERSIZE), 13); - assert_string_equal(buffer, SENDSTRING); -} - -void test_invalid_recv_TCP_buffer(void **state) { - char buffer[BUFFERSIZE]; - will_return(__wrap_recv, -1); - - assert_int_equal(OS_RecvTCPBuffer(-1, buffer, BUFFERSIZE), -1); -} - -void test_recv_TCP(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->client_socket = 3; - will_return(__wrap_recv, 1); - - data->msg = OS_RecvTCP(data->client_socket, BUFFERSIZE); - assert_non_null(data->msg); - - assert_string_equal(data->msg, SENDSTRING); -} - -void test_invalid_recv_TCP(void **state) { - will_return(__wrap_recv, NULL); - assert_null(OS_RecvTCP(-1, BUFFERSIZE)); -} - -void test_recv_secure_TCP(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char buffer[BUFFERSIZE]; - - data->client_socket = 5; - will_return(__wrap_recv, 4); - will_return(__wrap_recv, 13); - - assert_int_equal(OS_RecvSecureTCP(data->client_socket, buffer, BUFFERSIZE), 13); - - assert_string_equal(buffer, SENDSTRING); -} - -void test_tcp_invalid_sockets(void **state) { - char buffer[BUFFERSIZE]; - will_return(__wrap_accept, AF_INET); - will_return(__wrap_accept, -1); - - assert_int_equal(OS_AcceptTCP(-1, buffer, BUFFERSIZE), -1); -} - -void test_bind_UDP_port_ipv4(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_bind, 1); - - data->server_socket = OS_Bindportudp(PORT, IPV4, 0); - assert_return_code(data->server_socket, 0); -} - -void test_bind_UDP_port_ipv6(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_bind, 1); - - data->server_socket = OS_Bindportudp(PORT, IPV6, 1); - assert_return_code(data->server_socket, 0); -} - -void test_connect_UDP_ipv4(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 4); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - data->client_socket = OS_ConnectUDP(PORT, IPV4, 0, 0); - assert_return_code(data->client_socket , 0); -} - -void test_connect_UDP_ipv6(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 4); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - data->client_socket = OS_ConnectUDP(PORT, IPV6, 1, 0); - assert_return_code(data->client_socket , 0); -} - -void test_connect_UDP_ipv6_link_local_no_interface(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - expect_string(__wrap__minfo, formatted_msg, "No network interface provided to use with link-local IPv6 address."); - - data->client_socket = OS_ConnectUDP(PORT, IPV6_LINK_LOCAL, 1, 0); - assert_return_code(data->client_socket , 0); -} - -void test_connect_UDP_ipv6_link_local_with_interface(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_socket, 3); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_getsockopt, 0); - - data->client_socket = OS_ConnectUDP(PORT, IPV6_LINK_LOCAL, 1, 1); - assert_return_code(data->client_socket , 0); -} - -void test_send_UDP_by_size(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->server_client_socket = 4; - will_return(__wrap_send, 1); - - assert_int_equal(OS_SendUDPbySize(data->client_socket, strlen(SENDSTRING), SENDSTRING), 0); -} - -void test_recv_conn_UDP(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char buffer[BUFFERSIZE + 1]; - - data->server_client_socket = 4; - will_return(__wrap_recv, 13); - - assert_int_equal(OS_RecvConnUDP(data->server_socket, buffer, BUFFERSIZE), strlen(SENDSTRING)); -} - -void test_recv_UDP(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->server_client_socket = 4; - will_return(__wrap_recv, 1); - - data->msg = OS_RecvUDP(data->server_client_socket, BUFFERSIZE); - assert_non_null(data->msg); - - assert_string_equal(data->msg, SENDSTRING); -} - -void test_udp_recv_conn_invalid_sockets(void **state) { - char buffer[BUFFERSIZE + 1]; - will_return(__wrap_recv, -1); - - assert_int_equal(OS_RecvConnUDP(-1, buffer, BUFFERSIZE), 0); -} - -void test_udp_send_invalid_sockets(void **state) { - will_return(__wrap_send, -1); - assert_int_equal(OS_SendUDPbySize(-1, strlen(SENDSTRING), SENDSTRING), OS_SOCKTERR); -} - -void test_udp_recv_invalid_sockets(void **state) { - will_return(__wrap_recv, -1); - assert_null(OS_RecvUDP(-1, BUFFERSIZE)); -} - -void test_recv_unix_invalid_sockets(void **state) { - char buffer[BUFFERSIZE]; - will_return(__wrap_recvfrom, 0); - - assert_int_equal(OS_RecvUnix(-1, BUFFERSIZE - 1, buffer), 0); -} - -void test_send_unix_invalid_sockets(void **state) { - will_return(__wrap_send, -1); - assert_int_equal(OS_SendUnix(-1, SENDSTRING, strlen(SENDSTRING)), OS_SOCKTERR); -} - -void test_gethost_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *hostname = "google-public-dns-a.google.com"; - - data->addr->ai_family = AF_INET; - struct sockaddr_in *ipv4 = (struct sockaddr_in *)data->addr->ai_addr; - ipv4->sin_addr.s_addr = 134744072; - - expect_string(__wrap_getaddrinfo, node, hostname); - will_return(__wrap_getaddrinfo, data->addr); - will_return(__wrap_getaddrinfo, 0); - - data->ret = OS_GetHost(hostname, 2); - - assert_non_null(data->ret); - assert_string_equal(data->ret, "8.8.8.8"); -} - -void test_gethost_null(void **state) { - assert_null(OS_GetHost(NULL, 2)); -} - -void test_gethost_not_exists(void **state) { - char *hostname = "this.should.not.exist"; - - expect_string_count(__wrap_getaddrinfo, node, hostname, 3); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - - expect_value_count(__wrap_sleep, seconds, 1, 3); - - assert_null(OS_GetHost(hostname, 2)); -} - -void test_bind_unix_domain(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const int msg_size = 1; - - will_return(__wrap_getuid, 0); - will_return(__wrap_getgid, 995); - will_return(__wrap_socket, 3); - will_return(__wrap_bind, 1); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_fcntl, 0); - - expect_string(__wrap_chmod, path, data->socket_path); - will_return(__wrap_chmod, 0); - expect_string(__wrap_chown, __file, data->socket_path); - expect_value(__wrap_chown, __owner, 0); - expect_value(__wrap_chown, __group, 995); - will_return(__wrap_chown, 0); - - data->server_socket = OS_BindUnixDomain(data->socket_path, SOCK_DGRAM, msg_size); - assert_return_code(data->server_socket, 0); -} - -void test_getsocketsize(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const int msg_size = 1; - - will_return(__wrap_getsockopt, 0); - - assert_return_code(OS_getsocketsize(data->server_socket), msg_size); -} - -void test_connect_unix_domain(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const int msg_size = 1; - - will_return(__wrap_socket, 4); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_fcntl, 0); - - data->client_socket = OS_ConnectUnixDomain(data->socket_path, SOCK_DGRAM, msg_size); - assert_return_code(data->client_socket , 0); -} - -void test_send_unix(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->client_socket = 3; - will_return(__wrap_send, 15); - - assert_int_equal(OS_SendUnix(data->client_socket, SENDSTRING, 0), 0); -} - -void test_recv_unix(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char buffer[BUFFERSIZE]; - - data->server_client_socket = 4; - will_return(__wrap_recvfrom, 14); - - assert_int_equal(OS_RecvUnix(data->server_socket, BUFFERSIZE - 1, buffer), strlen(SENDSTRING) + 1); - assert_string_equal(buffer, SENDSTRING); -} - -void test_send_secure_TCP_cluster_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - char req[] = "command"; - data->client_socket = 3; - - will_return(__wrap_send, 5); - assert_int_equal(OS_SendSecureTCPCluster(data->client_socket, req , SENDSTRING, strlen(SENDSTRING)) , OS_SOCKTERR); -} - -void test_send_secure_TCP_cluster_command_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->client_socket = 3; - - expect_string(__wrap__merror, formatted_msg, "Empty command, not sending message to cluster"); - assert_int_equal(OS_SendSecureTCPCluster(data->client_socket, NULL , SENDSTRING, strlen(SENDSTRING)), -1); -} - -void test_send_secure_TCP_cluster_max_payload_exceeded(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - const unsigned MAX_PAYLOAD_SIZE = 1000001; - - char req[] = "command"; - data->client_socket = 3; - - expect_string(__wrap__merror, formatted_msg, "Data of length 1000001 exceeds maximum allowed 1000000"); - assert_int_equal(OS_SendSecureTCPCluster(data->client_socket, req, SENDSTRING, MAX_PAYLOAD_SIZE), -1); -} - -void test_send_secure_TCP_cluster_command_size_exceeded(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - const unsigned COMMAND_SIZE = 12; - - char req[] = "command size exceeded"; - data->client_socket = 3; - - expect_string(__wrap__merror, formatted_msg, "Command of length 21 exceeds maximum allowed 12"); - assert_int_equal(OS_SendSecureTCPCluster(data->client_socket, req, SENDSTRING, strlen(SENDSTRING)), -1); -} - -void test_recv_secure_cluster_TCP_socket_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char ret [BUFFERSIZE]; - - will_return(__wrap_recv, -1); - data->client_socket = -1; - - assert_int_equal(OS_RecvSecureClusterTCP(data->client_socket, ret, sizeof(ret)), -1); -} - -void test_recv_secure_cluster_TCP_socket_disconected_or_timeout(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char ret [BUFFERSIZE]; - - will_return(__wrap_recv, 0); - data->client_socket = -1; - - assert_int_equal(OS_RecvSecureClusterTCP(data->client_socket, ret, sizeof(ret)), 0); -} - -void test_recv_secure_cluster_TCP_wrong_header(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char ret [BUFFERSIZE]; - - will_return_always(__wrap_recv, 7); - data->client_socket = -1; - - assert_int_equal(OS_RecvSecureClusterTCP(data->client_socket, ret, sizeof(ret)), -1); -} - -void test_recv_secure_cluster_TCP_cmd_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char ret [BUFFERSIZE]; - - will_return_always(__wrap_recv, 20); - data->client_socket = 7; - - assert_int_equal(OS_RecvSecureClusterTCP(data->client_socket, ret, sizeof(ret)), -2); -} - -void test_resolve_hostname_success(void ** state){ - test_struct_t *data = (test_struct_t *)*state; - - data->addr->ai_family = AF_INET; - struct sockaddr_in *ipv4 = (struct sockaddr_in *)data->addr->ai_addr; - ipv4->sin_addr.s_addr = 134744072; - - os_strdup("localhost", data->ret); - - expect_string(__wrap_getaddrinfo, node, "localhost"); - will_return(__wrap_getaddrinfo, data->addr); - will_return(__wrap_getaddrinfo, 0); - - expect_string(__wrap_OS_IsValidIP, ip_address, data->ret); - expect_value(__wrap_OS_IsValidIP, final_ip, NULL); - will_return(__wrap_OS_IsValidIP, 0); - - resolve_hostname(&data->ret, 5); - - assert_string_equal(data->ret, "localhost/8.8.8.8"); -} - -void test_resolve_hostname_valid_ip(void ** state){ - char *hostname = "8.8.8.8"; - - expect_string(__wrap_OS_IsValidIP, ip_address, hostname); - expect_value(__wrap_OS_IsValidIP, final_ip, NULL); - will_return(__wrap_OS_IsValidIP, 1); - - resolve_hostname(&hostname, 5); -} - -void test_resolve_hostname_not_resolved(void ** state){ - test_struct_t *data = (test_struct_t *)*state; - - os_strdup("localhost", data->ret); - - expect_string(__wrap_OS_IsValidIP, ip_address, data->ret); - expect_value(__wrap_OS_IsValidIP, final_ip, NULL); - will_return(__wrap_OS_IsValidIP, 0); - - expect_string_count(__wrap_getaddrinfo, node, "localhost", 6); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - will_return(__wrap_getaddrinfo, NULL); - will_return(__wrap_getaddrinfo, -1); - - expect_value_count(__wrap_sleep, seconds, 1, 6); - - resolve_hostname(&data->ret, 5); - - assert_string_equal(data->ret, "localhost/"); -} - -void test_get_ip_from_resolved_hostname_ip(void ** state){ - const char *resolved_hostname = "localhost/8.8.8.8"; - - const char *ret = get_ip_from_resolved_hostname(resolved_hostname); - - assert_string_equal(ret, "8.8.8.8"); -} - -void test_get_ip_from_resolved_hostname_no_ip(void ** state){ - const char *resolved_hostname = "localhost/"; - - const char *ret = get_ip_from_resolved_hostname(resolved_hostname); - - assert_string_equal(ret, ""); -} - -// Tests external_socket_connect - -void test_external_socket_connect_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const int msg_size = 1; - - will_return(__wrap_socket, 4); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_fcntl, 0); - will_return(__wrap_setsockopt, 0); - will_return(__wrap_setsockopt, 0); - - int ret = external_socket_connect(data->socket_path, data->timeout); - assert_int_equal(ret, 4); -} - - -void test_external_socket_connect_failed_sent_timeout(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const int msg_size = 1; - - will_return(__wrap_socket, 4); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_fcntl, 0); - will_return(__wrap_setsockopt, -1); - - int ret = external_socket_connect(data->socket_path, data->timeout); - assert_int_equal(ret, -1); -} - -void test_external_socket_connect_failed_receive_timeout(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const int msg_size = 1; - - will_return(__wrap_socket, 4); - will_return(__wrap_connect, 0); - will_return(__wrap_getsockopt, 0); - will_return(__wrap_fcntl, 0); - will_return(__wrap_setsockopt, 0); - will_return(__wrap_setsockopt, -1); - - int ret = external_socket_connect(data->socket_path, data->timeout); - assert_int_equal(ret, -1); -} - -void get_ipv4_string_fail_size(void ** state) { - - char address[IPSIZE] = {0}; - struct in_addr addr; - -#ifndef WIN32 - addr.s_addr = 0x0F0F0F0F; -#else - addr.u.Byte = 0x0F0F0F0F; -#endif - - int ret = get_ipv4_string(addr, address, 1); - - assert_string_equal(address, ""); - assert_int_equal(ret, OS_INVALID); -} - -void get_ipv4_string_success(void ** state) { - - char address[IPSIZE] = {0}; - struct in_addr addr; - -#ifndef WIN32 - addr.s_addr = 0x0F0F0F0F; -#else - addr.u.Byte = 0x0F0F0F0F; -#endif - - int ret = get_ipv4_string(addr, address, IPSIZE); - - assert_string_equal(address, "15.15.15.15"); - assert_int_equal(ret, OS_SUCCESS); -} - -void get_ipv6_string_fail_size(void ** state) { - - char address[IPSIZE] = {0}; - struct in6_addr addr6; - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - addr6.s6_addr[i] = 0x00; -#else - addr6.u.Byte[i] = 0x00; -#endif - } - - int ret = get_ipv6_string(addr6, address, 1); - - assert_string_equal(address, ""); - assert_int_equal(ret, OS_INVALID); -} - -void get_ipv6_string_success(void ** state) { - - char address[IPSIZE] = {0}; - struct in6_addr addr6; - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - addr6.s6_addr[i] = 0x10; -#else - addr6.u.Byte[i] = 0x10; -#endif - - } - - expect_string(__wrap_OS_GetIPv4FromIPv6, ip_address, "1010:1010:1010:1010:1010:1010:1010:1010"); - expect_value(__wrap_OS_GetIPv4FromIPv6, size, IPSIZE); - will_return(__wrap_OS_GetIPv4FromIPv6, 0); - - expect_string(__wrap_OS_ExpandIPv6, ip_address, "1010:1010:1010:1010:1010:1010:1010:1010"); - expect_value(__wrap_OS_ExpandIPv6, size, IPSIZE); - will_return(__wrap_OS_ExpandIPv6, 0); - - int ret = get_ipv6_string(addr6, address, IPSIZE); - - assert_string_equal(address, "1010:1010:1010:1010:1010:1010:1010:1010"); - assert_int_equal(ret, OS_SUCCESS); -} - -void get_ipv4_numeric_fail(void ** state) { - - const char *address = "Not a valid IP"; - struct in_addr addr; - -#ifndef WIN32 - addr.s_addr = 0; -#else - addr.u.Byte = 0; -#endif - - int ret = get_ipv4_numeric(address, &addr); - - assert_int_equal(ret, OS_INVALID); -} - -void get_ipv4_numeric_success(void ** state) { - - const char *address = "15.15.15.15"; - struct in_addr addr; - -#ifndef WIN32 - addr.s_addr = 0; -#else - addr.u.Byte = 0; -#endif - - int ret = get_ipv4_numeric(address, &addr); - - assert_int_equal(ret, OS_SUCCESS); - -#ifndef WIN32 - assert_int_equal(addr.s_addr, 0x0F0F0F0F); -#else - assert_int_equal(addr.u.Byte, 0x0F0F0F0F); -#endif -} - -void get_ipv6_numeric_fail(void ** state) { - - const char *address = "Not a valid IP"; - struct in6_addr addr6; - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - addr6.s6_addr[i] = 0; -#else - addr6.u.Byte[i] = 0; -#endif - } - - int ret = get_ipv6_numeric(address, &addr6); - - assert_int_equal(ret, OS_INVALID); - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - assert_int_equal(addr6.s6_addr[i], 0); -#else - assert_int_equal(addr6.u.Byte[i], 0); -#endif - } -} - -void get_ipv6_numeric_success(void ** state) { - - const char *address = "1010:1010:1010:1010:1010:1010:1010:1010"; - struct in6_addr addr6; - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - addr6.s6_addr[i] = 0; -#else - addr6.u.Byte[i] = 0; -#endif - } - - int ret = get_ipv6_numeric(address, &addr6); - - assert_int_equal(ret, OS_SUCCESS); - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - assert_int_equal(addr6.s6_addr[i], 0x10); -#else - assert_int_equal(addr6.u.Byte[i], 0x10); -#endif - } -} - -void get_ipv6_numeric_compare_compres_ipv6(void ** state) { - - const char *address = "fd17:625c:f037::45ea:97eb"; - const char *address2 = "fd17:625c:f037:0:0:0:45ea:97eb"; - - struct in6_addr addr6; - struct in6_addr addr6_2; - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - addr6.s6_addr[i] = 0; - addr6_2.s6_addr[i] = 0; -#else - addr6.u.Byte[i] = 0; - addr6_2.u.Byte[i] = 0; -#endif - } - - int ret = get_ipv6_numeric(address, &addr6); - - assert_int_equal(ret, OS_SUCCESS); - - ret = get_ipv6_numeric(address2, &addr6_2); - - assert_int_equal(ret, OS_SUCCESS); - - for(unsigned int i = 0; i < 16 ; i++) { -#ifndef WIN32 - assert_int_equal(addr6.s6_addr[i], addr6_2.s6_addr[i]); -#else - assert_int_equal(addr6.u.Byte[i], addr6_2.u.Byte[i]); -#endif - } -} - -int main(void) { - const struct CMUnitTest tests[] = { - /* Bind a TCP port */ - cmocka_unit_test_setup_teardown(test_bind_TCP_port_ipv4, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_bind_TCP_port_null, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_bind_TCP_port_ipv6, test_setup, test_teardown), - - /* Open a TCP socket */ - cmocka_unit_test_setup_teardown(test_connect_TCP_ipv4, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_connect_TCP_ipv6, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_connect_TCP_ipv6_link_local_no_interface, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_connect_TCP_ipv6_link_local_with_interface, test_setup, test_teardown), - - /* Accept a TCP connection */ - cmocka_unit_test_setup_teardown(test_accept_TCP, test_setup, test_teardown), - cmocka_unit_test(test_invalid_accept_TCP), - - /* Send a TCP packet */ - cmocka_unit_test_setup_teardown(test_send_TCP, test_setup, test_teardown), - cmocka_unit_test(test_invalid_send_TCP), - - /* Send secure TCP message */ - cmocka_unit_test_setup_teardown(test_send_secure_TCP, test_setup, test_teardown), - - /* Receive a TCP packet */ - cmocka_unit_test_setup_teardown(test_recv_TCP_buffer, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_recv_TCP, test_setup, test_teardown), - cmocka_unit_test(test_invalid_recv_TCP), - cmocka_unit_test(test_invalid_recv_TCP_buffer), - - /* Receive secure TCP message */ - cmocka_unit_test_setup_teardown(test_recv_secure_TCP, test_setup, test_teardown), - - /* Send a TCP packet of a specific size */ - cmocka_unit_test_setup_teardown(test_send_TCP_by_size, test_setup, test_teardown), - cmocka_unit_test(test_invalid_send_TCP_by_size), - cmocka_unit_test(test_tcp_invalid_sockets), - - /* Bind a UDP port */ - cmocka_unit_test_setup_teardown(test_bind_UDP_port_ipv4, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_bind_UDP_port_ipv6, test_setup, test_teardown), - - /* Open a UDP socket */ - cmocka_unit_test_setup_teardown(test_connect_UDP_ipv4, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_connect_UDP_ipv6, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_connect_UDP_ipv6_link_local_no_interface, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_connect_UDP_ipv6_link_local_with_interface, test_setup, test_teardown), - - /* Send a UDP packet */ - cmocka_unit_test_setup_teardown(test_send_UDP_by_size, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_udp_send_invalid_sockets, test_setup, test_teardown), - - /* Receive a UDP packet */ - cmocka_unit_test_setup_teardown(test_recv_conn_UDP, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_recv_UDP, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_udp_recv_conn_invalid_sockets, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_udp_recv_invalid_sockets, test_setup, test_teardown), - - /* Bind a unix domain */ - cmocka_unit_test_setup_teardown(test_bind_unix_domain, test_setup, test_teardown), - - /* Get current maximum size */ - cmocka_unit_test_setup_teardown(test_getsocketsize, test_setup, test_teardown), - - /* Connect unix domain */ - cmocka_unit_test_setup_teardown(test_connect_unix_domain, test_setup, test_teardown), - - /* Send a message using a Unix socket */ - cmocka_unit_test_setup_teardown(test_send_unix, test_setup, test_teardown), - cmocka_unit_test(test_send_unix_invalid_sockets), - - /* Receive a message using a Unix socket */ - cmocka_unit_test_setup_teardown(test_recv_unix, test_setup, test_teardown), - - /* Call OS_GetHost */ - cmocka_unit_test(test_gethost_null), - cmocka_unit_test(test_gethost_not_exists), - cmocka_unit_test_setup_teardown(test_gethost_success, test_setup, test_teardown), - - /* Send secure TCP Cluster message */ - cmocka_unit_test_setup_teardown(test_send_secure_TCP_cluster_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_send_secure_TCP_cluster_command_null, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_send_secure_TCP_cluster_max_payload_exceeded, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_send_secure_TCP_cluster_command_size_exceeded, test_setup, test_teardown), - - /* Receive secure TCP Cluster message */ - cmocka_unit_test_setup_teardown(test_recv_secure_cluster_TCP_socket_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_recv_secure_cluster_TCP_socket_disconected_or_timeout, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_recv_secure_cluster_TCP_wrong_header, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_recv_secure_cluster_TCP_cmd_error, test_setup, test_teardown), - - /* Test for resolve_hostname */ - cmocka_unit_test_setup_teardown(test_resolve_hostname_success, test_setup, test_teardown), - cmocka_unit_test(test_resolve_hostname_valid_ip), - cmocka_unit_test_setup_teardown(test_resolve_hostname_not_resolved, test_setup, test_teardown), - - /* Test for get_ip_from_resolved_hostname */ - cmocka_unit_test(test_get_ip_from_resolved_hostname_ip), - cmocka_unit_test(test_get_ip_from_resolved_hostname_no_ip), - - /* Test for external_socket_connect */ - cmocka_unit_test_setup_teardown(test_external_socket_connect_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_external_socket_connect_failed_sent_timeout, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_external_socket_connect_failed_receive_timeout, test_setup, test_teardown), - - /* Test get_ipv4_string */ - cmocka_unit_test(get_ipv4_string_fail_size), - cmocka_unit_test(get_ipv4_string_success), - - /* Test get_ipv6_string */ - cmocka_unit_test(get_ipv6_string_fail_size), - cmocka_unit_test(get_ipv6_string_success), - - /* Test get_ipv4_numeric */ - cmocka_unit_test(get_ipv4_numeric_fail), - cmocka_unit_test(get_ipv4_numeric_success), - - /* Test get_ipv6_numeric */ - cmocka_unit_test(get_ipv6_numeric_fail), - cmocka_unit_test(get_ipv6_numeric_success), - cmocka_unit_test(get_ipv6_numeric_compare_compres_ipv6), - - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/remoted/CMakeLists.txt b/src/unit_tests/remoted/CMakeLists.txt deleted file mode 100644 index 4b9468cc3d6..00000000000 --- a/src/unit_tests/remoted/CMakeLists.txt +++ /dev/null @@ -1,132 +0,0 @@ -# Generate remoted library -file(GLOB remoted_files - ${SRC_FOLDER}/remoted/*.o) - -add_compile_options("-g") - -add_library(REMOTED_O STATIC ${remoted_files}) - -set_source_files_properties( - ${remoted_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - REMOTED_O - PROPERTIES - LINKER_LANGUAGE C -) - -link_directories(${SRC_FOLDER}/build/shared_modules/router) -include_directories(${SRC_FOLDER}/shared_modules/router/include) -target_link_libraries(REMOTED_O ${WAZUHLIB} ${WAZUHEXT} -lpthread -lrouter) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate remoted tests -list(APPEND remoted_names "test_manager") -list(APPEND remoted_flags "-Wl,--wrap,_mdebug2 -Wl,--wrap,_mdebug1 -Wl,--wrap,w_parser_get_agent \ - -Wl,--wrap,_merror -Wl,--wrap,_merror_exit -Wl,--wrap,popen \ - -Wl,--wrap,MergeAppendFile -Wl,--wrap,OS_MoveFile -Wl,--wrap,w_parser_get_group \ - -Wl,--wrap,wurl_request -Wl,--wrap,TestUnmergeFiles -Wl,--wrap,OS_MD5_File \ - -Wl,--wrap,open_memstream -Wl,--wrap,OS_MD5_Str -Wl,--wrap,fprintf\ - -Wl,--wrap,OSHash_Delete_ex -Wl,--wrap,OSHash_Delete -Wl,--wrap,OSHash_Get \ - -Wl,--wrap,OSHash_Get_ex -Wl,--wrap,OSHash_Next -Wl,--wrap,OSHash_SetFreeDataPointer \ - -Wl,--wrap,OSHash_Update_ex -Wl,--wrap,OSHash_Update -Wl,--wrap,OSHash_Get_Elem_ex \ - -Wl,--wrap,OSHash_Create -Wl,--wrap,OSHash_Add -Wl,--wrap,OSHash_Add_ex \ - -Wl,--wrap,checkBinaryFile -Wl,--wrap,OSHash_Set -Wl,--wrap,_minfo \ - -Wl,--wrap,opendir -Wl,--wrap,cldir_ex_ignore -Wl,--wrap,wreaddir -Wl,--wrap=_mwarn \ - -Wl,--wrap,closedir -Wl,--wrap,OSHash_Clean -Wl,--wrap,rmdir_ex -Wl,--wrap,mkdir -Wl,--wrap,stat\ - -Wl,--wrap,OS_SHA256_String -Wl,--wrap,readdir -Wl,--wrap,strerror -Wl,--wrap,wfopen \ - -Wl,--wrap,fopen -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap,fclose -Wl,--wrap,remove \ - -Wl,--wrap,fgets -Wl,--wrap,fflush -Wl,--wrap,fseek -Wl,--wrap,fgetpos -Wl,--wrap=fgetc \ - -Wl,--wrap,w_copy_file -Wl,--wrap,OSHash_Begin -Wl,--wrap,OSHash_Begin_ex -Wl,--wrap,req_save -Wl,--wrap,send_msg \ - -Wl,--wrap,wdb_update_agent_keepalive -Wl,--wrap,parse_agent_update_msg \ - -Wl,--wrap,wdb_update_agent_data -Wl,--wrap,linked_queue_push_ex \ - -Wl,--wrap,wdb_update_agent_connection_status -Wl,--wrap,wdb_update_agent_status_code -Wl,--wrap,SendMSG -Wl,--wrap,StartMQ \ - -Wl,--wrap,get_ipv4_string -Wl,--wrap,get_ipv6_string \ - -Wl,--wrap,wdb_get_agent_group -Wl,--wrap,compare_wazuh_versions \ - -Wl,--wrap,wdb_set_agent_groups_csv -Wl,--wrap,w_is_single_node \ - -Wl,--wrap,wdb_get_all_agents -Wl,--wrap,wdb_get_agent_info \ - -Wl,--wrap,rem_inc_send_ack -Wl,--wrap,rem_inc_recv_ctrl_request -Wl,--wrap,rem_inc_recv_ctrl_keepalive \ - -Wl,--wrap,rem_inc_recv_ctrl_startup -Wl,--wrap,rem_inc_recv_ctrl_shutdown -Wl,--wrap,pthread_mutex_lock \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,wdb_get_distinct_agent_groups -Wl,--wrap,unlink -Wl,--wrap,getpid \ - -Wl,--wrap,w_create_sendsync_payload -Wl,--wrap,w_send_clustered_message") - -list(APPEND remoted_names "test_secure") -list(APPEND remoted_flags "-Wl,--wrap,_merror -Wl,--wrap,_mwarn -Wl,--wrap,accept -Wl,--wrap,close \ - -Wl,--wrap,fclose -Wl,--wrap,fcntl -Wl,--wrap,fflush -Wl,--wrap,fgetc \ - -Wl,--wrap,fgetpos -Wl,--wrap,fgets -Wl,--wrap,fopen -Wl,--wrap,popen -Wl,--wrap,fread \ - -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,getpid -Wl,--wrap,key_lock_read \ - -Wl,--wrap,key_lock_write -Wl,--wrap,key_unlock -Wl,--wrap,nb_close \ - -Wl,--wrap,nb_open -Wl,--wrap,nb_recv -Wl,--wrap,nb_send -Wl,--wrap,OS_AddSocket \ - -Wl,--wrap,OS_DeleteSocket -Wl,--wrap,OS_IsAllowedDynamicID -Wl,--wrap,OS_IsAllowedIP \ - -Wl,--wrap,ReadSecMSG -Wl,--wrap,recvfrom -Wl,--wrap,rem_add_recv \ - -Wl,--wrap,rem_add_send -Wl,--wrap,rem_dec_tcp -Wl,--wrap,wfopen \ - -Wl,--wrap,rem_getCounter -Wl,--wrap,rem_inc_recv_ctrl \ - -Wl,--wrap,rem_inc_recv_unknown -Wl,--wrap,rem_inc_tcp \ - -Wl,--wrap,rem_msgpush -Wl,--wrap,rem_setCounter -Wl,--wrap,remove \ - -Wl,--wrap,save_controlmsg -Wl,--wrap,sleep -Wl,--wrap,stat -Wl,--wrap,time \ - -Wl,--wrap,w_mutex_lock -Wl,--wrap,w_mutex_unlock \ - -Wl,--wrap,wnotify_add -Wl,--wrap,SendMSG -Wl,--wrap,rem_inc_recv_evt \ - -Wl,--wrap,OS_DupKeyEntry -Wl,--wrap,OS_FreeKey ${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,router_provider_send_fb ${HASH_OP_WRAPPERS}") - -list(APPEND remoted_names "test_netbuffer") -list(APPEND remoted_flags "-Wl,--wrap,_merror -Wl,--wrap,_mwarn -Wl,--wrap,_mdebug1 -Wl,--wrap,wnet_order -Wl,--wrap,wnotify_modify \ - -Wl,--wrap,bqueue_push -Wl,--wrap,bqueue_peek -Wl,--wrap,bqueue_drop -Wl,--wrap,bqueue_clear -Wl,--wrap,sleep \ - -Wl,--wrap,send -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,fcntl -Wl,--wrap,getpid \ - -Wl,--wrap,bqueue_used -Wl,--wrap,rem_inc_send_discarded -Wl,--wrap,recv -Wl,--wrap,rem_msgpush") - -list(APPEND remoted_names "test_sendmsg") -list(APPEND remoted_flags "${DEBUG_OP_WRAPPERS} -Wl,--wrap,OS_IsAllowedID -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap,rwlock_lock_read -Wl,--wrap,rwlock_unlock -Wl,--wrap,CreateSecMSG -Wl,--wrap,nb_queue -Wl,--wrap,time \ - -Wl,--wrap,sendto -Wl,--wrap,fcntl -Wl,--wrap,rem_add_send") - -list(APPEND remoted_names "test_remote-config") -list(APPEND remoted_flags "${DEBUG_OP_WRAPPERS}") - -list(APPEND remoted_names "test_syslogtcp") -list(APPEND remoted_flags "-W") - -list(APPEND remoted_names "test_remote-state") -list(APPEND remoted_flags "-Wl,--wrap,time -Wl,--wrap,rem_get_qsize -Wl,--wrap,rem_get_tsize \ - -Wl,--wrap,OSHash_Create -Wl,--wrap,OSHash_Add -Wl,--wrap,OSHash_Add_ex -Wl,--wrap,OSHash_Begin -Wl,--wrap,OSHash_Begin_ex \ - -Wl,--wrap,OSHash_Delete_ex -Wl,--wrap,OSHash_Delete -Wl,--wrap,OSHash_Get -Wl,--wrap,OSHash_Clean \ - -Wl,--wrap,OSHash_Get_ex -Wl,--wrap,OSHash_Next -Wl,--wrap,OSHash_SetFreeDataPointer \ - -Wl,--wrap,OSHash_Update_ex -Wl,--wrap,OSHash_Update -Wl,--wrap,OSHash_Get_Elem_ex \ - -Wl,--wrap,wdb_get_agents_ids_of_current_node -Wl,--wrap,_merror") - -list(APPEND remoted_names "test_remcom") -list(APPEND remoted_flags "-Wl,--wrap,rem_create_state_json -Wl,--wrap,OS_BindUnixDomain -Wl,--wrap,select -Wl,--wrap,close -Wl,--wrap,accept \ - -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,getRemoteConfig -Wl,--wrap,rem_create_agents_state_json \ - -Wl,--wrap,assign_group_to_agent \ - -Wl,--wrap,wdb_get_agents_ids_of_current_node -Wl,--wrap,json_parse_agents -Wl,--wrap,getpid ${DEBUG_OP_WRAPPERS}") - -list(LENGTH remoted_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET remoted_names ${counter} remoted_test_name) - list(GET remoted_flags ${counter} remoted_test_flags) - - add_executable(${remoted_test_name} ${remoted_test_name}.c) - - target_link_libraries( - ${remoted_test_name} - ${WAZUHLIB} - ${WAZUHEXT} - REMOTED_O - ${TEST_DEPS} - ) - - if(NOT remoted_test_flags STREQUAL " ") - target_link_libraries( - ${remoted_test_name} - ${remoted_test_flags} - ) - endif() - add_test(NAME ${remoted_test_name} COMMAND ${remoted_test_name}) -endforeach() diff --git a/src/unit_tests/remoted/test_manager.c b/src/unit_tests/remoted/test_manager.c deleted file mode 100644 index 4776c613161..00000000000 --- a/src/unit_tests/remoted/test_manager.c +++ /dev/null @@ -1,5359 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/os_crypto/sha256_op_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/shared/agent_op_wrappers.h" -#include "../wrappers/wazuh/remoted/shared_download_wrappers.h" -#include "../wrappers/posix/dirent_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/wazuh/remoted/request_wrappers.h" -#include "../wrappers/wazuh/remoted/remoted_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" - -#include "../wazuh_db/wdb.h" -#include "../remoted/remoted.h" -#include "../remoted/shared_download.h" -#include "../../remoted/manager.c" - -int lookfor_agent_group(const char *agent_id, char *msg, char **r_group, int* wdb_sock); -extern OSHash *agent_data_hash; - -/* tests */ - -#define LONG_PATH "190-characters-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - -void keyentry_init(keyentry *key, char *name, char *id, char *ip, char *raw_key) { - os_calloc(1, sizeof(os_ip), key->ip); - key->ip->ip = ip ? strdup(ip) : NULL; - key->name = name ? strdup(name) : NULL; - key->id = id ? strdup(id) : NULL; - key->raw_key = raw_key ? strdup(raw_key) : NULL; -} - -void free_keyentry(keyentry *key) { - os_free(key->ip->ip); - os_free(key->ip); - os_free(key->name); - os_free(key->id); - os_free(key->raw_key); -} - -static void free_group(void *data) { - if (data) { - group_t *group = (group_t *)data; - if (group->f_time) { - OSHash_Clean(group->f_time, free_file_time); - } - os_free(group->name); - os_free(group); - } -} - -static void free_group_c_group(void *data) { - if (data) { - group_t *group = (group_t *)data; - os_free(group->name); - os_free(group); - } -} - -static int setup_globals(void ** state) { - agent_data_hash = __real_OSHash_Create(); - test_mode = 1; - - return 0; -} - -static int setup_globals_no_test_mode(void ** state) { - agent_data_hash = __real_OSHash_Create(); - test_mode = 0; - - return 0; -} - -static int teardown_globals(void ** state) { - __real_OSHash_Clean(agent_data_hash, agent_data_hash_cleaner); - test_mode = 0; - - return 0; -} - -static int setup_test_mode(void ** state) { - test_mode = 1; - - return 0; -} - -static int teardown_test_mode(void ** state) { - test_mode = 0; - - return 0; -} - - -int __wrap_send_msg(const char *agent_id, const char *msg, ssize_t msg_length) { - check_expected(agent_id); - check_expected(msg); - return 0; -} - -static int test_setup_group(void ** state) { - test_mode = 1; - return 0; -} - -static int test_teardown_group(void ** state) { - test_mode = 0; - return 0; -} - -static int test_c_group_setup(void ** state) { - group_t *group = NULL; - - test_mode = 0; - - groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), group); - group->name = strdup("test_default"); - OSHash_Add_ex(groups, "test_default", group); - - test_mode = 1; - - state[0] = group; - - return 0; -} - -static int test_find_group_setup(void ** state) { - group_t *group1 = NULL; - group_t *group2 = NULL; - - test_mode = 0; - - groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), group1); - group1->name = strdup("test_default"); - snprintf(group1->merged_sum, 17, "ABCDEF1234567890"); - OSHash_Add_ex(groups, "test_default", group1); - - os_calloc(1, sizeof(group_t), group2); - group2->name = strdup("test_test_default"); - snprintf(group2->merged_sum, 17, "ABCDEF1234567809"); - OSHash_Add_ex(groups, "test_test_default", group2); - - test_mode = 1; - - state[0] = group1; - state[1] = group2; - - return 0; -} - -static int test_process_deleted_groups_setup(void ** state) { - group_t *group1 = NULL; - group_t *group2 = NULL; - - test_mode = 0; - - os_calloc(1, sizeof(group_t), group1); - group1->name = strdup("test_default"); - - os_calloc(1, sizeof(group_t), group2); - group2->name = strdup("test_test_default"); - - test_mode = 1; - - state[0] = group1; - state[1] = group2; - - return 0; -} - -static int test_find_multi_group_setup(void ** state) { - group_t *multigroup1 = NULL; - group_t *multigroup2 = NULL; - - test_mode = 0; - - multi_groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), multigroup1); - multigroup1->name = strdup("test_default2"); - snprintf(multigroup1->merged_sum, 17, "1234567890ABCDEF"); - OSHash_Add_ex(multi_groups, "test_default2", multigroup1); - - os_calloc(1, sizeof(group_t), multigroup2); - multigroup2->name = strdup("test_test_default2"); - snprintf(multigroup2->merged_sum, 17, "1234567890ABCDFE"); - OSHash_Add_ex(multi_groups, "test_test_default2", multigroup2); - - test_mode = 1; - - state[0] = multigroup1; - state[1] = multigroup2; - - return 0; -} - -static int test_process_deleted_multi_groups_setup(void ** state) { - group_t *multigroup1 = NULL; - group_t *multigroup2 = NULL; - - test_mode = 0; - - os_calloc(1, sizeof(group_t), multigroup1); - multigroup1->name = strdup("test_default2"); - - os_calloc(1, sizeof(group_t), multigroup2); - multigroup2->name = strdup("test_test_default2"); - - test_mode = 1; - - state[0] = multigroup1; - state[1] = multigroup2; - - return 0; -} - -static int test_ftime_changed_setup(void ** state) { - file_time *file1 = NULL; - file_time *file2 = NULL; - file_time *file3 = NULL; - file_time *file4 = NULL; - - test_mode = 0; - - os_calloc(1, sizeof(file_time), file1); - file1->name = strdup("file1"); - file1->m_time = 123456789; - - os_calloc(1, sizeof(file_time), file2); - file2->name = strdup("file2"); - file2->m_time = 123456798; - - test_mode = 1; - - state[0] = file1; - state[1] = file2; - - return 0; -} - -static int test_process_group_setup(void ** state) { - group_t *group = NULL; - file_time *file = NULL; - - test_mode = 0; - - groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), group); - group->name = strdup("test_default"); - group->f_time = OSHash_Create(); - os_calloc(1, sizeof(file_time), file); - file->name = strdup("merged.mg"); - file->m_time = 123456789; - OSHash_Add_ex(group->f_time, "merged.mg", file); - strncpy(group->merged_sum, "AAAAAAAAAAAAAAAA", 32); - OSHash_Add_ex(groups, "test_default", group); - - if (setup_hashmap(state) != 0) { - return 1; - } - - test_mode = 1; - - state[0] = group->f_time; - state[1] = group; - - return 0; -} - -static int test_process_multi_groups_setup(void ** state) { - group_t *multigroup = NULL; - file_time *file = NULL; - - test_mode = 0; - - multi_groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), multigroup); - multigroup->name = strdup("groupA,groupB"); - multigroup->f_time = OSHash_Create(); - os_calloc(1, sizeof(file_time), file); - file->name = strdup("test_file2"); - file->m_time = 123456789; - OSHash_Add_ex(multigroup->f_time, "test_file2", file); - OSHash_Add_ex(multi_groups, "groupA,groupB", multigroup); - - if (setup_hashmap(state) != 0) { - return 1; - } - - test_mode = 1; - - return 0; -} - -static int test_process_multi_groups_groups_setup(void ** state) { - group_t *group1 = NULL; - group_t *group2 = NULL; - group_t *multigroup = NULL; - file_time *file = NULL; - - test_mode = 0; - - multi_groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), multigroup); - multigroup->name = strdup("group1,group2"); - multigroup->f_time = OSHash_Create(); - os_calloc(1, sizeof(file_time), file); - file->name = strdup("test_file2"); - file->m_time = 123456789; - OSHash_Add_ex(multigroup->f_time, "test_file2", file); - OSHash_Add_ex(multi_groups, "group1,group2", multigroup); - - groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), group1); - group1->name = strdup("group1"); - group1->has_changed = true; - group1->exists = true; - OSHash_Add_ex(groups, "group1", group1); - - os_calloc(1, sizeof(group_t), group2); - group2->name = strdup("group2"); - group2->has_changed = false; - group2->exists = true; - OSHash_Add_ex(groups, "group2", group2); - - if (setup_hashmap(state) != 0) { - return 1; - } - - test_mode = 1; - - state[0] = group1; - state[1] = multigroup; - - return 0; -} - -static int test_c_files_setup(void ** state) { - group_t *group1 = NULL; - group_t *group2 = NULL; - group_t *multigroup1 = NULL; - group_t *multigroup2 = NULL; - file_time *file1 = NULL; - file_time *file2 = NULL; - file_time *file3 = NULL; - file_time *file4 = NULL; - - test_mode = 0; - - groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), group1); - group1->name = strdup("test_default"); - group1->f_time = OSHash_Create(); - os_calloc(1, sizeof(file_time), file1); - file1->name = strdup("test_file"); - file1->m_time = 123456789; - OSHash_Add_ex(group1->f_time, "test_file", file1); - OSHash_Add_ex(groups, "test_default", group1); - - os_calloc(1, sizeof(group_t), group2); - group2->name = strdup("test_test_default"); - group2->f_time = OSHash_Create(); - os_calloc(1, sizeof(file_time), file2); - file2->name = strdup("test_test_file"); - file2->m_time = 123456798; - OSHash_Add_ex(group2->f_time, "test_test_file", file2); - OSHash_Add_ex(groups, "test_test_default", group2); - - multi_groups = OSHash_Create(); - - os_calloc(1, sizeof(group_t), multigroup1); - multigroup1->name = strdup("test_default2"); - multigroup1->f_time = OSHash_Create(); - os_calloc(1, sizeof(file_time), file3); - file3->name = strdup("test_file2"); - file3->m_time = 123456789; - OSHash_Add_ex(multigroup1->f_time, "test_file2", file3); - OSHash_Add_ex(multi_groups, "test_default2", multigroup1); - - os_calloc(1, sizeof(group_t), multigroup2); - multigroup2->name = strdup("test_test_default2"); - multigroup2->f_time = OSHash_Create(); - os_calloc(1, sizeof(file_time), file4); - file4->name = strdup("test_test_file2"); - file4->m_time = 123456798; - OSHash_Add_ex(multigroup2->f_time, "test_test_file2", file4); - OSHash_Add_ex(multi_groups, "test_test_default2", multigroup2); - - test_mode = 1; - - return 0; -} - -static int test_c_group_teardown(void ** state) { - test_mode = 0; - - if (groups) { - OSHash_Clean(groups, free_group_c_group); - } - - test_mode = 1; - - return 0; -} - -static int test_c_multi_group_teardown(void ** state) { - test_mode = 0; - - if (multi_groups) { - OSHash_Clean(multi_groups, free_group); - } - - test_mode = 1; - - return 0; -} - -static int test_process_deleted_groups_teardown(void ** state) { - group_t *group = (group_t *)state[1]; - - test_mode = 0; - - free_group_c_group(group); - - test_mode = 1; - - return 0; -} - -static int test_ftime_changed_teardown(void ** state) { - file_time *file1 = (file_time *)state[0]; - file_time *file2 = (file_time *)state[1]; - - test_mode = 0; - - free_file_time(file1); - free_file_time(file2); - - test_mode = 1; - - return 0; -} - -static int test_process_groups_teardown(void ** state) { - OSHash *f_time = (OSHash *)state[0]; - - test_mode = 0; - - OSHash_Clean(f_time, free_file_time); - - if (groups) { - OSHash_Clean(groups, free_group_c_group); - } - - if (teardown_hashmap(NULL) != 0) { - return -1; - } - - test_mode = 1; - - return 0; -} - -static int test_process_multi_groups_teardown(void ** state) { - test_mode = 0; - - if (multi_groups) { - OSHash_Clean(multi_groups, free_group); - } - - if (teardown_hashmap(NULL) != 0) { - return -1; - } - - test_mode = 1; - - return 0; -} - -static int test_process_multi_groups_groups_teardown(void ** state) { - OSHash *f_time = (OSHash *)state[0]; - - test_mode = 0; - - OSHash_Clean(f_time, free_file_time); - - if (multi_groups) { - OSHash_Clean(multi_groups, free_group_c_group); - } - - if (groups) { - OSHash_Clean(groups, free_group); - } - - if (teardown_hashmap(NULL) != 0) { - return -1; - } - - test_mode = 1; - - return 0; -} - -static int test_c_files_teardown(void ** state) { - test_mode = 0; - - if (groups) { - OSHash_Clean(groups, free_group); - } - - if (multi_groups) { - OSHash_Clean(multi_groups, free_group); - } - - test_mode = 1; - - return 0; -} - -/* Tests lookfor_agent_group */ - -void test_lookfor_agent_group_with_group() -{ - const int agent_id = 1; - const char agent_id_str[] = "001"; - char *msg = "Linux |localhost.localdomain |4.18.0-240.22.1.el8_3.x86_64 |#1 SMP Thu Apr 8 19:01:30 UTC 2021 |x86_64 [CentOS Linux|centos: 8.3] - Wazuh v4.2.0 / ab73af41699f13fdd81903b5f23d8d00\nc2305e0ac17e7176e924294c69cc7a24 merged.mg\n#\"_agent_ip\":10.0.2.4"; - char *r_group = NULL; - char *test_group = strdup("TESTGROUP"); - - expect_value(__wrap_wdb_get_agent_group, id, agent_id); - will_return(__wrap_wdb_get_agent_group, test_group); - - expect_string(__wrap__mdebug2, formatted_msg, "Agent '001' group is 'TESTGROUP'"); - - int ret = lookfor_agent_group(agent_id_str, msg, &r_group, NULL); - assert_int_equal(OS_SUCCESS, ret); - assert_string_equal(r_group, test_group); - - os_free(test_group); -} - -void test_lookfor_agent_group_set_default_group() -{ - const int agent_id = 1; - const char agent_id_str[] = "001"; - char *msg = "Linux |localhost.localdomain |4.18.0-240.22.1.el8_3.x86_64 |#1 SMP Thu Apr 8 19:01:30 UTC 2021 |x86_64 [CentOS Linux|centos: 8.3] - Wazuh v4.2.0 / ab73af41699f13fdd81903b5f23d8d00\nc2305e0ac17e7176e924294c69cc7a24 merged.mg\n#\"_agent_ip\":10.0.2.4"; - char *r_group = NULL; - - expect_value(__wrap_wdb_get_agent_group, id, agent_id); - will_return(__wrap_wdb_get_agent_group, NULL); - - expect_string(__wrap__mdebug2, formatted_msg, "Agent '001' with file 'merged.mg' MD5 'c2305e0ac17e7176e924294c69cc7a24'"); - - expect_function_call(__wrap_pthread_mutex_lock); - - will_return(__wrap_w_is_single_node, 0); - - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_wdb_set_agent_groups_csv, id, agent_id); - will_return(__wrap_wdb_set_agent_groups_csv, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Group assigned: 'default'"); - - int ret = lookfor_agent_group(agent_id_str, msg, &r_group, NULL); - assert_int_equal(OS_SUCCESS, ret); - assert_string_equal(r_group, "default"); - - os_free(r_group); -} - -void test_lookfor_agent_group_set_group_worker() -{ - const int agent_id = 1; - const char agent_id_str[] = "001"; - char *msg = "Linux |localhost.localdomain |4.18.0-240.22.1.el8_3.x86_64 |#1 SMP Thu Apr 8 19:01:30 UTC 2021 |x86_64 [CentOS Linux|centos: 8.3] - Wazuh v4.2.0 / ab73af41699f13fdd81903b5f23d8d00\nc2305e0ac17e7176e924294c69cc7a24 merged.mg\n#\"_agent_ip\":10.0.2.4"; - char *r_group = NULL; - - cJSON *input = cJSON_CreateObject(); - - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(parameters, "agent", "001"); - cJSON_AddStringToObject(parameters, "md5", "c2305e0ac17e7176e924294c69cc7a24"); - - cJSON_AddStringToObject(input, "command", "assigngroup"); - cJSON_AddItemToObject(input, "parameters", parameters); - - cJSON * cluster_request = cJSON_CreateObject(); - - cJSON_AddStringToObject(cluster_request, "daemon_name", "remoted"); - cJSON_AddItemToObject(cluster_request, "message", input); - - char *message = "{\"daemon_name\":\"remoted\"," - "\"message\":{\"command\":\"assigngroup\"," - "\"parameters\":{\"agent\":\"001\"," - "\"md5\":\"c2305e0ac17e7176e924294c69cc7a24\"}}}"; - - char *response = "{\"error\":0,\"data\":{\"group\":\"test1\"}}"; - - expect_value(__wrap_wdb_get_agent_group, id, agent_id); - will_return(__wrap_wdb_get_agent_group, NULL); - - expect_string(__wrap_w_create_sendsync_payload, daemon_name, "remoted"); - will_return(__wrap_w_create_sendsync_payload, 1); - will_return(__wrap_w_create_sendsync_payload, cluster_request); - - expect_string(__wrap__mdebug2, formatted_msg, "Sending message to master node: '{\"daemon_name\":\"remoted\"," - "\"message\":{\"command\":\"assigngroup\"," - "\"parameters\":{\"agent\":\"001\"," - "\"md5\":\"c2305e0ac17e7176e924294c69cc7a24\"}}}'"); - - expect_string(__wrap_w_send_clustered_message, command, "sendsync"); - expect_string(__wrap_w_send_clustered_message, payload, message); - will_return(__wrap_w_send_clustered_message, response); - will_return(__wrap_w_send_clustered_message, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Message received from master node: '{\"error\":0,\"data\":{\"group\":\"test1\"}}'"); - - logr.worker_node = 1; - int ret = lookfor_agent_group(agent_id_str, msg, &r_group, NULL); - logr.worker_node = 0; - - assert_int_equal(OS_SUCCESS, ret); - assert_string_equal(r_group, "test1"); - - os_free(r_group); -} - -void test_lookfor_agent_group_set_group_worker_error() -{ - const int agent_id = 1; - const char agent_id_str[] = "001"; - char *msg = "Linux |localhost.localdomain |4.18.0-240.22.1.el8_3.x86_64 |#1 SMP Thu Apr 8 19:01:30 UTC 2021 |x86_64 [CentOS Linux|centos: 8.3] - Wazuh v4.2.0 / ab73af41699f13fdd81903b5f23d8d00\nc2305e0ac17e7176e924294c69cc7a24 merged.mg\n#\"_agent_ip\":10.0.2.4"; - char *r_group = NULL; - - cJSON *input = cJSON_CreateObject(); - - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(parameters, "agent", "001"); - cJSON_AddStringToObject(parameters, "md5", "c2305e0ac17e7176e924294c69cc7a24"); - - cJSON_AddStringToObject(input, "command", "assigngroup"); - cJSON_AddItemToObject(input, "parameters", parameters); - - cJSON * cluster_request = cJSON_CreateObject(); - - cJSON_AddStringToObject(cluster_request, "daemon_name", "remoted"); - cJSON_AddItemToObject(cluster_request, "message", input); - - char *message = "{\"daemon_name\":\"remoted\"," - "\"message\":{\"command\":\"assigngroup\"," - "\"parameters\":{\"agent\":\"001\"," - "\"md5\":\"c2305e0ac17e7176e924294c69cc7a24\"}}}"; - - char *response = "{\"error\":1,\"data\":{}}"; - - expect_value(__wrap_wdb_get_agent_group, id, agent_id); - will_return(__wrap_wdb_get_agent_group, NULL); - - expect_string(__wrap_w_create_sendsync_payload, daemon_name, "remoted"); - will_return(__wrap_w_create_sendsync_payload, 1); - will_return(__wrap_w_create_sendsync_payload, cluster_request); - - expect_string(__wrap__mdebug2, formatted_msg, "Sending message to master node: '{\"daemon_name\":\"remoted\"," - "\"message\":{\"command\":\"assigngroup\"," - "\"parameters\":{\"agent\":\"001\"," - "\"md5\":\"c2305e0ac17e7176e924294c69cc7a24\"}}}'"); - - expect_string(__wrap_w_send_clustered_message, command, "sendsync"); - expect_string(__wrap_w_send_clustered_message, payload, message); - will_return(__wrap_w_send_clustered_message, response); - will_return(__wrap_w_send_clustered_message, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Message received from master node: '{\"error\":1,\"data\":{}}'"); - - expect_string(__wrap__merror, formatted_msg, "Agent '001' invalid or empty group assigned."); - - logr.worker_node = 1; - int ret = lookfor_agent_group(agent_id_str, msg, &r_group, NULL); - logr.worker_node = 0; - - assert_int_equal(OS_INVALID, ret); - assert_null(r_group); -} - -void test_lookfor_agent_group_msg_without_enter() -{ - const int agent_id = 2; - const char agent_id_str[] = "002"; - char *msg = "Linux |localhost.localdomain |4.18.0-240.22.1.el8_3.x86_64 |#1 SMP Thu Apr 8 19:01:30 UTC 2021 |x86_64 [CentOS Linux|centos: 8.3] - Wazuh v4.2.0 / ab73af41699f13fdd81903b5f23d8d00c2305e0ac17e7176e924294c69cc7a24 merged.mg"; - char *r_group = NULL; - - expect_value(__wrap_wdb_get_agent_group, id, agent_id); - will_return(__wrap_wdb_get_agent_group, NULL); - - expect_string(__wrap__merror, formatted_msg, "Invalid message from agent ID '002' (strchr \\n)"); - - int ret = lookfor_agent_group(agent_id_str, msg, &r_group, NULL); - assert_int_equal(OS_INVALID, ret); - assert_null(r_group); -} - -void test_lookfor_agent_group_bad_message() -{ - const int agent_id = 3; - const char agent_id_str[] = "003"; - char *msg = "Linux |localhost.localdomain\n#c2305e0ac17e7176e924294c69cc7a24 merged.mg\nc2305e0ac17e7176e924294c69cc7a24merged.mg\n#\"_agent_ip\":10.0.2.4"; - char *r_group = NULL; - - expect_value(__wrap_wdb_get_agent_group, id, agent_id); - will_return(__wrap_wdb_get_agent_group, NULL); - - expect_string(__wrap__merror, formatted_msg, "Invalid message from agent ID '003' (strchr ' ')"); - - int ret = lookfor_agent_group(agent_id_str, msg, &r_group, NULL); - assert_int_equal(OS_INVALID, ret); - assert_null(r_group); -} - -void test_lookfor_agent_group_message_without_second_enter() -{ - const int agent_id = 4; - const char agent_id_str[] = "004"; - char *msg = "Linux |localhost.localdomain \n#\"_agent_ip\":10.0.2.4"; - char *r_group = NULL; - - expect_value(__wrap_wdb_get_agent_group, id, agent_id); - will_return(__wrap_wdb_get_agent_group, NULL); - - expect_string(__wrap__merror, formatted_msg, "Invalid message from agent ID '004' (strchr \\n)"); - - int ret = lookfor_agent_group(agent_id_str, msg, &r_group, NULL); - assert_int_equal(OS_INVALID, ret); - assert_null(r_group); -} - -void test_c_group_no_changes(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_Str, str, "buffer stream"); - expect_value(__wrap_OS_MD5_Str, length, 13); - will_return(__wrap_OS_MD5_Str, "md5_test"); - will_return(__wrap_OS_MD5_Str, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_stat, __file, "etc/shared/test_default/merged.mg"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "merged.mg"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_string(__wrap__merror, formatted_msg, "Couldn't add file 'merged.mg' to group hash table."); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - assert_string_equal(group->name, "test_default"); - assert_string_equal(group->merged_sum, "md5_test"); - assert_non_null(group->f_time); -} - -void test_c_group_no_changes_disk(void **state) -{ - disk_storage = 1; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg.tmp"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg.tmp"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_unlink, file, "etc/shared/test_default/merged.mg.tmp"); - will_return(__wrap_unlink, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_stat, __file, "etc/shared/test_default/merged.mg"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "merged.mg"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_string(__wrap__merror, formatted_msg, "Couldn't add file 'merged.mg' to group hash table."); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - assert_string_equal(group->name, "test_default"); - assert_string_equal(group->merged_sum, "md5_test"); - assert_non_null(group->f_time); -} - -void test_c_group_changes(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_Str, str, "buffer stream"); - expect_value(__wrap_OS_MD5_Str, length, 13); - will_return(__wrap_OS_MD5_Str, "md5_test"); - will_return(__wrap_OS_MD5_Str, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test2"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)2); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, (FILE *)2); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test2"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_stat, __file, "etc/shared/test_default/merged.mg"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - expect_string(__wrap__merror, formatted_msg, "Unable to get entry attributes 'etc/shared/test_default/merged.mg'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - assert_string_equal(group->name, "test_default"); - assert_string_equal(group->merged_sum, "md5_test2"); - assert_non_null(group->f_time); -} - -void test_c_group_changes_disk(void **state) -{ - disk_storage = 1; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg.tmp"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg.tmp"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test2"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_OS_MoveFile, src, "etc/shared/test_default/merged.mg.tmp"); - expect_string(__wrap_OS_MoveFile, dst, "etc/shared/test_default/merged.mg"); - will_return(__wrap_OS_MoveFile, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test2"); - will_return(__wrap_OS_MD5_File, 0); - - expect_string(__wrap_stat, __file, "etc/shared/test_default/merged.mg"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - expect_string(__wrap__merror, formatted_msg, "Unable to get entry attributes 'etc/shared/test_default/merged.mg'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - assert_string_equal(group->name, "test_default"); - assert_string_equal(group->merged_sum, "md5_test2"); - assert_non_null(group->f_time); -} - -void test_c_group_fail(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_Str, str, "buffer stream"); - expect_value(__wrap_OS_MD5_Str, length, 13); - will_return(__wrap_OS_MD5_Str, "md5_test"); - will_return(__wrap_OS_MD5_Str, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)2); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, (FILE *)2); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap__merror, formatted_msg, "Accessing file 'etc/shared/test_default/merged.mg'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - assert_string_equal(group->name, "test_default"); - assert_string_equal(group->merged_sum, ""); - assert_non_null(group->f_time); -} - -void test_c_group_fail_disk(void **state) -{ - disk_storage = 1; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg.tmp"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg.tmp"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap__merror, formatted_msg, "Accessing file 'etc/shared/test_default/merged.mg.tmp'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - assert_string_equal(group->name, "test_default"); - assert_string_equal(group->merged_sum, ""); - assert_non_null(group->f_time); -} - -void test_c_group_downloaded_file(void **state) -{ - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 1; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, r_group); - - expect_string(__wrap__mdebug1, formatted_msg, "Downloading shared file 'etc/shared/test_default/merged.mg' from 'r_group->files_url'"); - - expect_string(__wrap_wurl_request, url, r_group->files->url); - expect_string(__wrap_wurl_request, dest, "var/download/merged.mg"); - will_return(__wrap_wurl_request, 0); - - expect_string(__wrap_TestUnmergeFiles, finalpath, "var/download/merged.mg"); - will_return(__wrap_TestUnmergeFiles, 1); - - expect_string(__wrap_OS_MoveFile, src, "var/download/merged.mg"); - expect_string(__wrap_OS_MoveFile, dst, "etc/shared/test_default/merged.mg"); - will_return(__wrap_OS_MoveFile, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap__merror, formatted_msg, "Accessing file 'etc/shared/test_default/merged.mg'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_downloaded_file_no_poll(void **state) -{ - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 1; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 1; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, r_group); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap__merror, formatted_msg, "Accessing file 'etc/shared/test_default/merged.mg'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_downloaded_file_is_corrupted(void **state) -{ - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 1; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, r_group); - - expect_string(__wrap__mdebug1, formatted_msg, "Downloading shared file 'etc/shared/test_default/merged.mg' from 'r_group->files_url'"); - - expect_string(__wrap_wurl_request, url, r_group->files->url); - expect_string(__wrap_wurl_request, dest, "var/download/merged.mg"); - will_return(__wrap_wurl_request, 0); - - expect_string(__wrap_TestUnmergeFiles, finalpath, "var/download/merged.mg"); - will_return(__wrap_TestUnmergeFiles, 0); - - expect_string(__wrap_unlink, file, "var/download/merged.mg"); - will_return(__wrap_unlink, -1); - - expect_string(__wrap__merror, formatted_msg, "The downloaded file 'var/download/merged.mg' is corrupted."); - expect_string(__wrap__merror, formatted_msg, "Failed to delete file 'var/download/merged.mg'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_download_all_files(void **state) -{ - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - - os_calloc(1, (2) * sizeof(file), r_group->files); - r_group->files[0].name = strdup("r_group->files_name"); - r_group->files[0].url = strdup("r_group->files_url");; - - r_group->files[1].name = NULL; - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = -1; - r_group->merged_is_downloaded = 1; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, r_group); - - expect_string(__wrap__mdebug1, formatted_msg, "Downloading shared file 'etc/shared/test_default/r_group->files_name' from 'r_group->files_url'"); - - expect_string(__wrap_wurl_request, url, r_group->files->url); - expect_string(__wrap_wurl_request, dest, "var/download/r_group->files_name"); - will_return(__wrap_wurl_request, 0); - - expect_string(__wrap_OS_MoveFile, src, "var/download/r_group->files_name"); - expect_string(__wrap_OS_MoveFile, dst, "etc/shared/test_default/r_group->files_name"); - will_return(__wrap_OS_MoveFile, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap__merror, formatted_msg, "Accessing file 'etc/shared/test_default/merged.mg'"); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_no_create_shared_file(void **state) -{ - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 0; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, false, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); - - assert_string_equal(group->name, "test_default"); - assert_string_equal(group->merged_sum, ""); - assert_non_null(group->f_time); -} - -void test_c_group_invalid_share_file(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 0; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - struct stat stat_buf = { .st_mtime = 123456788 }; - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_value(__wrap_MergeAppendFile, finalfp, (FILE *)1); - expect_value(__wrap_MergeAppendFile, path_offset, -1); - will_return(__wrap_MergeAppendFile, 1); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "ar.conf"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_string(__wrap__merror, formatted_msg, "Couldn't add file 'ar.conf' to group hash table."); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_Str, str, "buffer stream"); - expect_value(__wrap_OS_MD5_Str, length, 13); - will_return(__wrap_OS_MD5_Str, "md5_test"); - will_return(__wrap_OS_MD5_Str, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, NULL); - - will_return(__wrap_strerror, "No such file or directory"); - - expect_string(__wrap__merror, formatted_msg, "Unable to open file: 'etc/shared/test_default/merged.mg' due to [(0)-(No such file or directory)]."); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_append_file_error(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 0; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - struct stat stat_buf = { .st_mtime = 123456788 }; - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_value(__wrap_MergeAppendFile, finalfp, (FILE *)1); - expect_value(__wrap_MergeAppendFile, path_offset, -1); - will_return(__wrap_MergeAppendFile, 1); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "ar.conf"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, "Couldn't add file 'ar.conf' to group hash table."); - - // Start validate_shared_files function - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf2 = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf2); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - expect_value(__wrap_MergeAppendFile, finalfp, (FILE *)1); - expect_value(__wrap_MergeAppendFile, path_offset, 0x18); - will_return(__wrap_MergeAppendFile, 0); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_append_ar_error(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 0; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - struct stat stat_buf = { .st_mtime = 123456788 }; - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_value(__wrap_MergeAppendFile, finalfp, (FILE *)1); - expect_value(__wrap_MergeAppendFile, path_offset, -1); - will_return(__wrap_MergeAppendFile, 0); - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_truncate_error(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 0; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, NULL); - - will_return(__wrap_strerror, "No such file or directory"); - - expect_string(__wrap__merror, formatted_msg, "Unable to open memory stream due to [(0)-(No such file or directory)]."); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_group_truncate_error_disk(void **state) -{ - disk_storage = 1; - - group_t *group = (group_t *)state[0]; - - const char *group_name = "test_default"; - - // Initialize r_group structure - remote_files_group *r_group = NULL; - os_malloc(sizeof(remote_files_group), r_group); - os_strdup("r_group_name", r_group->name); - os_malloc(sizeof(file), r_group->files); - os_strdup("r_group->files_name", r_group->files->name); - os_strdup("r_group->files_url", r_group->files->url); - - r_group->poll = 0; - r_group->current_polling_time = 0; - r_group->merge_file_index = 0; - r_group->merged_is_downloaded = 0; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, group->name); - will_return(__wrap_w_parser_get_group, NULL); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg.tmp"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, NULL); - - will_return(__wrap_strerror, "No such file or directory"); - - expect_string(__wrap__merror, formatted_msg, "Unable to create merged file: 'etc/shared/test_default/merged.mg.tmp' due to [(0)-(No such file or directory)]."); - - c_group(group_name, &group->f_time, &group->merged_sum, SHAREDCFG_DIR, true, false); - - os_free(r_group->name) - os_free(r_group->files->name); - os_free(r_group->files->url); - os_free(r_group->files); - os_free(r_group); -} - -void test_c_multi_group_hash_multigroup_null(void **state) -{ - char *multi_group = NULL; - OSHash *_f_time = (OSHash *)10; - os_md5 sum; - char *hash_multigroup = NULL; - - c_multi_group(multi_group, &_f_time, &sum, hash_multigroup, true); -} - -void test_c_multi_group_open_directory_fail(void **state) -{ - char *multi_group = NULL; - OSHash *_f_time = (OSHash *)10; - os_md5 sum; - char *hash_multigroup = NULL; - - os_strdup("multi_group_test", multi_group); - os_strdup("multi_group_hash", hash_multigroup); - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/multi_group_hash"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 0); - - will_return(__wrap_strerror, "No such file or directory"); - - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'etc/shared': No such file or directory"); - - c_multi_group(multi_group, &_f_time, &sum, hash_multigroup, true); - - os_free(hash_multigroup); - os_free(multi_group); -} - -void test_c_multi_group_call_copy_directory(void **state) -{ - char *multi_group = NULL; - OSHash *_f_time = (OSHash *)10; - os_md5 sum; - char *hash_multigroup = NULL; - - os_strdup("multi_group_test", multi_group); - os_strdup("multi_group_hash", hash_multigroup); - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/multi_group_hash"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 1); - - expect_string(__wrap_wreaddir, name, "etc/shared/multi_group_test"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mwarn, formatted_msg, "Could not open directory 'etc/shared/multi_group_test'. Group folder was deleted."); - - /* Open the multi-group files and generate merged */ - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'var/multigroups': No such file or directory"); - - c_multi_group(multi_group, &_f_time, &sum, hash_multigroup, true); - - os_free(hash_multigroup); - os_free(multi_group); -} - -void test_c_multi_group_read_dir_fail_no_entry(void **state) -{ - char *multi_group = NULL; - OSHash *_f_time = (OSHash *)10; - os_md5 sum; - char *hash_multigroup = NULL; - - os_strdup("multi_group_test", multi_group); - os_strdup("multi_group_hash", hash_multigroup); - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/multi_group_hash"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 1); - - expect_string(__wrap_wreaddir, name, "etc/shared/multi_group_test"); - will_return(__wrap_wreaddir, NULL); - - // Open the multi-group files and generate merged // - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "Not a directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'var/multigroups': Not a directory"); - - errno = ENOTDIR; - - c_multi_group(multi_group, &_f_time, &sum, hash_multigroup, true); - - errno = 0; - - os_free(hash_multigroup); - os_free(multi_group); -} - -void test_c_multi_group_Ignore_hidden_files(void **state) -{ - char *multi_group = NULL; - OSHash *_f_time = (OSHash *)10; - os_md5 sum; - char *hash_multigroup = NULL; - - os_strdup("multi_group_test", multi_group); - os_strdup("multi_group_hash", hash_multigroup); - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/multi_group_hash"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 1); - - char** files = NULL; - os_malloc(5 * sizeof(char *), files); - os_strdup(".file_1", files[0]); - os_strdup("file_2", files[1]); - os_strdup("agent.conf", files[2]); - os_strdup("ignore_file", files[3]); - files[4] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/multi_group_test"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 0); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/multi_group_test/file_2"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "etc/shared/multi_group_test/file_2"); - expect_string(__wrap_w_copy_file, dst, "var/multigroups/multi_group_hash/file_2"); - expect_value(__wrap_w_copy_file, mode, 0x63); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - will_return(__wrap_opendir, 0); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/multi_group_test/agent.conf"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "etc/shared/multi_group_test/agent.conf"); - expect_string(__wrap_w_copy_file, dst, "var/multigroups/multi_group_hash/agent.conf"); - expect_value(__wrap_w_copy_file, mode, 0x61); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - time_t *last_modify; - os_calloc(1, sizeof(time_t), last_modify); - *last_modify = 10000; - - will_return(__wrap_opendir, 0); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/multi_group_test/ignore_file"); - will_return(__wrap_OSHash_Get, last_modify); - - // Open the multi-group files and generate merged // - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'var/multigroups': No such file or directory"); - - c_multi_group(multi_group, &_f_time, &sum, hash_multigroup, true); - - os_free(last_modify); - os_free(hash_multigroup); - os_free(multi_group); -} - -void test_c_multi_group_subdir_fail(void **state) -{ - char *multi_group = NULL; - OSHash *_f_time = (OSHash *)10; - os_md5 sum; - char *hash_multigroup = NULL; - - os_strdup("multi_group_test", multi_group); - os_strdup("hash_multi_group_test",hash_multigroup); - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/hash_multi_group_test"); - will_return(__wrap_cldir_ex_ignore, 0); - - // Open the multi-group files and generate merged // - will_return(__wrap_opendir, 1); - - // Start copy_directory function - expect_string(__wrap_wreaddir, name, "etc/shared/multi_group_test"); - will_return(__wrap_wreaddir, NULL); - - errno = 1; - expect_string(__wrap__mwarn, formatted_msg, "Could not open directory 'etc/shared/multi_group_test'. Group folder was deleted."); - - // End copy_directory function - - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'var/multigroups': ERROR"); - - c_multi_group(multi_group, &_f_time, &sum, hash_multigroup, true); - - errno = 0; - os_free(hash_multigroup); - os_free(multi_group); -} - -void test_c_multi_group_call_c_group(void **state) -{ - disk_storage = 0; - - char *multi_group = NULL; - OSHash *_f_time = (OSHash *)10; - os_md5 sum; - char *hash_multigroup = NULL; - - os_strdup("multi_group_test", multi_group); - os_strdup("hash_multi_group_test",hash_multigroup); - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/hash_multi_group_test"); - will_return(__wrap_cldir_ex_ignore, 0); - - // Open the multi-group files and generate merged // - will_return(__wrap_opendir, 1); - - // Start copy_directory function - expect_string(__wrap_wreaddir, name, "etc/shared/multi_group_test"); - will_return(__wrap_wreaddir, NULL); - - errno = 1; - expect_string(__wrap__mwarn, formatted_msg, "Could not open directory 'etc/shared/multi_group_test'. Group folder was deleted."); - - // End copy_directory function - - will_return(__wrap_opendir, 1); - - // Start c_group function - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, "hash_multi_group_test"); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, NULL); - - will_return(__wrap_strerror, "No such file or directory"); - - expect_string(__wrap__merror, formatted_msg, "Unable to open memory stream due to [(1)-(No such file or directory)]."); - // End c_group function - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/hash_multi_group_test"); - will_return(__wrap_cldir_ex_ignore, 0); - - c_multi_group(multi_group, &_f_time, &sum, hash_multigroup, true); - - errno = 0; - - os_free(hash_multigroup); - os_free(multi_group); -} - -void test_find_group_from_file_found(void **state) -{ - char group_name[OS_SIZE_65536] = {0}; - - OSHashNode* node = NULL; - os_calloc(1, sizeof(OSHashNode), node); - node->data = state[0]; - - expect_value(__wrap_OSHash_Begin, self, groups); - will_return(__wrap_OSHash_Begin, node); - - group_t *group = find_group_from_sum("ABCDEF1234567890", group_name); - - assert_string_equal(group_name, "test_default"); - assert_non_null(group); - assert_string_equal(group->name, "test_default"); - - os_free(node); -} - -void test_find_group_from_file_not_found(void **state) -{ - char group_name[OS_SIZE_65536] = {0}; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->data = state[0]; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->data = state[1]; - - expect_value(__wrap_OSHash_Begin, self, groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, groups); - will_return(__wrap_OSHash_Next, node2); - - expect_value(__wrap_OSHash_Next, self, groups); - will_return(__wrap_OSHash_Next, NULL); - - group_t *group = find_group_from_sum("2121212121", group_name); - - assert_string_equal(group_name, "\0"); - assert_null(group); - - os_free(node1); - os_free(node2); -} - -void test_find_multi_group_from_file_found(void **state) -{ - char multi_group_name[OS_SIZE_65536] = {0}; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->data = state[0]; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->data = state[1]; - - expect_value(__wrap_OSHash_Begin, self, multi_groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, node2); - - group_t *multi_group = find_multi_group_from_sum("1234567890ABCDFE", multi_group_name); - - assert_string_equal(multi_group_name, "test_test_default2"); - assert_non_null(multi_group); - assert_string_equal(multi_group->name, "test_test_default2"); - - os_free(node1); - os_free(node2); -} - -void test_find_multi_group_from_file_not_found(void **state) -{ - char multi_group_name[OS_SIZE_65536] = {0}; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->data = state[0]; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->data = state[1]; - - expect_value(__wrap_OSHash_Begin, self, multi_groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, node2); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, NULL); - - group_t *multi_group = find_multi_group_from_sum("4545454545", multi_group_name); - - assert_string_equal(multi_group_name, "\0"); - assert_null(multi_group); - - os_free(node1); - os_free(node2); -} - -void test_ftime_changed_same_fsum(void **state) -{ - file_time *file1 = (file_time *)state[0]; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->data = file1; - - OSHash *hash1 = (OSHash *)10; - OSHash *hash2 = (OSHash *)11; - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash1); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash2); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Begin, self, hash1); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Get_ex, self, hash2); - expect_string(__wrap_OSHash_Get_ex, key, "file1"); - will_return(__wrap_OSHash_Get_ex, file1); - - expect_value(__wrap_OSHash_Next, self, hash1); - will_return(__wrap_OSHash_Next, NULL); - - assert_false(ftime_changed(hash1, hash2)); - - os_free(node1); -} - -void test_ftime_changed_different_fsum_sum(void **state) -{ - file_time *file1 = (file_time *)state[0]; - file_time *file2 = (file_time *)state[1]; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->data = file1; - - OSHash *hash1 = (OSHash *)10; - OSHash *hash2 = (OSHash *)11; - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash1); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash2); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Begin, self, hash1); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Get_ex, self, hash2); - expect_string(__wrap_OSHash_Get_ex, key, "file1"); - will_return(__wrap_OSHash_Get_ex, file2); - - assert_true(ftime_changed(hash1, hash2)); - - os_free(node1); -} - -void test_ftime_changed_different_fsum_name(void **state) -{ - file_time *file1 = (file_time *)state[0]; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->data = file1; - - OSHash *hash1 = (OSHash *)10; - OSHash *hash2 = (OSHash *)11; - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash1); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash2); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Begin, self, hash1); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Get_ex, self, hash2); - expect_string(__wrap_OSHash_Get_ex, key, "file1"); - will_return(__wrap_OSHash_Get_ex, NULL); - - assert_true(ftime_changed(hash1, hash2)); - - os_free(node1); -} - -void test_ftime_changed_different_size(void **state) -{ - OSHash *hash1 = (OSHash *)10; - OSHash *hash2 = (OSHash *)11; - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash1); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, hash2); - will_return(__wrap_OSHash_Get_Elem_ex, 1); - - assert_true(ftime_changed(hash1, hash2)); -} - -void test_ftime_changed_one_null(void **state) -{ - OSHash *hash1 = (OSHash *)10; - OSHash *hash2 = NULL; - - assert_true(ftime_changed(hash1, hash2)); -} - -void test_ftime_changed_both_null(void **state) -{ - OSHash *hash1 = NULL; - OSHash *hash2 = NULL; - - assert_false(ftime_changed(hash1, hash2)); -} - -void test_group_changed_not_changed(void **state) -{ - group_t *group1 = (group_t *)state[0]; - group_t *group2 = (group_t *)state[1]; - - group1->exists = true; - group1->has_changed = false; - group2->exists = true; - group2->has_changed = false; - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_default"); - will_return(__wrap_OSHash_Get_ex, group1); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_test_default"); - will_return(__wrap_OSHash_Get_ex, group2); - - assert_false(group_changed("test_default,test_test_default")); -} - -void test_group_changed_has_changed(void **state) -{ - group_t *group1 = (group_t *)state[0]; - group_t *group2 = (group_t *)state[1]; - - group1->exists = true; - group1->has_changed = false; - group2->exists = true; - group2->has_changed = true; - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_default"); - will_return(__wrap_OSHash_Get_ex, group1); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_test_default"); - will_return(__wrap_OSHash_Get_ex, group2); - - assert_true(group_changed("test_default,test_test_default")); -} - -void test_group_changed_not_exists(void **state) -{ - group_t *group1 = (group_t *)state[0]; - group_t *group2 = (group_t *)state[1]; - - group1->exists = true; - group1->has_changed = false; - group2->exists = false; - group2->has_changed = false; - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_default"); - will_return(__wrap_OSHash_Get_ex, group1); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_test_default"); - will_return(__wrap_OSHash_Get_ex, group2); - - assert_true(group_changed("test_default,test_test_default")); -} - -void test_group_changed_invalid_group(void **state) -{ - group_t *group1 = (group_t *)state[0]; - group_t *group2 = (group_t *)state[1]; - - group1->exists = true; - group1->has_changed = false; - group2->exists = true; - group2->has_changed = false; - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_default"); - will_return(__wrap_OSHash_Get_ex, group1); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_test_default"); - will_return(__wrap_OSHash_Get_ex, group2); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "invalid_group"); - will_return(__wrap_OSHash_Get_ex, NULL); - - assert_true(group_changed("test_default,test_test_default,invalid_group")); -} - -void test_process_deleted_groups_delete(void **state) -{ - group_t *group1 = (group_t *)state[0]; - group_t *group2 = (group_t *)state[1]; - - group1->exists = false; - group1->has_changed = false; - group2->exists = true; - group2->has_changed = false; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->key = "test_default"; - node1->data = group1; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->key = "test_test_default"; - node2->data = group2; - - expect_value(__wrap_OSHash_Begin, self, groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, groups); - will_return(__wrap_OSHash_Next, node2); - - expect_value(__wrap_OSHash_Delete_ex, self, groups); - expect_string(__wrap_OSHash_Delete_ex, key, "test_default"); - will_return(__wrap_OSHash_Delete_ex, NULL); - - will_return(__wrap_OSHash_Clean, 0); - - expect_value(__wrap_OSHash_Next, self, groups); - will_return(__wrap_OSHash_Next, NULL); - - process_deleted_groups(); - - assert_non_null(group2); - assert_string_equal(group2->name, "test_test_default"); - assert_false(group2->has_changed); - assert_false(group2->exists); - - os_free(node1); - os_free(node2); -} - -void test_process_deleted_groups_no_changes(void **state) -{ - group_t *group1 = (group_t *)state[0]; - group_t *group2 = (group_t *)state[1]; - - group1->exists = true; - group1->has_changed = false; - group2->exists = true; - group2->has_changed = false; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->key = "test_default"; - node1->data = group1; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->key = "test_test_default"; - node2->data = group2; - - expect_value(__wrap_OSHash_Begin, self, groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, groups); - will_return(__wrap_OSHash_Next, node2); - - expect_value(__wrap_OSHash_Next, self, groups); - will_return(__wrap_OSHash_Next, NULL); - - process_deleted_groups(); - - assert_non_null(group1); - assert_string_equal(group1->name, "test_default"); - assert_false(group1->has_changed); - assert_false(group1->exists); - assert_non_null(group2); - assert_string_equal(group2->name, "test_test_default"); - assert_false(group2->has_changed); - assert_false(group2->exists); - - os_free(node1); - os_free(node2); -} - -void test_process_deleted_multi_groups_delete(void **state) -{ - group_t *multigroup1 = (group_t *)state[0]; - group_t *multigroup2 = (group_t *)state[1]; - - multigroup1->exists = false; - multigroup1->has_changed = false; - multigroup2->exists = true; - multigroup2->has_changed = false; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->key = "test_default2"; - node1->data = multigroup1; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->key = "test_test_default2"; - node2->data = multigroup2; - - will_return(__wrap_OSHash_Clean, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_value(__wrap_OSHash_Begin, self, multi_groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, node2); - - expect_value(__wrap_OSHash_Delete_ex, self, multi_groups); - expect_string(__wrap_OSHash_Delete_ex, key, "test_default2"); - will_return(__wrap_OSHash_Delete_ex, NULL); - - will_return(__wrap_OSHash_Clean, 0); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, NULL); - - expect_any(__wrap_OS_SHA256_String, str); - will_return(__wrap_OS_SHA256_String, "6e3a107738e7d0fc85241f04ed9686d37738e7d08086fb46e3a100fc85241f04"); - - expect_string(__wrap_rmdir_ex, name, "var/multigroups/6e3a1077"); - will_return(__wrap_rmdir_ex, 0); - - process_deleted_multi_groups(false); - - assert_non_null(multigroup2); - assert_string_equal(multigroup2->name, "test_test_default2"); - assert_false(multigroup2->has_changed); - assert_false(multigroup2->exists); - - os_free(node1); - os_free(node2); -} - -void test_process_deleted_multi_groups_no_changes(void **state) -{ - group_t *multigroup1 = (group_t *)state[0]; - group_t *multigroup2 = (group_t *)state[1]; - - multigroup1->exists = true; - multigroup1->has_changed = false; - multigroup2->exists = true; - multigroup2->has_changed = false; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->key = "test_default2"; - node1->data = multigroup1; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->key = "test_test_default2"; - node2->data = multigroup2; - - will_return(__wrap_OSHash_Clean, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_value(__wrap_OSHash_Begin, self, multi_groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, node2); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, NULL); - - process_deleted_multi_groups(false); - - assert_non_null(multigroup1); - assert_string_equal(multigroup1->name, "test_default2"); - assert_false(multigroup1->has_changed); - assert_false(multigroup1->exists); - assert_non_null(multigroup2); - assert_string_equal(multigroup2->name, "test_test_default2"); - assert_false(multigroup2->has_changed); - assert_false(multigroup2->exists); - - os_free(node1); - os_free(node2); -} - -void test_process_deleted_multi_groups_no_changes_initial_scan(void **state) -{ - group_t *multigroup1 = (group_t *)state[0]; - group_t *multigroup2 = (group_t *)state[1]; - - multigroup1->exists = true; - multigroup1->has_changed = false; - multigroup2->exists = true; - multigroup2->has_changed = false; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->key = "test_default2"; - node1->data = multigroup1; - - OSHashNode* node2 = NULL; - os_calloc(1, sizeof(OSHashNode), node2); - node2->key = "test_test_default2"; - node2->data = multigroup2; - - OSHashNode* node3 = NULL; - os_calloc(1, sizeof(OSHashNode), node3); - node3->key = "ignore"; - node3->data = "ignore_hash"; - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, node3); - - expect_value(__wrap_OSHash_Next, self, m_hash); - will_return(__wrap_OSHash_Next, NULL); - - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_OSHash_Clean, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_value(__wrap_OSHash_Begin, self, multi_groups); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, node2); - - expect_value(__wrap_OSHash_Next, self, multi_groups); - will_return(__wrap_OSHash_Next, NULL); - - process_deleted_multi_groups(true); - - assert_non_null(multigroup1); - assert_string_equal(multigroup1->name, "test_default2"); - assert_false(multigroup1->has_changed); - assert_false(multigroup1->exists); - assert_non_null(multigroup2); - assert_string_equal(multigroup2->name, "test_test_default2"); - assert_false(multigroup2->has_changed); - assert_false(multigroup2->exists); - - os_free(node1); - os_free(node2); - os_free(node3); -} - -void test_process_groups_open_directory_fail(void **state) -{ - will_return(__wrap_opendir, 0); - - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug1, formatted_msg, "Opening directory: 'etc/shared': No such file or directory"); - - process_groups(); -} - -void test_process_groups_readdir_fail(void **state) -{ - will_return(__wrap_opendir, 1); - - will_return(__wrap_readdir, NULL); - - process_groups(); -} - -void test_process_groups_subdir_null(void **state) -{ - struct dirent *entry; - os_calloc(1, sizeof(struct dirent), entry); - strcpy(entry->d_name, "test"); - - will_return(__wrap_opendir, 1); - - will_return(__wrap_readdir, entry); - - expect_string(__wrap_wreaddir, name, "etc/shared/test"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test'"); - - will_return(__wrap_readdir, NULL); - - process_groups(); - - os_free(entry); -} - -void test_process_groups_skip(void **state) -{ - struct dirent *entry; - os_calloc(1, sizeof(struct dirent), entry); - strcpy(entry->d_name, "."); - - will_return(__wrap_opendir, 1); - - will_return(__wrap_readdir, entry); - - will_return(__wrap_readdir, NULL); - - process_groups(); - - os_free(entry); -} - -void test_process_groups_skip_2(void **state) -{ - struct dirent *entry; - os_calloc(1, sizeof(struct dirent), entry); - strcpy(entry->d_name, ".."); - - will_return(__wrap_opendir, 1); - - will_return(__wrap_readdir, entry); - - will_return(__wrap_readdir, NULL); - - process_groups(); - - os_free(entry); -} - -void test_process_groups_find_group_null(void **state) -{ - disk_storage = 0; - - struct dirent *entry; - os_calloc(1, sizeof(struct dirent), entry); - strcpy(entry->d_name, "test"); - - char** subdir = NULL; - os_malloc(2 * sizeof(char *), subdir); - os_strdup("file_1", subdir[0]); - subdir[1] = NULL; - - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))free_group_c_group); - - will_return(__wrap_opendir, 1); - - will_return(__wrap_readdir, entry); - - expect_string(__wrap_wreaddir, name, "etc/shared/test"); - will_return(__wrap_wreaddir, subdir); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test"); - will_return(__wrap_OSHash_Get_ex, NULL); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, groups); - expect_string(__wrap_OSHash_Add_ex, key, "test"); - will_return(__wrap_OSHash_Add_ex, 2); - - // Start c_group function - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_w_parser_get_group, name, "test"); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_Str, str, "buffer stream"); - expect_value(__wrap_OS_MD5_Str, length, 13); - will_return(__wrap_OS_MD5_Str, "md5_test"); - will_return(__wrap_OS_MD5_Str, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap_wfopen, path, "etc/shared/test/merged.mg"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, NULL); - - will_return(__wrap_strerror, "No such file or directory"); - - expect_string(__wrap__merror, formatted_msg, "Unable to open file: 'etc/shared/test/merged.mg' due to [(0)-(No such file or directory)]."); - // End c_group function - - will_return(__wrap_readdir, NULL); - - process_groups(); - - os_free(entry); -} - -void test_process_groups_find_group_changed(void **state) -{ - disk_storage = 0; - - group_t *group = (group_t *)state[1]; - - struct dirent *entry; - os_calloc(1, sizeof(struct dirent), entry); - strcpy(entry->d_name, "test_default"); - - char** subdir = NULL; - os_malloc(2 * sizeof(char *), subdir); - os_strdup("test_file_change", subdir[0]); - subdir[1] = NULL; - - will_return(__wrap_opendir, 1); - - will_return(__wrap_readdir, entry); - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, subdir); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_default"); - will_return(__wrap_OSHash_Get_ex, group); - - // Start c_group function - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "1212121212121"); - will_return(__wrap_OS_MD5_File, -1); - // End c_group function - - // Start ftime_changed - expect_value(__wrap_OSHash_Get_Elem_ex, self, group->f_time); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, (OSHash *)10); - will_return(__wrap_OSHash_Get_Elem_ex, 1); - // End ftime_changed - - will_return(__wrap_OSHash_Clean, NULL); - - // Start c_group function - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)11); - - expect_string(__wrap_w_parser_get_group, name, "test_default"); - will_return(__wrap_w_parser_get_group, NULL); - - will_return(__wrap_open_memstream, strdup("buffer stream")); - will_return(__wrap_open_memstream, 13); - will_return(__wrap_open_memstream, (FILE *)1); - - expect_value(__wrap_fprintf, __stream, (FILE *)1); - expect_string(__wrap_fprintf, formatted_msg, "#test_default\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_value(__wrap_fclose, _File, (FILE *)1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_OS_MD5_Str, str, "buffer stream"); - expect_value(__wrap_OS_MD5_Str, length, 13); - will_return(__wrap_OS_MD5_Str, "md5_test"); - will_return(__wrap_OS_MD5_Str, 0); - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "md5_test"); - will_return(__wrap_OS_MD5_File, -1); - - expect_string(__wrap_wfopen, path, "etc/shared/test_default/merged.mg"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, NULL); - - will_return(__wrap_strerror, "No such file or directory"); - - expect_string(__wrap__merror, formatted_msg, "Unable to open file: 'etc/shared/test_default/merged.mg' due to [(0)-(No such file or directory)]."); - // End c_group function - - expect_string(__wrap__mdebug2, formatted_msg, "Group 'test_default' has changed."); - - will_return(__wrap_OSHash_Clean, NULL); - - will_return(__wrap_readdir, NULL); - - process_groups(); - - os_free(entry); -} - -void test_process_groups_find_group_not_changed(void **state) -{ - group_t *group = (group_t *)state[1]; - - struct dirent *entry; - os_calloc(1, sizeof(struct dirent), entry); - strcpy(entry->d_name, "test_default"); - - char** subdir = NULL; - os_malloc(4 * sizeof(char *), subdir); - os_strdup("merged.mg", subdir[0]); - os_strdup("test_file", subdir[1]); - os_strdup("agent.conf", subdir[2]); - subdir[3] = NULL; - - OSHashNode* node1 = NULL; - os_calloc(1, sizeof(OSHashNode), node1); - node1->data = group->f_time; - - will_return(__wrap_opendir, 1); - - will_return(__wrap_readdir, entry); - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, subdir); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_default"); - will_return(__wrap_OSHash_Get_ex, group); - - // Start c_group function - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_string(__wrap_stat, __file, "etc/shared/ar.conf"); - will_return(__wrap_stat, 0); - will_return(__wrap_stat, -1); - - // Start validate_shared_files function - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - // End validate_shared_files function - - expect_string(__wrap_OS_MD5_File, fname, "etc/shared/test_default/merged.mg"); - expect_value(__wrap_OS_MD5_File, mode, OS_TEXT); - will_return(__wrap_OS_MD5_File, "1212121212121"); - will_return(__wrap_OS_MD5_File, -1); - // End c_group function - - // Start ftime_changed - expect_value(__wrap_OSHash_Get_Elem_ex, self, group->f_time); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, (OSHash *)10); - will_return(__wrap_OSHash_Get_Elem_ex, 2); - - expect_value(__wrap_OSHash_Begin, self, group->f_time); - will_return(__wrap_OSHash_Begin, node1); - - expect_value(__wrap_OSHash_Get_ex, self, (OSHash *)10); - expect_any(__wrap_OSHash_Get_ex, key); - will_return(__wrap_OSHash_Get_ex, group->f_time); - - expect_value(__wrap_OSHash_Next, self, group->f_time); - will_return(__wrap_OSHash_Next, NULL); - // End ftime_changed - - will_return(__wrap_OSHash_Clean, NULL); - - will_return(__wrap_readdir, NULL); - - process_groups(); - - os_free(entry); - os_free(node1); -} - -void test_process_multi_groups_no_groups(void **state) -{ - will_return(__wrap_wdb_get_distinct_agent_groups, NULL); - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, NULL); - - process_multi_groups(); -} - -void test_process_multi_groups_single_group(void **state) -{ - cJSON* j_agent_info = cJSON_Parse("[{\"group\":\"group1\",\"group_hash\":\"ec282560\"}]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, NULL); - - process_multi_groups(); -} - -void test_process_multi_groups_OSHash_Add_fail(void **state) -{ - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't add multigroup 'group1,group2' to hash table 'm_hash'"); - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, NULL); - - process_multi_groups(); -} - -void test_process_multi_groups_OSHash_Add_fail_multi_chunk_empty_first(void **state) -{ - cJSON* j_agent_info = cJSON_Parse("[[],[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't add multigroup 'group1,group2' to hash table 'm_hash'"); - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, NULL); - - process_multi_groups(); -} - -void test_process_multi_groups_OSHash_Add_fail_multi_chunk_empty_second(void **state) -{ - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}],[]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't add multigroup 'group1,group2' to hash table 'm_hash'"); - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, NULL); - - process_multi_groups(); -} - -void test_process_multi_groups_OSHash_Add_fail_multi_chunk(void **state) -{ - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}], [{\"group\":\"group3,group4\",\"group_hash\":\"abcdef\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't add multigroup 'group1,group2' to hash table 'm_hash'"); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group3,group4"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't add multigroup 'group3,group4' to hash table 'm_hash'"); - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, NULL); - - process_multi_groups(); -} - -void test_process_multi_groups_open_fail(void **state) -{ - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))cleaner); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 2); - - OSHashNode * hash_node; - os_calloc(1, sizeof(OSHashNode), hash_node); - w_strdup("group1,group2", hash_node->key); - hash_node->data = "ef48b4cd"; - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, hash_node); - - expect_string(__wrap_wreaddir, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_wreaddir, NULL); - errno = EACCES; - will_return(__wrap_strerror, "Permission denied"); - expect_string(__wrap__merror, formatted_msg, "Cannot open multigroup directory 'var/multigroups/ef48b4cd': Permission denied (13)"); - - expect_value(__wrap_OSHash_Next, self, m_hash); - will_return(__wrap_OSHash_Next, NULL); - - process_multi_groups(); - - errno = 0; - - os_free(hash_node->key); - os_free(hash_node); -} - -void test_process_multi_groups_find_multi_group_null(void **state) -{ - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))free_group_c_group); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't add multigroup 'group1,group2' to hash table 'm_hash'"); - - OSHashNode * hash_node; - os_calloc(1, sizeof(OSHashNode), hash_node); - w_strdup("group1,group2", hash_node->key); - hash_node->data = "ef48b4cd"; - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, hash_node); - - char** subdir = NULL; - os_malloc(2 * sizeof(char *), subdir); - os_strdup("merged.mg", subdir[0]); - subdir[1] = NULL; - - expect_string(__wrap_wreaddir, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_wreaddir, subdir); - - expect_value(__wrap_OSHash_Get_ex, self, multi_groups); - expect_string(__wrap_OSHash_Get_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Get_ex, NULL); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, multi_groups); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 2); - - // Start c_multi_group - // Open the multi-group files and generate merged - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'etc/shared': No such file or directory"); - - expect_value(__wrap_OSHash_Next, self, m_hash); - will_return(__wrap_OSHash_Next, NULL); - - process_multi_groups(); - - os_free(hash_node->key); - os_free(hash_node); -} - -void test_process_multi_groups_group_changed(void **state) -{ - group_t *group = (group_t *)state[0]; - group_t *multigroup = (group_t *)state[1]; - - state[0] = multigroup->f_time; - - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))cleaner); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 2); - - OSHashNode * hash_node; - os_calloc(1, sizeof(OSHashNode), hash_node); - w_strdup("group1,group2", hash_node->key); - hash_node->data = "ef48b4cd"; - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, hash_node); - - char** subdir = NULL; - os_malloc(2 * sizeof(char *), subdir); - os_strdup("merged.mg", subdir[0]); - subdir[1] = NULL; - - expect_string(__wrap_wreaddir, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_wreaddir, subdir); - - expect_value(__wrap_OSHash_Get_ex, self, multi_groups); - expect_string(__wrap_OSHash_Get_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Get_ex, multigroup); - - // Start group_changed - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "group1"); - will_return(__wrap_OSHash_Get_ex, group); - // End group_changed - - will_return(__wrap_OSHash_Clean, NULL); - - // Start c_multi_group - // Open the multi-group files and generate merged - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'etc/shared': No such file or directory"); - - expect_string(__wrap__mdebug2, formatted_msg, "Multigroup 'group1,group2' has changed."); - - expect_value(__wrap_OSHash_Next, self, m_hash); - will_return(__wrap_OSHash_Next, NULL); - - process_multi_groups(); - - os_free(hash_node->key); - os_free(hash_node); -} - -void test_process_multi_groups_changed_outside(void **state) -{ - group_t *group = (group_t *)state[0]; - group_t *multigroup = (group_t *)state[1]; - - group->has_changed = false; - - state[0] = multigroup->f_time; - - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))cleaner); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 2); - - OSHashNode * hash_node; - os_calloc(1, sizeof(OSHashNode), hash_node); - w_strdup("group1,group2", hash_node->key); - hash_node->data = "ef48b4cd"; - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, hash_node); - - char** subdir = NULL; - os_malloc(2 * sizeof(char *), subdir); - os_strdup("merged.mg", subdir[0]); - subdir[1] = NULL; - - expect_string(__wrap_wreaddir, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_wreaddir, subdir); - - expect_value(__wrap_OSHash_Get_ex, self, multi_groups); - expect_string(__wrap_OSHash_Get_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Get_ex, multigroup); - - // Start group_changed - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "group1"); - will_return(__wrap_OSHash_Get_ex, group); - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "group2"); - will_return(__wrap_OSHash_Get_ex, group); - // End group_changed - - will_return(__wrap_OSHash_Clean, NULL); - - // Start c_multi_group - // Open the multi-group files, no generate merged - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'var/multigroups': No such file or directory"); - - // Open the multi-group files and generate merged - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'etc/shared': No such file or directory"); - - expect_string(__wrap__mwarn, formatted_msg, "Multigroup 'group1,group2' was modified from outside, so it was regenerated."); - - expect_value(__wrap_OSHash_Next, self, m_hash); - will_return(__wrap_OSHash_Next, NULL); - - will_return(__wrap_OSHash_Clean, NULL); - - process_multi_groups(); - - os_free(hash_node->key); - os_free(hash_node); -} - -void test_process_multi_groups_changed_outside_nocmerged(void **state) -{ - group_t *group = (group_t *)state[0]; - group_t *multigroup = (group_t *)state[1]; - - group->has_changed = false; - - state[0] = multigroup->f_time; - - cJSON* j_agent_info = cJSON_Parse("[[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]]"); - - will_return(__wrap_wdb_get_distinct_agent_groups, j_agent_info); - - __real_OSHash_SetFreeDataPointer(mock_hashmap, (void (*)(void *))cleaner); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, m_hash); - expect_string(__wrap_OSHash_Add_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Add_ex, 2); - - OSHashNode * hash_node; - os_calloc(1, sizeof(OSHashNode), hash_node); - w_strdup("group1,group2", hash_node->key); - hash_node->data = "ef48b4cd"; - - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, hash_node); - - char** subdir = NULL; - os_malloc(2 * sizeof(char *), subdir); - os_strdup("merged.mg", subdir[0]); - subdir[1] = NULL; - - expect_string(__wrap_wreaddir, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_wreaddir, subdir); - - expect_value(__wrap_OSHash_Get_ex, self, multi_groups); - expect_string(__wrap_OSHash_Get_ex, key, "group1,group2"); - will_return(__wrap_OSHash_Get_ex, multigroup); - - // Start group_changed - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "group1"); - will_return(__wrap_OSHash_Get_ex, group); - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "group2"); - will_return(__wrap_OSHash_Get_ex, group); - // End group_changed - - will_return(__wrap_OSHash_Clean, NULL); - - // Start c_multi_group - // Open the multi-group files, no generate merged - expect_string(__wrap_cldir_ex_ignore, name, "var/multigroups/ef48b4cd"); - will_return(__wrap_cldir_ex_ignore, 0); - - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug2, formatted_msg, "Opening directory: 'var/multigroups': No such file or directory"); - - expect_string(__wrap__mdebug2, formatted_msg, "Multigroup 'group1,group2' was modified from outside."); - logr.nocmerged = 1; - expect_value(__wrap_OSHash_Next, self, m_hash); - will_return(__wrap_OSHash_Next, NULL); - - process_multi_groups(); - - logr.nocmerged = 0; - - os_free(hash_node->key); - os_free(hash_node); -} - -void test_c_files(void **state) -{ - expect_string(__wrap__mdebug2, formatted_msg, "Updating shared files."); - - expect_function_call(__wrap_pthread_mutex_lock); - - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "No such file or directory"); - expect_string(__wrap__mdebug1, formatted_msg, "Opening directory: 'etc/shared': No such file or directory"); - - will_return(__wrap_wdb_get_distinct_agent_groups, NULL); - - m_hash = (OSHash *)1; - expect_value(__wrap_OSHash_Begin, self, m_hash); - will_return(__wrap_OSHash_Begin, NULL); - - expect_value(__wrap_OSHash_Begin, self, groups); - will_return(__wrap_OSHash_Begin, NULL); - - will_return(__wrap_OSHash_Clean, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, (OSHash *)10); - - expect_value(__wrap_OSHash_Begin, self, multi_groups); - will_return(__wrap_OSHash_Begin, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "End updating shared files."); - - c_files(false); -} - -void test_validate_shared_files_files_null(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default'"); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_hidden_file(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup(".hidden_file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_merged_file(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("merged.mg"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_max_path_size_warning(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - char log_str[PATH_MAX + 1] = {0}; - - snprintf(log_str, PATH_MAX, "Path too long '%s/test-file'", LONG_PATH); - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-files"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, LONG_PATH); - will_return(__wrap_wreaddir, files); - - expect_string(__wrap__mwarn, formatted_msg, log_str); - - reported_path_size_exceeded = 0; - - validate_shared_files(LONG_PATH, finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_max_path_size_debug(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - char log_str[PATH_MAX + 1] = {0}; - - snprintf(log_str, PATH_MAX, "Path too long '%s/test-file'", LONG_PATH); - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-files"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, LONG_PATH); - will_return(__wrap_wreaddir, files); - - expect_string(__wrap__mdebug2, formatted_msg, log_str); - - reported_path_size_exceeded = 1; - - validate_shared_files(LONG_PATH, finalfp, &_f_time, false, false, -1); - - reported_path_size_exceeded = 0; -} - -void test_validate_shared_files_valid_file_limite_size(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - char file_str[PATH_MAX + 1] = {0}; - snprintf(file_str, PATH_MAX, "%s/test-file", LONG_PATH); - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, LONG_PATH); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, file_str); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, file_str); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, file_str); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, file_str); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files(LONG_PATH, finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_still_invalid(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - time_t *last_modify; - os_calloc(1, sizeof(time_t), last_modify); - *last_modify = 10000; - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, last_modify); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 1); - - expect_any(__wrap_OSHash_Set, self); - expect_string(__wrap_OSHash_Set, key, "etc/shared/test_default/test-file"); - expect_any(__wrap_OSHash_Set, data); - will_return(__wrap_OSHash_Set, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "File 'etc/shared/test_default/test-file' modified but still invalid."); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); - - os_free(last_modify); -} - -void test_validate_shared_files_valid_now(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - time_t *last_modify; - os_calloc(1, sizeof(time_t), last_modify); - *last_modify = 10000; - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, last_modify); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - expect_any(__wrap_OSHash_Delete, self); - expect_string(__wrap_OSHash_Delete, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Delete, NULL); - - expect_string(__wrap__minfo, formatted_msg, "File 'etc/shared/test_default/test-file' is valid after last modification."); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_valid_file(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_stat_error(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((3) * sizeof(char *), files); - files[0] = strdup("stat-error-file"); - files[1] = strdup("test-file"); - files[2] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf_err = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/stat-error-file"); - will_return(__wrap_stat, &stat_buf_err); - will_return(__wrap_stat, -1); - - expect_string(__wrap__merror, formatted_msg, "Unable to get entry attributes 'etc/shared/test_default/stat-error-file'"); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_merge_file(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - expect_value(__wrap_MergeAppendFile, finalfp, finalfp); - expect_value(__wrap_MergeAppendFile, path_offset, 0x18); - will_return(__wrap_MergeAppendFile, 1); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, true, false, -1); -} - -void test_validate_shared_files_merge_file_append_fail(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - expect_value(__wrap_MergeAppendFile, finalfp, finalfp); - expect_value(__wrap_MergeAppendFile, path_offset, 0x18); - will_return(__wrap_MergeAppendFile, 0); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, true, false, -1); -} - -void test_validate_shared_files_fail_add(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 1); - - expect_string(__wrap_OSHash_Add, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Add, 0); - - expect_string(__wrap__merror, formatted_msg, "Unable to add file 'etc/shared/test_default/test-file' to hash table of invalid files."); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_subfolder_empty(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-subfolder"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = 0040000 }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default/test-subfolder'"); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_subfolder_append_fail(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-subfolder"); - files[1] = NULL; - char ** files2 = NULL; - os_malloc((2) * sizeof(char *), files2); - files2[0] = strdup("test-file"); - files2[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = 0040000 }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_wreaddir, files2); - - struct stat stat_buf2 = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_stat, &stat_buf2); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - expect_value(__wrap_MergeAppendFile, finalfp, finalfp); - expect_value(__wrap_MergeAppendFile, path_offset, 0x18); - will_return(__wrap_MergeAppendFile, 0); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, true, false, -1); -} - -void test_validate_shared_files_valid_file_subfolder_empty(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((3) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = strdup("test-subfolder"); - files[2] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - struct stat stat_buf_2 = { .st_mode = S_IFDIR }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_stat, &stat_buf_2); - will_return(__wrap_stat, 0); - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Could not open directory 'etc/shared/test_default/test-subfolder'"); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_subfolder_valid_file(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-subfolder"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFDIR }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - // Initialize files structure - char ** files2 = NULL; - os_malloc((2) * sizeof(char *), files2); - files2[0] = strdup("test-file"); - files2[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_wreaddir, files2); - - struct stat stat_buf_2 = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_stat, &stat_buf_2); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_valid_file_subfolder_valid_file(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((3) * sizeof(char *), files); - files[0] = strdup("test-subfolder"); - files[1] = strdup("test-file-main-folder"); - files[2] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFDIR }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - // Initialize files structure - char ** files2 = NULL; - os_malloc((2) * sizeof(char *), files2); - files2[0] = strdup("test-file"); - files2[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_wreaddir, files2); - - struct stat stat_buf_2 = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_stat, &stat_buf_2); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-subfolder/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - struct stat stat_buf_3 = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-file-main-folder"); - will_return(__wrap_stat, &stat_buf_3); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-file-main-folder"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-file-main-folder"); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-file-main-folder"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_validate_shared_files_sub_subfolder_valid_file(void **state) -{ - FILE * finalfp = (FILE *)5; - OSHash *_f_time = (OSHash *)10; - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-subfolder"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default"); - will_return(__wrap_wreaddir, files); - - struct stat stat_buf = { .st_mode = S_IFDIR }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_stat, &stat_buf); - will_return(__wrap_stat, 0); - - // Initialize files structure - char ** files2 = NULL; - os_malloc((2) * sizeof(char *), files2); - files2[0] = strdup("test-subfolder2"); - files2[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default/test-subfolder"); - will_return(__wrap_wreaddir, files2); - - struct stat stat_buf_2 = { .st_mode = S_IFDIR }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder/test-subfolder2"); - will_return(__wrap_stat, &stat_buf_2); - will_return(__wrap_stat, 0); - - // Initialize files structure - char ** files3 = NULL; - os_malloc((2) * sizeof(char *), files3); - files3[0] = strdup("test-file"); - files3[1] = NULL; - - expect_string(__wrap_wreaddir, name, "etc/shared/test_default/test-subfolder/test-subfolder2"); - will_return(__wrap_wreaddir, files3); - - struct stat stat_buf_3 = { .st_mode = S_IFREG }; - expect_string(__wrap_stat, __file, "etc/shared/test_default/test-subfolder/test-subfolder2/test-file"); - will_return(__wrap_stat, &stat_buf_3); - will_return(__wrap_stat, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "etc/shared/test_default/test-subfolder/test-subfolder2/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_checkBinaryFile, f_name, "etc/shared/test_default/test-subfolder/test-subfolder2/test-file"); - will_return(__wrap_checkBinaryFile, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, (OSHash *)10); - expect_string(__wrap_OSHash_Add_ex, key, "etc/shared/test_default/test-subfolder/test-subfolder2/test-file"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_any(__wrap__merror, formatted_msg); - - validate_shared_files("etc/shared/test_default", finalfp, &_f_time, false, false, -1); -} - -void test_copy_directory_files_null(void **state) -{ - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, NULL); - - errno = 1; - expect_string(__wrap__mwarn, formatted_msg, "Could not open directory 'src_path'. Group folder was deleted."); - - copy_directory("src_path", "dst_path", "group_test"); - -} - -void test_copy_directory_hidden_file(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup(".hidden_file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - copy_directory("src_path", "dst_path", "group_test"); -} - -void test_copy_directory_merged_file(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("merged.mg"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - copy_directory("src_path", "dst_path", "group_test"); -} - -void test_copy_directory_source_path_too_long_warning(void **state) -{ - char log_str[PATH_MAX + 1] = {0}; - snprintf(log_str, PATH_MAX, "Source path too long '%s/test-file'", LONG_PATH); - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-files"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, LONG_PATH); - will_return(__wrap_wreaddir, files); - - expect_string(__wrap__mwarn, formatted_msg, log_str); - - reported_path_size_exceeded = 0; - - copy_directory(LONG_PATH, "dst_path", "group_test"); -} - -void test_copy_directory_source_path_too_long_debug(void **state) -{ - char log_str[PATH_MAX + 1] = {0}; - snprintf(log_str, PATH_MAX, "Source path too long '%s/test-file'", LONG_PATH); - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-files"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, LONG_PATH); - will_return(__wrap_wreaddir, files); - - expect_string(__wrap__mdebug2, formatted_msg, log_str); - - reported_path_size_exceeded = 1; - - copy_directory(LONG_PATH, "dst_path", "group_test"); - - reported_path_size_exceeded = 0; -} - -void test_copy_directory_destination_path_too_long_warning(void **state) -{ - char log_str[PATH_MAX + 1] = {0}; - snprintf(log_str, PATH_MAX, "Destination path too long '%s/test-file'", LONG_PATH); - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-files"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - expect_string(__wrap__mwarn, formatted_msg, log_str); - - reported_path_size_exceeded = 0; - - copy_directory("src_path", LONG_PATH, "group_test"); -} - -void test_copy_directory_destination_path_too_long_debug(void **state) -{ - char log_str[PATH_MAX + 1] = {0}; - snprintf(log_str, PATH_MAX, "Destination path too long '%s/test-file'", LONG_PATH); - - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-files"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - expect_string(__wrap__mdebug2, formatted_msg, log_str); - - reported_path_size_exceeded = 1; - - copy_directory("src_path", LONG_PATH, "group_test"); - - reported_path_size_exceeded = 0; -} - -void test_copy_directory_invalid_file(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - time_t *last_modify; - os_calloc(1, sizeof(time_t), last_modify); - *last_modify = 10000; - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/test-file"); - will_return(__wrap_OSHash_Get, last_modify); - - copy_directory("src_path", "dst_path", "group_test"); - - os_free(last_modify); -} - -void test_copy_directory_agent_conf_file(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("agent.conf"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/agent.conf"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "src_path/agent.conf"); - expect_string(__wrap_w_copy_file, dst, "dst_path/agent.conf"); - expect_value(__wrap_w_copy_file, mode, 0x61); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - copy_directory("src_path", "dst_path", "group_test"); -} - -void test_copy_directory_valid_file(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "src_path/test-file"); - expect_string(__wrap_w_copy_file, dst, "dst_path/test-file"); - expect_value(__wrap_w_copy_file, mode, 0x63); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - copy_directory("src_path", "dst_path", "group_test"); -} - -void test_copy_directory_valid_file_subfolder_file(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((3) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = strdup("subfolder"); - files[2] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "src_path/test-file"); - expect_string(__wrap_w_copy_file, dst, "dst_path/test-file"); - expect_value(__wrap_w_copy_file, mode, 0x63); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - will_return(__wrap_opendir, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Making new directory: subfolder"); - - expect_string(__wrap_mkdir, __path, "dst_path/subfolder"); - expect_value(__wrap_mkdir, __mode, 0770); - will_return(__wrap_mkdir, 0); - - // Initialize files structure - char ** files2 = NULL; - os_malloc((2) * sizeof(char *), files2); - files2[0] = strdup("test-file"); - files2[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path/subfolder"); - will_return(__wrap_wreaddir, files2); - - will_return(__wrap_opendir, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/subfolder/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "src_path/subfolder/test-file"); - expect_string(__wrap_w_copy_file, dst, "dst_path/subfolder/test-file"); - expect_value(__wrap_w_copy_file, mode, 0x63); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - copy_directory("src_path", "dst_path", "group_test"); -} - -void test_copy_directory_mkdir_fail(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("subfolder"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Making new directory: subfolder"); - - expect_string(__wrap_mkdir, __path, "dst_path/subfolder"); - expect_value(__wrap_mkdir, __mode, 0770); - will_return(__wrap_mkdir, -1); - - errno = 10; - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Cannot create directory 'dst_path/subfolder': ERROR (10)"); - - copy_directory("src_path", "dst_path", "group_test"); - errno = 0; -} - -void test_copy_directory_mkdir_exist(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((2) * sizeof(char *), files); - files[0] = strdup("subfolder"); - files[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Making new directory: subfolder"); - - expect_string(__wrap_mkdir, __path, "dst_path/subfolder"); - expect_value(__wrap_mkdir, __mode, 0770); - will_return(__wrap_mkdir, -1); - - errno = 17; - expect_string(__wrap_wreaddir, name, "src_path/subfolder"); - will_return(__wrap_wreaddir, NULL); - - expect_string(__wrap__mwarn, formatted_msg, "Could not open directory 'src_path/subfolder'. Group folder was deleted."); - - copy_directory("src_path", "dst_path", "group_test"); - errno = 0; -} - -void test_copy_directory_file_subfolder_file(void **state) -{ - // Initialize files structure - char ** files = NULL; - os_malloc((4) * sizeof(char *), files); - files[0] = strdup("test-file"); - files[1] = strdup("subfolder"); - files[2] = strdup("test-file-2"); - files[3] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path"); - will_return(__wrap_wreaddir, files); - - will_return(__wrap_opendir, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "src_path/test-file"); - expect_string(__wrap_w_copy_file, dst, "dst_path/test-file"); - expect_value(__wrap_w_copy_file, mode, 0x63); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - will_return(__wrap_opendir, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Making new directory: subfolder"); - - expect_string(__wrap_mkdir, __path, "dst_path/subfolder"); - expect_value(__wrap_mkdir, __mode, 0770); - will_return(__wrap_mkdir, 0); - - // Initialize files structure - char ** files2 = NULL; - os_malloc((2) * sizeof(char *), files2); - files2[0] = strdup("test-file"); - files2[1] = NULL; - - expect_string(__wrap_wreaddir, name, "src_path/subfolder"); - will_return(__wrap_wreaddir, files2); - - will_return(__wrap_opendir, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 10); - invalid_files = OSHash_Create(); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/subfolder/test-file"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "src_path/subfolder/test-file"); - expect_string(__wrap_w_copy_file, dst, "dst_path/subfolder/test-file"); - expect_value(__wrap_w_copy_file, mode, 0x63); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - will_return(__wrap_opendir, 0); - - expect_any(__wrap_OSHash_Get, self); - expect_string(__wrap_OSHash_Get, key, "src_path/test-file-2"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_w_copy_file, src, "src_path/test-file-2"); - expect_string(__wrap_w_copy_file, dst, "dst_path/test-file-2"); - expect_value(__wrap_w_copy_file, mode, 0x63); - expect_value(__wrap_w_copy_file, silent, 1); - will_return(__wrap_w_copy_file, 0); - - copy_directory("src_path", "dst_path", "group_test"); -} - -void test_save_controlmsg_request_error(void **state) -{ - keyentry * key = NULL; - char *r_msg = "req "; - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap__merror, formatted_msg, "Request control format error."); - expect_string(__wrap__mdebug2, formatted_msg, "r_msg = \"req \""); - - save_controlmsg(key, r_msg, msg_length, wdb_sock); -} - -void test_save_controlmsg_request_success(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - strcpy(r_msg, "req payload is here"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - - expect_string(__wrap_req_save, counter, "payload"); - expect_string(__wrap_req_save, buffer, "is here"); - expect_value(__wrap_req_save, length, OS_SIZE_128 - strlen(HC_REQUEST) - strlen("payload ")); - will_return(__wrap_req_save, 0); - - expect_string(__wrap_rem_inc_recv_ctrl_request, agent_id, "001"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); -} - -void test_save_controlmsg_invalid_msg(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, "Invalid message"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap__mwarn, formatted_msg, "Invalid message from agent: 'NEW_AGENT' (001)"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); -} - -void test_save_controlmsg_agent_invalid_version(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - char s_msg[OS_FLSIZE + 1] = {0}; - strcpy(r_msg, "agent startup {\"version\":\"v4.6.0\"}"); - snprintf(s_msg, OS_FLSIZE, "%s%s%s%s%s", CONTROL_HEADER, HC_ERROR, "{\"message\":\"", HC_INVALID_VERSION_RESPONSE, "\"}"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - memset(&key.peer_info, 0, sizeof(struct sockaddr_storage)); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "Agent NEW_AGENT sent HC_STARTUP from ''"); - - expect_string(__wrap_compare_wazuh_versions, version1, "v4.5.0"); - expect_string(__wrap_compare_wazuh_versions, version2, "v4.6.0"); - expect_value(__wrap_compare_wazuh_versions, compare_patch, false); - will_return(__wrap_compare_wazuh_versions, -1); - - expect_string(__wrap__mdebug2, formatted_msg, "Unable to connect agent: '001': 'Incompatible version'"); - - expect_value(__wrap_wdb_update_agent_status_code, id, 1); - expect_value(__wrap_wdb_update_agent_status_code, status_code, INVALID_VERSION); - expect_string(__wrap_wdb_update_agent_status_code, version, "v4.6.0"); - expect_string(__wrap_wdb_update_agent_status_code, sync_status, "synced"); - will_return(__wrap_wdb_update_agent_status_code, OS_SUCCESS); - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, s_msg); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); -} - -void test_save_controlmsg_get_agent_version_fail(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - char s_msg[OS_FLSIZE + 1] = {0}; - strcpy(r_msg, "agent startup {\"test\":\"fail\"}"); - snprintf(s_msg, OS_FLSIZE, "%s%s%s%s%s", CONTROL_HEADER, HC_ERROR, "{\"message\":\"", HC_RETRIEVE_VERSION, "\"}"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - memset(&key.peer_info, 0, sizeof(struct sockaddr_storage)); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "Agent NEW_AGENT sent HC_STARTUP from ''"); - expect_string(__wrap__merror, formatted_msg, "Error getting version from agent '001'"); - - expect_string(__wrap__mdebug2, formatted_msg, "Unable to connect agent: '001': 'Couldn't retrieve version'"); - - expect_value(__wrap_wdb_update_agent_status_code, id, 1); - expect_value(__wrap_wdb_update_agent_status_code, status_code, ERR_VERSION_RECV); - expect_string(__wrap_wdb_update_agent_status_code, sync_status, "synced"); - will_return(__wrap_wdb_update_agent_status_code, OS_INVALID); - - expect_string(__wrap__mwarn, formatted_msg, "Unable to set status code for agent: '001'"); - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, s_msg); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); -} - -void test_save_controlmsg_could_not_add_pending_data(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, "Invalid message \n with enter"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, "#!-agent ack "); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - expect_string(__wrap_rem_inc_recv_ctrl_keepalive, agent_id, "001"); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, NULL); - - expect_string(__wrap_OSHash_Add, key, "001"); - will_return(__wrap_OSHash_Add, 0); - - expect_string(__wrap__merror, formatted_msg, "Couldn't add pending data into hash table."); - - expect_function_call(__wrap_pthread_mutex_unlock); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); -} - -void test_save_controlmsg_unable_to_save_last_keepalive(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, "Invalid message \n with enter"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, "#!-agent ack "); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - expect_string(__wrap_rem_inc_recv_ctrl_keepalive, agent_id, "001"); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - pending_data_t data; - char * message = strdup("Invalid message \n"); - data.changed = true; - data.message = message; - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, &data); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_wdb_update_agent_keepalive, id, 1); - expect_string(__wrap_wdb_update_agent_keepalive, connection_status, AGENT_CS_ACTIVE); - expect_string(__wrap_wdb_update_agent_keepalive, sync_status, "synced"); - will_return(__wrap_wdb_update_agent_keepalive, OS_INVALID); - - expect_string(__wrap__mwarn, formatted_msg, "Unable to save last keepalive and set connection status as active for agent: 001"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - free_keyentry(&key); - os_free(data.message); -} - -void test_save_controlmsg_update_msg_error_parsing(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, "valid message \n with enter"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, "#!-agent ack "); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - expect_string(__wrap_rem_inc_recv_ctrl_keepalive, agent_id, "001"); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - pending_data_t *data; - os_calloc(1, sizeof(struct pending_data_t), data); - char * message = strdup("different message"); - data->changed = true; - data->message = message; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, data); - - expect_string(__wrap__mdebug2, formatted_msg, "save_controlmsg(): inserting 'valid message \n'"); - - groups = (OSHash *)10; - multi_groups = (OSHash *)10; - - char* group = NULL; - w_strdup("test_group", group); - expect_value(__wrap_wdb_get_agent_group, id, 1); - will_return(__wrap_wdb_get_agent_group, group); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_string(__wrap__mdebug2, formatted_msg, "Agent '001' group is 'test_group'"); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_group"); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_value(__wrap_OSHash_Get_ex, self, multi_groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_group"); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "No such group 'test_group' for agent '001'"); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_mutex_unlock); - - agent_info_data *agent_data; - os_calloc(1, sizeof(agent_info_data), agent_data); - agent_data->id = 1; - - expect_string(__wrap_parse_agent_update_msg, msg, "valid message \n"); - will_return(__wrap_parse_agent_update_msg, agent_data); - will_return(__wrap_parse_agent_update_msg, OS_INVALID); - - expect_string(__wrap__merror, formatted_msg, "Error parsing message for agent '001'"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - os_free(agent_data); - - free_keyentry(&key); - os_free(data->message); - os_free(data->group); - os_free(data); -} - -void test_save_controlmsg_update_msg_unable_to_update_information(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, "valid message \n with enter"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, "#!-agent ack "); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - expect_string(__wrap_rem_inc_recv_ctrl_keepalive, agent_id, "001"); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - pending_data_t *data; - os_calloc(1, sizeof(struct pending_data_t), data); - char * message = strdup("different message"); - data->changed = false; - data->message = message; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, data); - - expect_string(__wrap__mdebug2, formatted_msg, "save_controlmsg(): inserting 'valid message \n'"); - - groups = (OSHash *)10; - multi_groups = (OSHash *)10; - - group_t *group = NULL; - os_calloc(1, sizeof(group_t), group); - group->name = strdup("test_group"); - memset(&group->merged_sum, 0, sizeof(os_md5)); - snprintf(group->merged_sum, 7, "112359"); - - expect_function_call(__wrap_pthread_mutex_lock); - - char* group_name = NULL; - w_strdup("test_group", group_name); - expect_value(__wrap_wdb_get_agent_group, id, 1); - will_return(__wrap_wdb_get_agent_group, group_name); - - expect_string(__wrap__mdebug2, formatted_msg, "Agent '001' group is 'test_group'"); - - expect_value(__wrap_OSHash_Get_ex, self, groups); - expect_string(__wrap_OSHash_Get_ex, key, "test_group"); - will_return(__wrap_OSHash_Get_ex, group); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_mutex_unlock); - - agent_info_data *agent_data; - os_calloc(1, sizeof(agent_info_data), agent_data); - agent_data->id = 1; - os_strdup("managerHost", agent_data->manager_host); - os_strdup("10.2.2.2", agent_data->agent_ip); - os_strdup("version 4.3", agent_data->version); - os_strdup("112358", agent_data->merged_sum); - - os_strdup("NodeName", node_name); - - expect_string(__wrap_parse_agent_update_msg, msg, "valid message \n"); - will_return(__wrap_parse_agent_update_msg, agent_data); - will_return(__wrap_parse_agent_update_msg, OS_SUCCESS); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_any(__wrap_wdb_update_agent_data, agent_data); - will_return(__wrap_wdb_update_agent_data, OS_INVALID); - - os_calloc(1, sizeof(w_linked_queue_t), pending_queue); - - expect_any(__wrap_linked_queue_push_ex, queue); - expect_any(__wrap_linked_queue_push_ex, data); - - expect_string(__wrap__mdebug1, formatted_msg, "Unable to update information in global.db for agent: 001"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - os_free(group->name); - os_free(group); - - os_free(agent_data->manager_host); - os_free(agent_data); - - os_free(node_name); - - free_keyentry(&key); - os_free(data->message); - os_free(data->group); - os_free(data); -} - -void test_save_controlmsg_update_msg_lookfor_agent_group_fail(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, "valid message \n with enter"); - - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, "#!-agent ack "); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - expect_string(__wrap_rem_inc_recv_ctrl_keepalive, agent_id, "001"); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - pending_data_t *data; - os_calloc(1, sizeof(struct pending_data_t), data); - char * message = strdup("different message"); - data->changed = false; - data->message = message; - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, data); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_string(__wrap__mdebug2, formatted_msg, "save_controlmsg(): inserting 'valid message \n'"); - - expect_value(__wrap_wdb_get_agent_group, id, 1); - will_return(__wrap_wdb_get_agent_group, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__merror, formatted_msg, "Error getting group for agent '001'"); - - agent_info_data *agent_data; - os_calloc(1, sizeof(agent_info_data), agent_data); - agent_data->id = 1; - os_strdup("manager_host", agent_data->manager_host); - os_strdup("10.2.2.2", agent_data->agent_ip); - os_strdup("version 4.3", agent_data->version); - os_strdup("112358", agent_data->merged_sum); - - expect_string(__wrap_parse_agent_update_msg, msg, "valid message \n"); - will_return(__wrap_parse_agent_update_msg, agent_data); - will_return(__wrap_parse_agent_update_msg, OS_SUCCESS); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_any(__wrap_wdb_update_agent_data, agent_data); - will_return(__wrap_wdb_update_agent_data, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Unable to update information in global.db for agent: 001"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - os_free(agent_data->manager_host); - os_free(agent_data); - - free_keyentry(&key); - os_free(data->message); - os_free(data->group); - os_free(data); -} - -void test_save_controlmsg_startup(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, "agent startup {\"version\":\"v4.5.0\"}"); - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - key.peer_info.ss_family = 0; - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_string(__wrap_send_msg, agent_id, "001"); - expect_string(__wrap_send_msg, msg, "#!-agent ack "); - - expect_string(__wrap_rem_inc_send_ack, agent_id, "001"); - - expect_string(__wrap_rem_inc_recv_ctrl_startup, agent_id, "001"); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent NEW_AGENT sent HC_STARTUP from ''"); - - expect_string(__wrap_compare_wazuh_versions, version1, "v4.5.0"); - expect_string(__wrap_compare_wazuh_versions, version2, "v4.5.0"); - expect_value(__wrap_compare_wazuh_versions, compare_patch, false); - will_return(__wrap_compare_wazuh_versions, 0); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - pending_data_t data; - char * message = strdup("startup message \n"); - data.changed = false; - data.message = message; - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, &data); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_wdb_update_agent_keepalive, id, 1); - expect_string(__wrap_wdb_update_agent_keepalive, connection_status, AGENT_CS_PENDING); - expect_string(__wrap_wdb_update_agent_keepalive, sync_status, "synced"); - will_return(__wrap_wdb_update_agent_keepalive, OS_INVALID); - - expect_string(__wrap__mwarn, formatted_msg, "Unable to save last keepalive and set connection status as pending for agent: 001"); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); - os_free(message); -} - -void test_save_controlmsg_shutdown(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, HC_SHUTDOWN); - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - memset(&key.peer_info, 0, sizeof(struct sockaddr_storage)); - key.peer_info.ss_family = AF_INET; - - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_any(__wrap_get_ipv4_string, address); - expect_any(__wrap_get_ipv4_string, address_size); - will_return(__wrap_get_ipv4_string, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent NEW_AGENT sent HC_SHUTDOWN from ''"); - - expect_string(__wrap_rem_inc_recv_ctrl_shutdown, agent_id, "001"); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - pending_data_t data; - char * message = strdup("shutdown message \n"); - data.changed = false; - data.message = message; - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, &data); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_wdb_update_agent_connection_status, id, 1); - expect_string(__wrap_wdb_update_agent_connection_status, connection_status, AGENT_CS_DISCONNECTED); - expect_string(__wrap_wdb_update_agent_connection_status, sync_status, "synced"); - will_return(__wrap_wdb_update_agent_connection_status, OS_SUCCESS); - - expect_string(__wrap_SendMSG, message, "1:wazuh-remoted:ossec: Agent stopped: 'NEW_AGENT->10.2.2.5'."); - expect_string(__wrap_SendMSG, locmsg, "[001] (NEW_AGENT) 10.2.2.5"); - expect_any(__wrap_SendMSG, loc); - will_return(__wrap_SendMSG, -1); - - will_return(__wrap_strerror, "fail"); - expect_string(__wrap__merror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'fail'"); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, -1); - - expect_string(__wrap__minfo, formatted_msg, "Successfully reconnected to 'queue/sockets/queue'"); - - expect_string(__wrap_SendMSG, message, "1:wazuh-remoted:ossec: Agent stopped: 'NEW_AGENT->10.2.2.5'."); - expect_string(__wrap_SendMSG, locmsg, "[001] (NEW_AGENT) 10.2.2.5"); - expect_any(__wrap_SendMSG, loc); - will_return(__wrap_SendMSG, -1); - - will_return(__wrap_strerror, "fail"); - expect_string(__wrap__merror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'fail'"); - - will_return(__wrap_OSHash_Delete_ex, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, "001"); - expect_value(__wrap_OSHash_Delete_ex, self, agent_data_hash); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); - os_free(message); -} - -void test_save_controlmsg_shutdown_wdb_fail(void **state) -{ - char r_msg[OS_SIZE_128] = {0}; - strcpy(r_msg, HC_SHUTDOWN); - keyentry key; - keyentry_init(&key, "NEW_AGENT", "001", "10.2.2.5", NULL); - memset(&key.peer_info, 0, sizeof(struct sockaddr_storage)); - key.peer_info.ss_family = AF_INET6; - size_t msg_length = sizeof(r_msg); - int *wdb_sock = NULL; - - expect_any(__wrap_get_ipv6_string, address); - expect_any(__wrap_get_ipv6_string, address_size); - will_return(__wrap_get_ipv6_string, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Agent NEW_AGENT sent HC_SHUTDOWN from ''"); - - expect_string(__wrap_rem_inc_recv_ctrl_shutdown, agent_id, "001"); - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, 1); - pending_data = OSHash_Create(); - - pending_data_t data; - char * message = strdup("shutdown message \n"); - data.changed = false; - data.message = message; - - expect_value(__wrap_OSHash_Get, self, pending_data); - expect_string(__wrap_OSHash_Get, key, "001"); - will_return(__wrap_OSHash_Get, &data); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_wdb_update_agent_connection_status, id, 1); - expect_string(__wrap_wdb_update_agent_connection_status, connection_status, AGENT_CS_DISCONNECTED); - expect_string(__wrap_wdb_update_agent_connection_status, sync_status, "synced"); - will_return(__wrap_wdb_update_agent_connection_status, OS_INVALID); - - expect_string(__wrap__mwarn, formatted_msg, "Unable to set connection status as disconnected for agent: 001"); - - will_return(__wrap_OSHash_Delete_ex, NULL); - expect_string(__wrap_OSHash_Delete_ex, key, "001"); - expect_value(__wrap_OSHash_Delete_ex, self, agent_data_hash); - - save_controlmsg(&key, r_msg, msg_length, wdb_sock); - - free_keyentry(&key); - os_free(message); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests lookfor_agent_group - cmocka_unit_test(test_lookfor_agent_group_with_group), - cmocka_unit_test(test_lookfor_agent_group_set_default_group), - cmocka_unit_test(test_lookfor_agent_group_set_group_worker), - cmocka_unit_test(test_lookfor_agent_group_set_group_worker_error), - cmocka_unit_test(test_lookfor_agent_group_msg_without_enter), - cmocka_unit_test(test_lookfor_agent_group_bad_message), - cmocka_unit_test(test_lookfor_agent_group_message_without_second_enter), - // Tests c_group - cmocka_unit_test_setup_teardown(test_c_group_no_changes, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_no_changes_disk, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_changes, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_changes_disk, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_fail, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_fail_disk, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_downloaded_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_downloaded_file_no_poll, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_downloaded_file_is_corrupted, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_download_all_files, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_no_create_shared_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_invalid_share_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_append_file_error, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_append_ar_error, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_truncate_error, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_c_group_truncate_error_disk, test_c_group_setup, test_c_group_teardown), - // Tests c_multi_group - cmocka_unit_test(test_c_multi_group_hash_multigroup_null), - cmocka_unit_test(test_c_multi_group_open_directory_fail), - cmocka_unit_test(test_c_multi_group_call_copy_directory), - cmocka_unit_test(test_c_multi_group_read_dir_fail_no_entry), - cmocka_unit_test(test_c_multi_group_Ignore_hidden_files), - cmocka_unit_test(test_c_multi_group_subdir_fail), - cmocka_unit_test(test_c_multi_group_call_c_group), - // Test find_group_from_sum - cmocka_unit_test_setup_teardown(test_find_group_from_file_found, test_find_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_find_group_from_file_not_found, test_find_group_setup, test_c_group_teardown), - // Test find_multi_group_from_sum - cmocka_unit_test_setup_teardown(test_find_multi_group_from_file_found, test_find_multi_group_setup, test_c_multi_group_teardown), - cmocka_unit_test_setup_teardown(test_find_multi_group_from_file_not_found, test_find_multi_group_setup, test_c_multi_group_teardown), - // Test ftime_changed - cmocka_unit_test_setup_teardown(test_ftime_changed_same_fsum, test_ftime_changed_setup, test_ftime_changed_teardown), - cmocka_unit_test_setup_teardown(test_ftime_changed_different_fsum_sum, test_ftime_changed_setup, test_ftime_changed_teardown), - cmocka_unit_test_setup_teardown(test_ftime_changed_different_fsum_name, test_ftime_changed_setup, test_ftime_changed_teardown), - cmocka_unit_test_setup_teardown(test_ftime_changed_different_size, test_ftime_changed_setup, test_ftime_changed_teardown), - cmocka_unit_test_setup_teardown(test_ftime_changed_one_null, test_ftime_changed_setup, test_ftime_changed_teardown), - cmocka_unit_test(test_ftime_changed_both_null), - // Test group_changed - cmocka_unit_test_setup_teardown(test_group_changed_not_changed, test_find_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_group_changed_has_changed, test_find_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_group_changed_not_exists, test_find_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_group_changed_invalid_group, test_find_group_setup, test_c_group_teardown), - // Test process_deleted_groups - cmocka_unit_test_setup_teardown(test_process_deleted_groups_delete, test_process_deleted_groups_setup, test_process_deleted_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_deleted_groups_no_changes, test_find_group_setup, test_c_group_teardown), - // Test process_deleted_multi_groups - cmocka_unit_test_setup_teardown(test_process_deleted_multi_groups_delete, test_process_deleted_multi_groups_setup, test_process_deleted_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_deleted_multi_groups_no_changes, test_find_multi_group_setup, test_c_multi_group_teardown), - cmocka_unit_test_setup_teardown(test_process_deleted_multi_groups_no_changes_initial_scan, test_find_multi_group_setup, test_c_multi_group_teardown), - // Test process_groups - cmocka_unit_test(test_process_groups_open_directory_fail), - cmocka_unit_test(test_process_groups_readdir_fail), - cmocka_unit_test(test_process_groups_subdir_null), - cmocka_unit_test(test_process_groups_skip), - cmocka_unit_test(test_process_groups_skip_2), - cmocka_unit_test_setup_teardown(test_process_groups_find_group_null, test_process_group_setup, test_process_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_groups_find_group_changed, test_process_group_setup, test_process_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_groups_find_group_not_changed, test_process_group_setup, test_process_groups_teardown), - // Test process_multi_groups - cmocka_unit_test(test_process_multi_groups_no_groups), - cmocka_unit_test(test_process_multi_groups_single_group), - cmocka_unit_test(test_process_multi_groups_OSHash_Add_fail), - cmocka_unit_test(test_process_multi_groups_OSHash_Add_fail_multi_chunk_empty_first), - cmocka_unit_test(test_process_multi_groups_OSHash_Add_fail_multi_chunk_empty_second), - cmocka_unit_test(test_process_multi_groups_OSHash_Add_fail_multi_chunk), - cmocka_unit_test_setup_teardown(test_process_multi_groups_open_fail, test_process_multi_groups_setup, test_process_multi_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_multi_groups_find_multi_group_null, test_process_multi_groups_setup, test_process_multi_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_multi_groups_group_changed, test_process_multi_groups_groups_setup, test_process_multi_groups_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_multi_groups_changed_outside, test_process_multi_groups_groups_setup, test_process_multi_groups_groups_teardown), - cmocka_unit_test_setup_teardown(test_process_multi_groups_changed_outside_nocmerged, test_process_multi_groups_groups_setup, test_process_multi_groups_groups_teardown), - // Test c_files - cmocka_unit_test_setup_teardown(test_c_files, test_c_files_setup, test_c_files_teardown), - // Test validate_shared_files - cmocka_unit_test_setup_teardown(test_validate_shared_files_files_null, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_hidden_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_merged_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_max_path_size_warning, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_max_path_size_debug, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_valid_file_limite_size, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_still_invalid, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_valid_now, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_valid_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_fail_add, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_stat_error, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_merge_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_merge_file_append_fail, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_subfolder_empty, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_subfolder_append_fail, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_valid_file_subfolder_empty, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_subfolder_valid_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_valid_file_subfolder_valid_file, test_c_group_setup, test_c_group_teardown), - cmocka_unit_test_setup_teardown(test_validate_shared_files_sub_subfolder_valid_file, test_c_group_setup, test_c_group_teardown), - // Test copy_directory - cmocka_unit_test(test_copy_directory_files_null), - cmocka_unit_test(test_copy_directory_hidden_file), - cmocka_unit_test(test_copy_directory_merged_file), - cmocka_unit_test(test_copy_directory_source_path_too_long_warning), - cmocka_unit_test(test_copy_directory_source_path_too_long_debug), - cmocka_unit_test(test_copy_directory_destination_path_too_long_warning), - cmocka_unit_test(test_copy_directory_destination_path_too_long_debug), - cmocka_unit_test(test_copy_directory_invalid_file), - cmocka_unit_test(test_copy_directory_agent_conf_file), - cmocka_unit_test(test_copy_directory_valid_file), - cmocka_unit_test(test_copy_directory_valid_file_subfolder_file), - cmocka_unit_test(test_copy_directory_mkdir_fail), - cmocka_unit_test(test_copy_directory_mkdir_exist), - cmocka_unit_test(test_copy_directory_file_subfolder_file), - // Tests save_controlmsg - cmocka_unit_test(test_save_controlmsg_request_error), - cmocka_unit_test(test_save_controlmsg_request_success), - cmocka_unit_test(test_save_controlmsg_invalid_msg), - cmocka_unit_test_setup_teardown(test_save_controlmsg_agent_invalid_version, setup_globals_no_test_mode, teardown_globals), - cmocka_unit_test_setup_teardown(test_save_controlmsg_get_agent_version_fail, setup_test_mode, teardown_test_mode), - cmocka_unit_test_setup_teardown(test_save_controlmsg_could_not_add_pending_data, setup_test_mode, teardown_test_mode), - cmocka_unit_test_setup_teardown(test_save_controlmsg_unable_to_save_last_keepalive, setup_test_mode, teardown_test_mode), - cmocka_unit_test_setup_teardown(test_save_controlmsg_update_msg_error_parsing, setup_test_mode, teardown_test_mode), - cmocka_unit_test_setup_teardown(test_save_controlmsg_update_msg_unable_to_update_information, setup_test_mode, teardown_test_mode), - cmocka_unit_test_setup_teardown(test_save_controlmsg_update_msg_lookfor_agent_group_fail, setup_test_mode, teardown_test_mode), - cmocka_unit_test_setup_teardown(test_save_controlmsg_startup, setup_globals, teardown_globals), - cmocka_unit_test_setup_teardown(test_save_controlmsg_shutdown, setup_globals, teardown_globals), - cmocka_unit_test_setup_teardown(test_save_controlmsg_shutdown_wdb_fail, setup_globals, teardown_globals), - }; - return cmocka_run_group_tests(tests, test_setup_group, test_teardown_group); -} diff --git a/src/unit_tests/remoted/test_netbuffer.c b/src/unit_tests/remoted/test_netbuffer.c deleted file mode 100644 index a6eb25635dd..00000000000 --- a/src/unit_tests/remoted/test_netbuffer.c +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../remoted/remoted.h" - -#include "../wrappers/common.h" -#include "../wrappers/linux/socket_wrappers.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/shared/bqueue_op_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/notify_op_wrappers.h" -#include "../wrappers/wazuh/remoted/queue_wrappers.h" - -extern wnotify_t * notify; -extern unsigned int send_chunk; - -int sock = 15; - -/* setup/teardown */ - -static int test_setup(void ** state) { - test_mode = 1; - - send_buffer_size = 100; - - netbuffer_t *netbuffer; - struct sockaddr_storage peer_info; - - memset(&peer_info, 0, sizeof(struct sockaddr_storage)); - - os_calloc(1, sizeof(netbuffer_t), netbuffer); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - nb_open(netbuffer, sock, &peer_info); - - *state = netbuffer; - - os_calloc(1, sizeof(wnotify_t), notify); - - send_chunk = 14; - - return 0; -} - -static int test_teardown(void ** state) { - test_mode = 0; - - netbuffer_t *netbuffer = *state; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - nb_close(netbuffer, sock); - os_free(netbuffer->buffers); - os_free(netbuffer); - - os_free(notify); - - return 0; -} - -/* Tests */ - -void test_nb_queue_ok(void ** state) { - netbuffer_t *netbuffer = *state; - char msg[10] = {0}; - char final_msg[14] = {0}; - - ssize_t size = snprintf(msg, 10, "abcdefghi"); - ssize_t final_size = snprintf(final_msg, 14, "4321abcdefghi"); - char *agent_id = "001"; - - expect_value(__wrap_wnet_order, value, 9); - will_return(__wrap_wnet_order, 0b00110001001100100011001100110100); //1234 - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_push, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_memory(__wrap_bqueue_push, data, final_msg, final_size); - expect_value(__wrap_bqueue_push, length, final_size); - expect_value(__wrap_bqueue_push, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_push, 0); - - expect_memory(__wrap_bqueue_used, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - will_return(__wrap_bqueue_used, final_size); - - expect_memory(__wrap_wnotify_modify, notify, notify, sizeof(wnotify_t *)); - expect_value(__wrap_wnotify_modify, fd, sock); - expect_value(__wrap_wnotify_modify, op, WO_READ | WO_WRITE); - will_return(__wrap_wnotify_modify, 0); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_queue(netbuffer, sock, msg, size, agent_id); - - assert_int_equal(retval, 0); -} - -void test_nb_queue_retry_ok(void ** state) { - netbuffer_t *netbuffer = *state; - char msg[10] = {0}; - char final_msg[14] = {0}; - - ssize_t size = snprintf(msg, 10, "abcdefghi"); - ssize_t final_size = snprintf(final_msg, 14, "4321abcdefghi"); - char *agent_id = "001"; - - send_timeout_to_retry = 5; - - expect_value(__wrap_wnet_order, value, 9); - will_return(__wrap_wnet_order, 0b00110001001100100011001100110100); //1234 - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_push, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_memory(__wrap_bqueue_push, data, final_msg, final_size); - expect_value(__wrap_bqueue_push, length, final_size); - expect_value(__wrap_bqueue_push, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_push, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "Not enough buffer space. Retrying... [buffer_size=100, used=0, msg_size=9]"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_sleep, seconds, 5); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_push, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_memory(__wrap_bqueue_push, data, final_msg, final_size); - expect_value(__wrap_bqueue_push, length, final_size); - expect_value(__wrap_bqueue_push, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_push, 0); - - expect_memory(__wrap_bqueue_used, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - will_return(__wrap_bqueue_used, final_size); - - expect_memory(__wrap_wnotify_modify, notify, notify, sizeof(wnotify_t *)); - expect_value(__wrap_wnotify_modify, fd, sock); - expect_value(__wrap_wnotify_modify, op, WO_READ | WO_WRITE); - will_return(__wrap_wnotify_modify, 0); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_queue(netbuffer, sock, msg, size, agent_id); - - assert_int_equal(retval, 0); -} - -void test_nb_queue_retry_err(void ** state) { - netbuffer_t *netbuffer = *state; - char msg[10] = {0}; - char final_msg[14] = {0}; - - ssize_t size = snprintf(msg, 10, "abcdefghi"); - ssize_t final_size = snprintf(final_msg, 14, "4321abcdefghi"); - char *agent_id = "001"; - - send_timeout_to_retry = 5; - - expect_value(__wrap_wnet_order, value, 9); - will_return(__wrap_wnet_order, 0b00110001001100100011001100110100); //1234 - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_push, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_memory(__wrap_bqueue_push, data, final_msg, final_size); - expect_value(__wrap_bqueue_push, length, final_size); - expect_value(__wrap_bqueue_push, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_push, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "Not enough buffer space. Retrying... [buffer_size=100, used=0, msg_size=9]"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_sleep, seconds, 5); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_push, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_memory(__wrap_bqueue_push, data, final_msg, final_size); - expect_value(__wrap_bqueue_push, length, final_size); - expect_value(__wrap_bqueue_push, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_push, -1); - - expect_string(__wrap_rem_inc_send_discarded, agent_id, agent_id); - - expect_string(__wrap__mwarn, formatted_msg, "Package dropped. Could not append data into buffer."); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_queue(netbuffer, sock, msg, size, agent_id); - - assert_int_equal(retval, -1); -} - -void test_nb_send_ok(void ** state) { - netbuffer_t *netbuffer = *state; - char final_msg[14] = {0}; - - ssize_t final_size = snprintf(final_msg, 14, "4321abcdefghi"); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_peek, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_value(__wrap_bqueue_peek, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_peek, 1); - will_return(__wrap_bqueue_peek, final_msg); - will_return(__wrap_bqueue_peek, final_size); - - will_return(__wrap_send, final_size); - - expect_memory(__wrap_bqueue_drop, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_value(__wrap_bqueue_drop, length, final_size); - will_return(__wrap_bqueue_drop, final_size); - - expect_memory(__wrap_bqueue_used, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - will_return(__wrap_bqueue_used, 0); - - expect_memory(__wrap_wnotify_modify, notify, notify, sizeof(wnotify_t *)); - expect_value(__wrap_wnotify_modify, fd, sock); - expect_value(__wrap_wnotify_modify, op, WO_READ); - will_return(__wrap_wnotify_modify, 0); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_send(netbuffer, sock); - - assert_int_equal(retval, final_size); -} - -void test_nb_send_zero_ok(void ** state) { - netbuffer_t *netbuffer = *state; - char final_msg[14] = {0}; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_peek, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_value(__wrap_bqueue_peek, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_peek, 0); - will_return(__wrap_bqueue_peek, 0); - - expect_memory(__wrap_wnotify_modify, notify, notify, sizeof(wnotify_t *)); - expect_value(__wrap_wnotify_modify, fd, sock); - expect_value(__wrap_wnotify_modify, op, WO_READ); - will_return(__wrap_wnotify_modify, 0); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_send(netbuffer, sock); - - assert_int_equal(retval, 0); -} - -void test_nb_send_would_block_ok(void ** state) { - netbuffer_t *netbuffer = *state; - char final_msg[14] = {0}; - - ssize_t final_size = snprintf(final_msg, 14, "4321abcdefghi"); - - errno = EWOULDBLOCK; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_peek, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_value(__wrap_bqueue_peek, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_peek, 1); - will_return(__wrap_bqueue_peek, final_msg); - will_return(__wrap_bqueue_peek, final_size); - - will_return(__wrap_send, -1); - - expect_memory(__wrap_bqueue_used, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - will_return(__wrap_bqueue_used, final_size); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_send(netbuffer, sock); - - assert_int_equal(retval, -1); -} - -void test_nb_send_err(void ** state) { - netbuffer_t *netbuffer = *state; - char final_msg[14] = {0}; - - ssize_t final_size = snprintf(final_msg, 14, "4321abcdefghi"); - - errno = ECONNRESET; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_memory(__wrap_bqueue_peek, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - expect_value(__wrap_bqueue_peek, flags, BQUEUE_NOFLAG); - will_return(__wrap_bqueue_peek, 1); - will_return(__wrap_bqueue_peek, final_msg); - will_return(__wrap_bqueue_peek, final_size); - - will_return(__wrap_send, -1); - - expect_string(__wrap__merror, formatted_msg, "Could not send data to socket 15: Connection reset by peer (104)"); - - expect_memory(__wrap_bqueue_used, queue, (bqueue_t *)netbuffer->buffers[sock].bqueue, sizeof(bqueue_t *)); - will_return(__wrap_bqueue_used, 0); - - expect_memory(__wrap_wnotify_modify, notify, notify, sizeof(wnotify_t *)); - expect_value(__wrap_wnotify_modify, fd, sock); - expect_value(__wrap_wnotify_modify, op, WO_READ); - will_return(__wrap_wnotify_modify, 0); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_send(netbuffer, sock); - - assert_int_equal(retval, -1); -} - -void test_nb_recv_incomplete_first_message(void ** state) { - netbuffer_t *netbuffer = *state; - char buffer_data[14] = {0xFB,0x03,0x00,0x00,0x21,0x31,0x36,0x30,0x37,0x21,0x23,0x41,0x45,0x53}; - - void *buffer = &buffer_data; - os_calloc(14, sizeof(char*), netbuffer->buffers[sock].data); - memcpy((char*)netbuffer->buffers[sock].data, (char*)buffer, 14); - - netbuffer->buffers[sock].data_len = 0; - - expect_function_call(__wrap_pthread_mutex_lock); - - will_return(__wrap_recv, 14); - - expect_value(__wrap_wnet_order, value, 1019); - will_return(__wrap_wnet_order, 1019); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_recv(netbuffer, sock); - - assert_int_equal(retval, 14); -} - -void test_nb_recv_incomplete_second_message(void ** state) { - netbuffer_t *netbuffer = *state; - char buffer_data[26] = {0x08,0x00,0x00,0x00,0x21,0x31,0x36,0x30,0x37,0x37,0x31,0x36,0xFB,0x03,0x00,0x00,0x21,0x31,0x36,0x30,0x37,0x21,0x23,0x41,0x45,0x53}; - - void *buffer = &buffer_data; - os_calloc(26, sizeof(char*), netbuffer->buffers[sock].data); - memcpy((char*)netbuffer->buffers[sock].data, (char*)buffer, 26); - - netbuffer->buffers[sock].data_len = 0; - - expect_function_call(__wrap_pthread_mutex_lock); - - will_return(__wrap_recv, 26); - - expect_value(__wrap_wnet_order, value, 8); - will_return(__wrap_wnet_order, 8); - - expect_value(__wrap_rem_msgpush, size, 8); - expect_value(__wrap_rem_msgpush, addr, (struct sockaddr_storage *)&netbuffer->buffers[sock].peer_info); - expect_value(__wrap_rem_msgpush, sock, 15); - will_return(__wrap_rem_msgpush, 0); - - expect_value(__wrap_wnet_order, value, 1019); - will_return(__wrap_wnet_order, 1019); - - expect_function_call(__wrap_pthread_mutex_unlock); - - int retval = nb_recv(netbuffer, sock); - - assert_int_equal(retval, 26); - assert_int_equal(*(uint32_t *)netbuffer->buffers[sock].data, 1019); - assert_int_equal(netbuffer->buffers[sock].data_len, 14); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_nb_queue_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_queue_retry_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_queue_retry_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_send_zero_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_send_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_send_would_block_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_send_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_recv_incomplete_first_message, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_nb_recv_incomplete_second_message, test_setup, test_teardown), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/remoted/test_remcom.c b/src/unit_tests/remoted/test_remcom.c deleted file mode 100644 index 1a95eb1adbf..00000000000 --- a/src/unit_tests/remoted/test_remcom.c +++ /dev/null @@ -1,745 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../remoted/remoted.h" -#include "../../remoted/state.h" - -#include "../wrappers/posix/select_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/remoted/state_wrappers.h" -#include "../wrappers/wazuh/remoted/config_wrappers.h" -#include "../wrappers/wazuh/remoted/manager_wrappers.h" - -char* remcom_output_builder(int error_code, const char* message, cJSON* data_json); -size_t remcom_dispatch(char * command, char ** output); - -/* setup/teardown */ - -static int test_teardown(void ** state) { - char* string = *state; - os_free(string); - return 0; -} - -// Wrappers - -int __wrap_accept() { - return mock(); -} - -/* Tests */ - -void test_remcom_output_builder(void ** state) { - int error_code = 5; - const char* message = "test msg"; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "remoted"); - - char* msg = remcom_output_builder(error_code, message, data_json); - - *state = msg; - - assert_non_null(msg); - assert_string_equal(msg, "{\"error\":5,\"message\":\"test msg\",\"data\":{\"test1\":18,\"test2\":\"remoted\"}}"); -} - -void test_remcom_dispatch_getstats(void ** state) { - char* request = "{\"command\":\"getstats\"}"; - char *response = NULL; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "remoted"); - - will_return(__wrap_rem_create_state_json, data_json); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":18,\"test2\":\"remoted\"}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getconfig(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{\"section\":\"remote\"}}"; - char *response = NULL; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 15); - cJSON_AddStringToObject(data_json, "test2", "remoted"); - - will_return(__wrap_getRemoteConfig, data_json); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":15,\"test2\":\"remoted\"}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getconfig_unknown_section(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{\"section\":\"testtest\"}}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":7,\"message\":\"Unrecognized or not configured section\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getconfig_empty_section(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{}}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":6,\"message\":\"Empty section\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getconfig_empty_parameters(void ** state) { - char* request = "{\"command\":\"getconfig\"}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":5,\"message\":\"Empty parameters\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_empty_parameters(void ** state) { - char* request = "{\"command\":\"getagentsstats\"}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":5,\"message\":\"Empty parameters\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_invalid_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"agents\"}}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":8,\"message\":\"Invalid agents parameter\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_empty_last_id(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\"}}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":10,\"message\":\"Empty last id\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_too_many_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": [1,2,3,4,5,6,7,8,9,10,11, \ - 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \ - 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83, \ - 84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114, \ - 115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141, \ - 142,143,144,145,146,147,148,149,150,151]}}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":11,\"message\":\"Too many agents\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_all_empty_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\", \"last_id\": 0}}"; - char *response = NULL; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, REM_MAX_NUM_AGENTS_STATS); - will_return(__wrap_wdb_get_agents_ids_of_current_node, NULL); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":9,\"message\":\"Error getting agents from DB\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_all_due(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\", \"last_id\": 0}}"; - char *response = NULL; - cJSON* data_json = cJSON_CreateObject(); - - int *connected_agents; - os_calloc(151, sizeof(int), connected_agents); - for (size_t i = 0; i < 150; i++) { - connected_agents[i] = i+1; - } - connected_agents[150] = OS_INVALID; - - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, REM_MAX_NUM_AGENTS_STATS); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_rem_create_agents_state_json, agents_ids, connected_agents); - will_return(__wrap_rem_create_agents_state_json, data_json); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":1,\"message\":\"due\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_all_ok(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": \"all\", \"last_id\": 0}}"; - char *response = NULL; - cJSON* data_json = cJSON_CreateObject(); - - int *connected_agents; - os_calloc(2, sizeof(int), connected_agents); - connected_agents[0] = 1; - connected_agents[1] = OS_INVALID; - - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, REM_MAX_NUM_AGENTS_STATS); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_rem_create_agents_state_json, agents_ids, connected_agents); - will_return(__wrap_rem_create_agents_state_json, data_json); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_array_empty_agents(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": []}}"; - char *response = NULL; - - will_return(__wrap_json_parse_agents, NULL); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":9,\"message\":\"Error getting agents from DB\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_getagentsstats_array_ok(void ** state) { - char* request = "{\"command\":\"getagentsstats\", \"module\":\"api\", \"parameters\": {\"agents\": [1]}}"; - char *response = NULL; - cJSON* data_json = cJSON_CreateObject(); - - int *connected_agents; - os_calloc(2, sizeof(int), connected_agents); - connected_agents[0] = 1; - connected_agents[1] = OS_INVALID; - - will_return(__wrap_json_parse_agents, connected_agents); - - expect_value(__wrap_rem_create_agents_state_json, agents_ids, connected_agents); - will_return(__wrap_rem_create_agents_state_json, data_json); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_assigngroup(void ** state) { - char* request = "{\"command\":\"assigngroup\", \"parameters\": {\"agent\": \"001\", \"md5\": \"1234567890abcdef\"}}"; - char *response = NULL; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddStringToObject(data_json, "group", "test1"); - - expect_string(__wrap_assign_group_to_agent, agent_id, "001"); - expect_string(__wrap_assign_group_to_agent, md5, "1234567890abcdef"); - will_return(__wrap_assign_group_to_agent, data_json); - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{\"group\":\"test1\"}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_assigngroup_invalid_parameters(void ** state) { - char* request = "{\"command\":\"assigngroup\", \"parameters\": {\"md5\": \"1234567890abcdef\"}}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":12,\"message\":\"Invalid agent or md5 parameter\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_assigngroup_empty_parameters(void ** state) { - char* request = "{\"command\":\"assigngroup\"}}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":5,\"message\":\"Empty parameters\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_unknown_command(void ** state) { - char* request = "{\"command\":\"unknown\"}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":4,\"message\":\"Unrecognized command\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_empty_command(void ** state) { - char* request = "{}"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":3,\"message\":\"Empty command\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_dispatch_invalid_json(void ** state) { - char* request = "unknown"; - char *response = NULL; - - size_t size = remcom_dispatch(request, &response); - - *state = response; - - assert_non_null(response); - assert_string_equal(response, "{\"error\":2,\"message\":\"Invalid JSON input\",\"data\":{}}"); - assert_int_equal(size, strlen(response)); -} - -void test_remcom_main(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - size_t input_size = strlen(input) + 1; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "remoted"); - - char *response = "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":18,\"test2\":\"remoted\"}}"; - size_t response_size = strlen(response); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - will_return(__wrap_rem_create_state_json, data_json); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, response_size); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_max_size(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_MAXLEN); - - expect_string(__wrap__merror, formatted_msg, "Received message > '4194304'"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_empty(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Empty message from local client"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_error(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, -1); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): 'Success'"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_sockerror(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_accept_error(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, -1); - - expect_string(__wrap__merror, formatted_msg, "At accept(): 'Success'"); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_select_zero(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 0); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_select_error_eintr(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = EINTR; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, -1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__merror, formatted_msg, "At OS_RecvSecureTCP(): response size is bigger than expected"); - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread finished"); - - remcom_main(NULL); -} - -void test_remcom_main_select_error(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{\"command\":\"getstats\"}"; - - errno = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, -1); - - expect_string(__wrap__merror_exit, formatted_msg, "At select(): 'Success'"); - - expect_assert_failure(remcom_main(NULL)); -} - -void test_remcom_main_bind_error(void **state) -{ - int socket = 0; - int peer = 1111; - - expect_string(__wrap__mdebug1, formatted_msg, "Local requests thread ready"); - - expect_string(__wrap_OS_BindUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, -1); - - expect_string(__wrap__merror, formatted_msg, "Unable to bind to socket 'queue/sockets/remote': (0) 'Success'"); - - remcom_main(NULL); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test remcom_output_builder - cmocka_unit_test_teardown(test_remcom_output_builder, test_teardown), - // Test remcom_dispatch - cmocka_unit_test_teardown(test_remcom_dispatch_getstats, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getconfig, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getconfig_unknown_section, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getconfig_empty_section, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getconfig_empty_parameters, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_empty_parameters, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_invalid_agents, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_empty_last_id, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_too_many_agents, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_all_empty_agents, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_all_due, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_all_ok, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_array_empty_agents, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_getagentsstats_array_ok, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_assigngroup, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_assigngroup_invalid_parameters, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_assigngroup_empty_parameters, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_unknown_command, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_empty_command, test_teardown), - cmocka_unit_test_teardown(test_remcom_dispatch_invalid_json, test_teardown), - // Test remcom_main - cmocka_unit_test(test_remcom_main), - cmocka_unit_test(test_remcom_main_max_size), - cmocka_unit_test(test_remcom_main_empty), - cmocka_unit_test(test_remcom_main_error), - cmocka_unit_test(test_remcom_main_sockerror), - cmocka_unit_test(test_remcom_main_accept_error), - cmocka_unit_test(test_remcom_main_select_zero), - cmocka_unit_test(test_remcom_main_select_error_eintr), - cmocka_unit_test(test_remcom_main_select_error), - cmocka_unit_test(test_remcom_main_bind_error), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/remoted/test_remote-config.c b/src/unit_tests/remoted/test_remote-config.c deleted file mode 100644 index 10e01330780..00000000000 --- a/src/unit_tests/remoted/test_remote-config.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../remoted/remoted.h" -#include "../../headers/shared.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -int w_remoted_get_net_protocol(const char * content); - -void w_remoted_parse_agents(XML_NODE node, remoted * logr); - - -/* setup/teardown */ - - -/* wraps */ - - -/* tests */ - -// Test w_remoted_get_net_protocol - -void test_w_remoted_get_net_protocol_content_NULL(void **state) -{ - const char * content = NULL; - - expect_string(__wrap__mwarn, formatted_msg, "(9000): Error getting protocol. Default value (TCP) will be used."); - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, REMOTED_NET_PROTOCOL_DEFAULT); - -} - -void test_w_remoted_get_net_protocol_content_empty(void **state) -{ - const char * content = ""; - - expect_string(__wrap__mwarn, formatted_msg, "(9001): Ignored invalid value '' for 'protocol'."); - - expect_string(__wrap__mwarn, formatted_msg, "(9000): Error getting protocol. Default value (TCP) will be used."); - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, REMOTED_NET_PROTOCOL_DEFAULT); - -} - -void test_w_remoted_get_net_protocol_content_ignore_values(void **state) -{ - const char * content = "hello, world"; - - expect_string(__wrap__mwarn, formatted_msg, "(9001): Ignored invalid value 'hello' for 'protocol'."); - - expect_string(__wrap__mwarn, formatted_msg, "(9001): Ignored invalid value 'world' for 'protocol'."); - - expect_string(__wrap__mwarn, formatted_msg, "(9000): Error getting protocol. Default value (TCP) will be used."); - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, REMOTED_NET_PROTOCOL_DEFAULT); - -} - -void test_w_remoted_get_net_protocol_content_tcp(void **state) -{ - const char * content = "tcp"; - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, 1); - -} - -void test_w_remoted_get_net_protocol_content_udp(void **state) -{ - const char * content = "udp"; - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, 2); - -} - -void test_w_remoted_get_net_protocol_content_tcp_udp(void **state) -{ - const char * content = "tcp,udp"; - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, 3); - -} - -void test_w_remoted_get_net_protocol_content_udp_tcp(void **state) -{ - const char * content = "udp, tcp"; - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, 3); - -} - -void test_w_remoted_get_net_protocol_content_mix(void **state) -{ - const char * content = "hello, tcp, , world, udp"; - - expect_string(__wrap__mwarn, formatted_msg, "(9001): Ignored invalid value 'hello' for 'protocol'."); - - expect_string(__wrap__mwarn, formatted_msg, "(9001): Ignored invalid value '' for 'protocol'."); - - expect_string(__wrap__mwarn, formatted_msg, "(9001): Ignored invalid value 'world' for 'protocol'."); - - int ret = w_remoted_get_net_protocol(content); - assert_int_equal(ret, 3); - -} - -// Test w_remoted_parse_agents - -remoted logr = {0}; - -static void test_w_remoted_parse_agents_no(void **state) { - logr.allow_higher_versions = REMOTED_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - XML_NODE node; - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("allow_higher_versions", node[0]->element); - os_strdup("no", node[0]->content); - node[1] = NULL; - - w_remoted_parse_agents(node, &logr); - assert_false(logr.allow_higher_versions); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -static void test_w_remoted_parse_agents_yes(void **state) { - logr.allow_higher_versions = REMOTED_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - XML_NODE node; - - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("allow_higher_versions", node[0]->element); - os_strdup("yes", node[0]->content); - node[1] = NULL; - - w_remoted_parse_agents(node, &logr); - assert_true(logr.allow_higher_versions); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -static void test_w_remoted_parse_agents_invalid_value(void **state) { - logr.allow_higher_versions = REMOTED_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - XML_NODE node; - - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("allow_higher_versions", node[0]->element); - os_strdup("invalid_value", node[0]->content); - node[1] = NULL; - - expect_string(__wrap__mwarn, formatted_msg, - "(9001): Ignored invalid value 'invalid_value' for 'allow_higher_versions'."); - w_remoted_parse_agents(node, &logr); - assert_int_equal(logr.allow_higher_versions, REMOTED_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -static void test_w_remoted_parse_agents_invalid_element(void **state) { - logr.allow_higher_versions = REMOTED_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT; - - XML_NODE node; - - os_calloc(2, sizeof(xml_node *), node); - os_calloc(1, sizeof(xml_node), node[0]); - os_strdup("invalid_element", node[0]->element); // Use an invalid element name - os_strdup("no", node[0]->content); - node[1] = NULL; - - expect_string(__wrap__mwarn, formatted_msg, - "(1230): Invalid element in the configuration: 'invalid_element'."); - w_remoted_parse_agents(node, &logr); - assert_int_equal(logr.allow_higher_versions, REMOTED_ALLOW_AGENTS_HIGHER_VERSIONS_DEFAULT); - - os_free(node[0]->element); - os_free(node[0]->content); - os_free(node[0]); - os_free(node); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests - cmocka_unit_test(test_w_remoted_get_net_protocol_content_NULL), - cmocka_unit_test(test_w_remoted_get_net_protocol_content_empty), - cmocka_unit_test(test_w_remoted_get_net_protocol_content_ignore_values), - cmocka_unit_test(test_w_remoted_get_net_protocol_content_tcp), - cmocka_unit_test(test_w_remoted_get_net_protocol_content_udp), - cmocka_unit_test(test_w_remoted_get_net_protocol_content_tcp_udp), - cmocka_unit_test(test_w_remoted_get_net_protocol_content_udp_tcp), - cmocka_unit_test(test_w_remoted_get_net_protocol_content_mix), - cmocka_unit_test(test_w_remoted_parse_agents_no), - cmocka_unit_test(test_w_remoted_parse_agents_yes), - cmocka_unit_test(test_w_remoted_parse_agents_invalid_value), - cmocka_unit_test(test_w_remoted_parse_agents_invalid_element), - - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/remoted/test_remote-state.c b/src/unit_tests/remoted/test_remote-state.c deleted file mode 100644 index a56b46d0af0..00000000000 --- a/src/unit_tests/remoted/test_remote-state.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../remoted/remoted.h" -#include "../../remoted/state.h" - -#include "../wrappers/posix/time_wrappers.h" -#include "../wrappers/wazuh/remoted/queue_wrappers.h" - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/shared/cluster_utils_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" - -typedef struct test_struct { - remoted_agent_state_t *agent_state; - OSHashNode *hash_node; - cJSON * state_json; -} test_struct_t; - -extern remoted_state_t remoted_state; -extern OSHash *remoted_agents_state; - -remoted_agent_state_t * get_node(const char *agent_id); -void w_remoted_clean_agents_state(int *sock); - -/* setup/teardown */ - -static int test_setup(void ** state) { - remoted_state.uptime = 123456789; - remoted_state.tcp_sessions = 5; - remoted_state.recv_bytes = 123456; - remoted_state.sent_bytes = 234567; - remoted_state.keys_reload_count = 15; - remoted_state.recv_breakdown.evt_count = 1234; - remoted_state.recv_breakdown.ctrl_count = 2345; - remoted_state.recv_breakdown.ping_count = 18; - remoted_state.recv_breakdown.unknown_count = 8; - remoted_state.recv_breakdown.dequeued_count = 4; - remoted_state.recv_breakdown.discarded_count = 95; - remoted_state.recv_breakdown.ctrl_breakdown.keepalive_count = 1115; - remoted_state.recv_breakdown.ctrl_breakdown.startup_count = 48; - remoted_state.recv_breakdown.ctrl_breakdown.shutdown_count = 12; - remoted_state.recv_breakdown.ctrl_breakdown.request_count = 2; - remoted_state.sent_breakdown.ack_count = 1114; - remoted_state.sent_breakdown.shared_count = 2540; - remoted_state.sent_breakdown.ar_count = 18; - remoted_state.sent_breakdown.sca_count = 8; - remoted_state.sent_breakdown.request_count = 9; - remoted_state.sent_breakdown.discarded_count = 85; - - return 0; -} - -static int test_setup_agent(void ** state) { - test_struct_t *test_data = NULL; - os_calloc(1, sizeof(test_struct_t),test_data); - os_calloc(1, sizeof(remoted_agent_state_t), test_data->agent_state); - os_calloc(1, sizeof(OSHashNode), test_data->hash_node); - - test_mode = 0; - will_return(__wrap_time, 123456789); - remoted_agents_state = __wrap_OSHash_Create(); - - test_data->agent_state->uptime = 123456789; - test_data->agent_state->recv_evt_count = 12568; - test_data->agent_state->recv_ctrl_count = 2568; - test_data->agent_state->ctrl_breakdown.keepalive_count = 1234; - test_data->agent_state->ctrl_breakdown.startup_count = 2345; - test_data->agent_state->ctrl_breakdown.shutdown_count = 234; - test_data->agent_state->ctrl_breakdown.request_count = 127; - test_data->agent_state->sent_breakdown.ack_count = 2346; - test_data->agent_state->sent_breakdown.shared_count = 235; - test_data->agent_state->sent_breakdown.ar_count = 514; - test_data->agent_state->sent_breakdown.sca_count = 134; - test_data->agent_state->sent_breakdown.request_count = 153; - test_data->agent_state->sent_breakdown.discarded_count = 235; - - OSHash_Add_ex(remoted_agents_state, "001", test_data->agent_state); - test_mode = 1; - - test_data->hash_node->key = "001"; - test_data->hash_node->data = test_data->agent_state; - - *state = test_data; - - return 0; -} - -static int test_teardown_agent(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - cJSON_Delete(test_data->state_json); - - if (remoted_agents_state) { - OSHash_Free(remoted_agents_state); - remoted_agents_state = NULL; - } - - os_free(test_data->hash_node); - os_free(test_data); - - return 0; -} - -static int test_setup_empty_hash_table(void ** state) { - test_struct_t *test_data = NULL; - os_calloc(1, sizeof(test_struct_t),test_data); - os_calloc(1, sizeof(remoted_agent_state_t), test_data->agent_state); - - test_data->agent_state->uptime = 123456789; - - test_mode = 0; - will_return(__wrap_time, 123456789); - remoted_agents_state = __wrap_OSHash_Create(); - test_mode = 1; - - *state = test_data; - - return 0; -} - -static int test_teardown_empty_hash_table(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - if (remoted_agents_state) { - OSHash_Free(remoted_agents_state); - remoted_agents_state = NULL; - } - - os_free(test_data->agent_state); - os_free(test_data); - - return 0; -} - -/* Tests */ - -void test_rem_create_state_json(void ** state) { - will_return(__wrap_time, 123456789); - will_return(__wrap_rem_get_qsize, 789); - will_return(__wrap_rem_get_tsize, 100000); - - cJSON* state_json = rem_create_state_json(); - - assert_non_null(state_json); - - assert_int_equal(cJSON_GetObjectItem(state_json, "uptime")->valueint, 123456789); - - assert_non_null(cJSON_GetObjectItem(state_json, "metrics")); - cJSON* metrics = cJSON_GetObjectItem(state_json, "metrics"); - - assert_non_null(cJSON_GetObjectItem(metrics, "bytes")); - cJSON* bytes = cJSON_GetObjectItem(metrics, "bytes"); - - assert_non_null(cJSON_GetObjectItem(bytes, "received")); - assert_int_equal(cJSON_GetObjectItem(bytes, "received")->valueint, 123456); - assert_non_null(cJSON_GetObjectItem(bytes, "sent")); - assert_int_equal(cJSON_GetObjectItem(bytes, "sent")->valueint, 234567); - - assert_non_null(cJSON_GetObjectItem(metrics, "messages")); - cJSON* messages = cJSON_GetObjectItem(metrics, "messages"); - - assert_non_null(cJSON_GetObjectItem(messages, "received_breakdown")); - cJSON* recv = cJSON_GetObjectItem(messages, "received_breakdown"); - - assert_non_null(cJSON_GetObjectItem(recv, "event")); - assert_int_equal(cJSON_GetObjectItem(recv, "event")->valueint, 1234); - assert_non_null(cJSON_GetObjectItem(recv, "control")); - assert_int_equal(cJSON_GetObjectItem(recv, "control")->valueint, 2345); - assert_non_null(cJSON_GetObjectItem(recv, "ping")); - assert_int_equal(cJSON_GetObjectItem(recv, "ping")->valueint, 18); - assert_non_null(cJSON_GetObjectItem(recv, "unknown")); - assert_int_equal(cJSON_GetObjectItem(recv, "unknown")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(recv, "dequeued_after")); - assert_int_equal(cJSON_GetObjectItem(recv, "dequeued_after")->valueint, 4); - assert_non_null(cJSON_GetObjectItem(recv, "discarded")); - assert_int_equal(cJSON_GetObjectItem(recv, "discarded")->valueint, 95); - - assert_non_null(cJSON_GetObjectItem(recv, "control_breakdown")); - cJSON* ctrl = cJSON_GetObjectItem(recv, "control_breakdown"); - - assert_non_null(cJSON_GetObjectItem(ctrl, "request")); - assert_int_equal(cJSON_GetObjectItem(ctrl, "request")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(ctrl, "startup")); - assert_int_equal(cJSON_GetObjectItem(ctrl, "startup")->valueint, 48); - assert_non_null(cJSON_GetObjectItem(ctrl, "shutdown")); - assert_int_equal(cJSON_GetObjectItem(ctrl, "shutdown")->valueint, 12); - assert_non_null(cJSON_GetObjectItem(ctrl, "keepalive")); - assert_int_equal(cJSON_GetObjectItem(ctrl, "keepalive")->valueint, 1115); - - assert_non_null(cJSON_GetObjectItem(messages, "sent_breakdown")); - cJSON* sent = cJSON_GetObjectItem(messages, "sent_breakdown"); - - assert_non_null(cJSON_GetObjectItem(sent, "ack")); - assert_int_equal(cJSON_GetObjectItem(sent, "ack")->valueint, 1114); - assert_non_null(cJSON_GetObjectItem(sent, "shared")); - assert_int_equal(cJSON_GetObjectItem(sent, "shared")->valueint, 2540); - assert_non_null(cJSON_GetObjectItem(sent, "ar")); - assert_int_equal(cJSON_GetObjectItem(sent, "ar")->valueint, 18); - assert_non_null(cJSON_GetObjectItem(sent, "sca")); - assert_int_equal(cJSON_GetObjectItem(sent, "sca")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(sent, "request")); - assert_int_equal(cJSON_GetObjectItem(sent, "request")->valueint, 9); - assert_non_null(cJSON_GetObjectItem(sent, "discarded")); - assert_int_equal(cJSON_GetObjectItem(sent, "discarded")->valueint, 85); - - assert_non_null(cJSON_GetObjectItem(metrics, "tcp_sessions")); - assert_int_equal(cJSON_GetObjectItem(metrics, "tcp_sessions")->valueint, 5); - assert_non_null(cJSON_GetObjectItem(metrics, "keys_reload_count")); - assert_int_equal(cJSON_GetObjectItem(metrics, "keys_reload_count")->valueint, 15); - - assert_non_null(cJSON_GetObjectItem(metrics, "queues")); - cJSON* queue = cJSON_GetObjectItem(metrics, "queues"); - - cJSON* received = cJSON_GetObjectItem(queue, "received"); - assert_non_null(cJSON_GetObjectItem(received, "usage")); - assert_int_equal(cJSON_GetObjectItem(received, "usage")->valueint, 789); - assert_non_null(cJSON_GetObjectItem(received, "size")); - assert_int_equal(cJSON_GetObjectItem(received, "size")->valueint, 100000); - - cJSON_Delete(state_json); -} - -void test_rem_create_agents_state_json(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - int *agents_ids = NULL; - os_calloc(2, sizeof(int), agents_ids); - agents_ids[0] = 1; - agents_ids[1] = OS_INVALID; - const char *agent_id = "001"; - - will_return(__wrap_time, 123456789); - - expect_value(__wrap_OSHash_Get_ex, self, remoted_agents_state); - expect_string(__wrap_OSHash_Get_ex, key, agent_id); - will_return(__wrap_OSHash_Get_ex, test_data->hash_node->data); - - test_data->state_json = rem_create_agents_state_json(agents_ids); - - assert_non_null(test_data->state_json); - - assert_non_null(cJSON_GetObjectItem(test_data->state_json, "agents")); - cJSON* agents = cJSON_GetObjectItem(test_data->state_json, "agents"); - - assert_non_null(cJSON_GetArrayItem(agents, 0)); - cJSON* agent = cJSON_GetArrayItem(agents, 0); - assert_int_equal(cJSON_GetObjectItem(agent, "id")->valueint, 1); - assert_int_equal(cJSON_GetObjectItem(agent, "uptime")->valueint, 123456789); - - assert_non_null(cJSON_GetObjectItem(agent, "metrics")); - cJSON* agent_metrics = cJSON_GetObjectItem(agent, "metrics"); - - assert_non_null(cJSON_GetObjectItem(agent_metrics, "messages")); - cJSON* messages = cJSON_GetObjectItem(agent_metrics, "messages"); - - assert_non_null(cJSON_GetObjectItem(messages, "received_breakdown")); - cJSON* messages_received_breakdown = cJSON_GetObjectItem(messages, "received_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(messages_received_breakdown, "event")->valueint, 12568); - assert_int_equal(cJSON_GetObjectItem(messages_received_breakdown, "control")->valueint, 2568); - - assert_non_null(cJSON_GetObjectItem(messages_received_breakdown, "control_breakdown")); - cJSON* control_breakdown = cJSON_GetObjectItem(messages_received_breakdown, "control_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(control_breakdown, "request")->valueint, 127); - assert_int_equal(cJSON_GetObjectItem(control_breakdown, "startup")->valueint, 2345); - assert_int_equal(cJSON_GetObjectItem(control_breakdown, "shutdown")->valueint, 234); - assert_int_equal(cJSON_GetObjectItem(control_breakdown, "keepalive")->valueint, 1234); - - assert_non_null(cJSON_GetObjectItem(messages, "sent_breakdown")); - cJSON* messages_sent_breakdown = cJSON_GetObjectItem(messages, "sent_breakdown"); - - assert_int_equal(cJSON_GetObjectItem(messages_sent_breakdown, "ack")->valueint, 2346); - assert_int_equal(cJSON_GetObjectItem(messages_sent_breakdown, "shared")->valueint, 235); - assert_int_equal(cJSON_GetObjectItem(messages_sent_breakdown, "ar")->valueint, 514); - assert_int_equal(cJSON_GetObjectItem(messages_sent_breakdown, "sca")->valueint, 134); - assert_int_equal(cJSON_GetObjectItem(messages_sent_breakdown, "request")->valueint, 153); - assert_int_equal(cJSON_GetObjectItem(messages_sent_breakdown, "discarded")->valueint, 235); - - os_free(test_data->agent_state); - os_free(agents_ids); -} - -void test_rem_get_node_new_node(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - const char *agent_id = "001"; - - expect_value(__wrap_OSHash_Get_ex, self, remoted_agents_state); - expect_string(__wrap_OSHash_Get_ex, key, agent_id); - will_return(__wrap_OSHash_Get_ex, NULL); - - will_return(__wrap_time, 123456789); - - expect_value(__wrap_OSHash_Add_ex, self, remoted_agents_state); - expect_string(__wrap_OSHash_Add_ex, key, agent_id); - expect_memory(__wrap_OSHash_Add_ex, data, test_data->agent_state, sizeof(test_data->agent_state)); - will_return(__wrap_OSHash_Add_ex, 2); - - remoted_agent_state_t *agent_state_returned = get_node(agent_id); - - assert_non_null(agent_state_returned); - - os_free(agent_state_returned); -} - -void test_rem_get_node_existing_node(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - const char *agent_id = "001"; - - expect_value(__wrap_OSHash_Get_ex, self, remoted_agents_state); - expect_string(__wrap_OSHash_Get_ex, key, agent_id); - will_return(__wrap_OSHash_Get_ex, test_data->agent_state); - - remoted_agent_state_t *agent_state_returned = get_node(agent_id); - - assert_non_null(agent_state_returned); - - os_free(test_data->agent_state); -} - -void test_w_remoted_clean_agents_state_empty_table(void ** state) { - expect_value(__wrap_OSHash_Begin_ex, self, remoted_agents_state); - will_return(__wrap_OSHash_Begin_ex, NULL); - - int sock = 1; - - w_remoted_clean_agents_state(&sock); -} - -void test_w_remoted_clean_agents_state_completed(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - expect_value(__wrap_OSHash_Begin_ex, self, remoted_agents_state); - will_return(__wrap_OSHash_Begin_ex, test_data->hash_node); - - int *connected_agents = NULL; - os_calloc(1, sizeof(int), connected_agents); - connected_agents[0] = OS_INVALID; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, -1); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_OSHash_Next, self, remoted_agents_state); - will_return(__wrap_OSHash_Next, NULL); - - expect_value(__wrap_OSHash_Delete_ex, self, remoted_agents_state); - expect_value(__wrap_OSHash_Delete_ex, key, "001"); - will_return(__wrap_OSHash_Delete_ex, test_data->agent_state); - - int sock = 1; - - w_remoted_clean_agents_state(&sock); -} - -void test_w_remoted_clean_agents_state_completed_without_delete(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - expect_value(__wrap_OSHash_Begin_ex, self, remoted_agents_state); - will_return(__wrap_OSHash_Begin_ex, test_data->hash_node); - - int *connected_agents = NULL; - os_calloc(1, sizeof(int), connected_agents); - connected_agents[0] = 1; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, -1); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - expect_value(__wrap_OSHash_Next, self, remoted_agents_state); - will_return(__wrap_OSHash_Next, NULL); - - int sock = 1; - - w_remoted_clean_agents_state(&sock); - - os_free(test_data->agent_state); -} - -void test_w_remoted_clean_agents_state_query_fail(void ** state) { - test_struct_t *test_data = (test_struct_t *)*state; - - expect_value(__wrap_OSHash_Begin_ex, self, remoted_agents_state); - will_return(__wrap_OSHash_Begin_ex, test_data->hash_node); - - int *connected_agents = NULL; - - expect_string(__wrap_wdb_get_agents_ids_of_current_node, status, AGENT_CS_ACTIVE); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, last_id, 0); - expect_value(__wrap_wdb_get_agents_ids_of_current_node, limit, -1); - will_return(__wrap_wdb_get_agents_ids_of_current_node, connected_agents); - - int sock = 1; - - w_remoted_clean_agents_state(&sock); - - os_free(test_data->agent_state); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test rem_create_state_json - cmocka_unit_test_setup(test_rem_create_state_json, test_setup), - // Test rem_create_agents_state_json - cmocka_unit_test_setup_teardown(test_rem_create_agents_state_json, test_setup_agent, test_teardown_agent), - // Test get_node - cmocka_unit_test_setup_teardown(test_rem_get_node_new_node, test_setup_empty_hash_table, test_teardown_empty_hash_table), - cmocka_unit_test_setup_teardown(test_rem_get_node_existing_node, test_setup_agent, test_teardown_agent), - // Test w_remoted_clean_agents_state - cmocka_unit_test_setup_teardown(test_w_remoted_clean_agents_state_empty_table, test_setup_empty_hash_table, test_teardown_empty_hash_table), - cmocka_unit_test_setup_teardown(test_w_remoted_clean_agents_state_completed, test_setup_agent, test_teardown_agent), - cmocka_unit_test_setup_teardown(test_w_remoted_clean_agents_state_completed_without_delete, test_setup_agent, test_teardown_agent), - cmocka_unit_test_setup_teardown(test_w_remoted_clean_agents_state_query_fail, test_setup_agent, test_teardown_agent), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/remoted/test_secure.c b/src/unit_tests/remoted/test_secure.c deleted file mode 100644 index cbc7e421735..00000000000 --- a/src/unit_tests/remoted/test_secure.c +++ /dev/null @@ -1,2503 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../remoted/remoted.h" -#include "../wrappers/common.h" -#include "../wrappers/linux/socket_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_metadata_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/posix/stat_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/wazuh/shared/queue_linked_op_wrappers.h" -#include "../wrappers/wazuh/os_crypto/keys_wrappers.h" -#include "../wrappers/wazuh/os_crypto/msgs_wrappers.h" -#include "../wrappers/wazuh/remoted/queue_wrappers.h" -#include "../wrappers/wazuh/remoted/manager_wrappers.h" -#include "../wrappers/wazuh/remoted/netbuffer_wrappers.h" -#include "../wrappers/wazuh/remoted/netcounter_wrappers.h" -#include "../wrappers/wazuh/os_crypto/msgs_wrappers.h" -#include "../wrappers/wazuh/remoted/state_wrappers.h" -#include "../wrappers/wazuh/shared_modules/router_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../../remoted/secure.c" - -typedef struct test_agent_info { - char* agent_id; - char* agent_name; - char* agent_ip; -} test_agent_info; - -extern keystore keys; -extern remoted logr; -extern wnotify_t * notify; -extern char *str_family_address[FAMILY_ADDRESS_SIZE]; -extern OSHash *agent_data_hash; - -void tmp_HandleSecureMessage_invalid_family_address(sa_family_t sin_family); - -/* Forward declarations */ -void * close_fp_main(void * args); -void HandleSecureMessage(const message_t *message, int *wdb_sock); - -/* Setup/teardown */ - -static int setup_config(void **state) { - w_linked_queue_t *queue = linked_queue_init(); - keys.opened_fp_queue = queue; - test_mode = 1; - return 0; -} - -static int teardown_config(void **state) { - linked_queue_free(keys.opened_fp_queue); - test_mode = 0; - return 0; -} - -static int setup_new_tcp(void **state) { - test_mode = 1; - os_calloc(1, sizeof(wnotify_t), notify); - notify->fd = 0; - return 0; -} - -static int teardown_new_tcp(void **state) { - test_mode = 0; - os_free(notify); - return 0; -} - -static int setup_remoted_configuration(void **state) { - test_mode = 1; - node_name = "test_node_name"; - agent_data_hash = (OSHash*)1; - - test_agent_info* agent; - os_calloc(1, sizeof(test_agent_info), agent); - os_strdup("001", agent->agent_id); - os_strdup("focal", agent->agent_name); - os_strdup("192.168.33.20", agent->agent_ip); - - *state = agent; - - return 0; -} - -static int teardown_remoted_configuration(void **state) { - test_mode = 0; - node_name = ""; - router_syscollector_handle = NULL; - router_rsync_handle = NULL; - - test_agent_info *data = (test_agent_info *)*state; - free(data->agent_id); - free(data->agent_name); - free(data->agent_ip); - free(data); - - return 0; -} - -/* Wrappers */ - -time_t __wrap_time(int time) { - check_expected(time); - return mock(); -} - -void __wrap_key_lock_write(){ - function_called(); -} - -void __wrap_key_unlock(){ - function_called(); -} - -void __wrap_key_lock_read(){ - function_called(); -} - -int __wrap_close(int __fd) { - return mock(); -} - -/*****************WRAPS********************/ -int __wrap_w_mutex_lock(pthread_mutex_t *mutex) { - check_expected_ptr(mutex); - return 0; -} - -int __wrap_w_mutex_unlock(pthread_mutex_t *mutex) { - check_expected_ptr(mutex); - return 0; -} - -/* Tests close_fp_main*/ - -void test_close_fp_main_queue_empty(void **state) -{ - logr.rids_closing_time = 10; - - // sleep - expect_value(__wrap_sleep, seconds, 10); - - // key_lock - expect_function_call(__wrap_key_lock_write); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 0"); - - expect_string(__wrap__mdebug1, formatted_msg, "Rids closer thread started."); - - // key_unlock - expect_function_call(__wrap_key_unlock); - - close_fp_main(&keys); - assert_int_equal(keys.opened_fp_queue->elements, 0); -} - -void test_close_fp_main_first_node_no_close_first(void **state) -{ - logr.rids_closing_time = 10; - - keyentry *first_node_key = NULL; - os_calloc(1, sizeof(keyentry), first_node_key); - - int now = 123456789; - first_node_key->id = strdup("001"); - first_node_key->updating_time = now - 1; - - // Queue with one element - w_linked_queue_node_t *node1 = linked_queue_push(keys.opened_fp_queue, first_node_key); - keys.opened_fp_queue->first = node1; - - // sleep - expect_value(__wrap_sleep, seconds, 10); - - // key_lock - expect_function_call(__wrap_key_lock_write); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 1"); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, now); - - expect_string(__wrap__mdebug2, formatted_msg, "Checking rids_node of agent 001."); - - expect_string(__wrap__mdebug1, formatted_msg, "Rids closer thread started."); - // key_unlock - expect_function_call(__wrap_key_unlock); - - close_fp_main(&keys); - assert_int_equal(keys.opened_fp_queue->elements, 1); - os_free(node1); - os_free(first_node_key->id); - os_free(first_node_key); -} - -void test_close_fp_main_close_first(void **state) -{ - logr.rids_closing_time = 10; - - keyentry *first_node_key = NULL; - os_calloc(1, sizeof(keyentry), first_node_key); - - int now = 123456789; - first_node_key->id = strdup("001"); - first_node_key->updating_time = now - logr.rids_closing_time - 100; - - first_node_key->fp = (FILE *)1234; - - // Queue with one element - w_linked_queue_node_t *node1 = linked_queue_push(keys.opened_fp_queue, first_node_key); - - // sleep - expect_value(__wrap_sleep, seconds, 10); - - // key_lock - expect_function_call(__wrap_key_lock_write); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 1"); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, now); - - expect_string(__wrap__mdebug2, formatted_msg, "Checking rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Pop rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Closing rids for agent 001."); - - expect_value(__wrap_fclose, _File, (FILE *)1234); - will_return(__wrap_fclose, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 0"); - - expect_string(__wrap__mdebug1, formatted_msg, "Rids closer thread started."); - - // key_unlock - expect_function_call(__wrap_key_unlock); - - close_fp_main(&keys); - assert_int_equal(keys.opened_fp_queue->elements, 0); - os_free(first_node_key->id); - os_free(first_node_key); -} - -void test_close_fp_main_close_first_queue_2(void **state) -{ - logr.rids_closing_time = 10; - - keyentry *first_node_key = NULL; - os_calloc(1, sizeof(keyentry), first_node_key); - - keyentry *second_node_key = NULL; - os_calloc(1, sizeof(keyentry), second_node_key); - - int now = 123456789; - first_node_key->id = strdup("001"); - first_node_key->updating_time = now - logr.rids_closing_time - 100; - first_node_key->fp = (FILE *)1234; - - second_node_key->id = strdup("002"); - second_node_key->updating_time = now - 1; - - // Queue with one element - w_linked_queue_node_t *node1 = linked_queue_push(keys.opened_fp_queue, first_node_key); - w_linked_queue_node_t *node2 = linked_queue_push(keys.opened_fp_queue, second_node_key); - - // sleep - expect_value(__wrap_sleep, seconds, 10); - - // key_lock - expect_function_call(__wrap_key_lock_write); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 2"); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, now); - - expect_string(__wrap__mdebug2, formatted_msg, "Checking rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Pop rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Closing rids for agent 001."); - - expect_value(__wrap_fclose, _File, (FILE *)1234); - will_return(__wrap_fclose, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 1"); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, now); - - expect_string(__wrap__mdebug2, formatted_msg, "Checking rids_node of agent 002."); - - expect_string(__wrap__mdebug1, formatted_msg, "Rids closer thread started."); - - // key_unlock - expect_function_call(__wrap_key_unlock); - - close_fp_main(&keys); - assert_int_equal(keys.opened_fp_queue->elements, 1); - os_free(first_node_key->id); - os_free(first_node_key); - - os_free(node2); - os_free(second_node_key->id); - os_free(second_node_key); -} - -void test_close_fp_main_close_first_queue_2_close_2(void **state) -{ - logr.rids_closing_time = 10; - - keyentry *first_node_key = NULL; - os_calloc(1, sizeof(keyentry), first_node_key); - - keyentry *second_node_key = NULL; - os_calloc(1, sizeof(keyentry), second_node_key); - - int now = 123456789; - first_node_key->id = strdup("001"); - first_node_key->updating_time = now - logr.rids_closing_time - 100; - first_node_key->fp = (FILE *)1234; - - second_node_key->id = strdup("002"); - second_node_key->updating_time = now - logr.rids_closing_time - 99; - second_node_key->fp = (FILE *)1234; - - // Queue with one element - w_linked_queue_node_t *node1 = linked_queue_push(keys.opened_fp_queue, first_node_key); - w_linked_queue_node_t *node2 = linked_queue_push(keys.opened_fp_queue, second_node_key); - - // sleep - expect_value(__wrap_sleep, seconds, 10); - - // key_lock - expect_function_call(__wrap_key_lock_write); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 2"); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, now); - - expect_string(__wrap__mdebug2, formatted_msg, "Checking rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Pop rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Closing rids for agent 001."); - - expect_value(__wrap_fclose, _File, (FILE *)1234); - will_return(__wrap_fclose, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 1"); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, now); - - expect_string(__wrap__mdebug2, formatted_msg, "Checking rids_node of agent 002."); - - expect_string(__wrap__mdebug2, formatted_msg, "Pop rids_node of agent 002."); - - expect_string(__wrap__mdebug2, formatted_msg, "Closing rids for agent 002."); - - expect_value(__wrap_fclose, _File, (FILE *)1234); - will_return(__wrap_fclose, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 0"); - - expect_string(__wrap__mdebug1, formatted_msg, "Rids closer thread started."); - - // key_unlock - expect_function_call(__wrap_key_unlock); - - close_fp_main(&keys); - assert_int_equal(keys.opened_fp_queue->elements, 0); - os_free(first_node_key->id); - os_free(first_node_key); - - os_free(second_node_key->id); - os_free(second_node_key); -} - -void test_close_fp_main_close_fp_null(void **state) -{ - logr.rids_closing_time = 10; - - keyentry *first_node_key = NULL; - os_calloc(1, sizeof(keyentry), first_node_key); - - int now = 123456789; - first_node_key->id = strdup("001"); - first_node_key->updating_time = now - logr.rids_closing_time - 100; - first_node_key->fp = NULL; - - // Queue with one element - w_linked_queue_node_t *node1 = linked_queue_push(keys.opened_fp_queue, first_node_key); - - // sleep - expect_value(__wrap_sleep, seconds, 10); - - // key_lock - expect_function_call(__wrap_key_lock_write); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 1"); - - expect_value(__wrap_time, time, 0); - will_return(__wrap_time, now); - - expect_string(__wrap__mdebug2, formatted_msg, "Checking rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Pop rids_node of agent 001."); - - expect_string(__wrap__mdebug2, formatted_msg, "Opened rids queue size: 0"); - - expect_string(__wrap__mdebug1, formatted_msg, "Rids closer thread started."); - - // key_unlock - expect_function_call(__wrap_key_unlock); - - close_fp_main(&keys); - assert_int_equal(keys.opened_fp_queue->elements, 0); - os_free(first_node_key->id); - os_free(first_node_key); -} - -void tmp_HandleSecureMessage_invalid_family_address(sa_family_t sin_family) -{ - char buffer[OS_MAXSTR + 1] = "!1234!"; - message_t message = { .buffer = buffer, .size = 6, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("001"); - key->sock = 1; - key->keyid = 1; - - keys.keyentries[0] = key; - - global_counter = 0; - - peer_info.sin_family = sin_family; - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - char auxBuff[OS_MAXSTR + 1] = {0}; - - if (peer_info.sin_family < sizeof(str_family_address)/sizeof(str_family_address[0])) { - sprintf(auxBuff, "IP address family '%d':'%s' not supported.", peer_info.sin_family, str_family_address[peer_info.sin_family]); - expect_string(__wrap__merror, formatted_msg, auxBuff); - } else { - sprintf(auxBuff, "IP address family '%d' not found.", peer_info.sin_family); - expect_string(__wrap__merror, formatted_msg, auxBuff); - } - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_invalid_family_address_af_unspec(void **state) -{ - tmp_HandleSecureMessage_invalid_family_address(AF_UNSPEC); -} - -void test_HandleSecureMessage_invalid_family_address_af_netlink(void **state) -{ - tmp_HandleSecureMessage_invalid_family_address(AF_NETLINK); -} - -void test_HandleSecureMessage_invalid_family_address_af_unix(void **state) -{ - tmp_HandleSecureMessage_invalid_family_address(AF_UNIX); -} - -void test_HandleSecureMessage_invalid_family_address_af_x25(void **state) -{ - tmp_HandleSecureMessage_invalid_family_address(AF_X25); -} - -void test_HandleSecureMessage_invalid_family_address_not_found(void **state) -{ - tmp_HandleSecureMessage_invalid_family_address(50); -} - -void test_HandleSecureMessage_shutdown_message(void **state) -{ - char buffer[OS_MAXSTR + 1] = "#!-agent shutdown "; - message_t message = { .buffer = buffer, .size = 18, .sock = 1, .counter = 10 }; - struct sockaddr_in peer_info; - int wdb_sock; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("009"); - key->sock = 1; - key->keyid = 1; - - keys.keyentries[0] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0100007F; - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 0); - - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, "#!-agent shutdown "); - expect_value(__wrap_ReadSecMSG, id, 0); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, "#!-agent shutdown "); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_value(__wrap_rem_getCounter, fd, 1); - will_return(__wrap_rem_getCounter, 10); - - //OS_DupKeyEntry - expect_value(__wrap_OS_DupKeyEntry, key, key); - will_return(__wrap_OS_DupKeyEntry, key); - - expect_value(__wrap_rem_getCounter, fd, 1); - will_return(__wrap_rem_getCounter, 10); - - expect_function_call(__wrap_key_unlock); - - expect_value(__wrap_save_controlmsg, key, key); - expect_string(__wrap_save_controlmsg, r_msg, "agent shutdown "); - expect_value(__wrap_save_controlmsg, wdb_sock, &wdb_sock); - - expect_string(__wrap_rem_inc_recv_ctrl, agent_id, key->id); - - //OS_FreeKey - expect_value(__wrap_OS_FreeKey, key, key); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_NewMessage_NoShutdownMessage(void **state) -{ - char buffer[OS_MAXSTR + 1] = "#!-agent startup "; - message_t message = { .buffer = buffer, .size = 17, .sock = 1, .counter = 11 }; - struct sockaddr_in peer_info; - int wdb_sock; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("009"); - key->sock = 1; - key->keyid = 1; - - keys.keyentries[0] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0100007F; - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 0); - - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, "#!-agent startup "); - expect_value(__wrap_ReadSecMSG, id, 0); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, "#!-agent startup "); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_value(__wrap_rem_getCounter, fd, 1); - will_return(__wrap_rem_getCounter, 10); - - //OS_DupKeyEntry - expect_value(__wrap_OS_DupKeyEntry, key, key); - will_return(__wrap_OS_DupKeyEntry, key); - - expect_value(__wrap_rem_getCounter, fd, 1); - will_return(__wrap_rem_getCounter, 10); - - expect_value(__wrap_OS_AddSocket, keys, &keys); - expect_value(__wrap_OS_AddSocket, i, 0); - expect_value(__wrap_OS_AddSocket, sock, message.sock); - will_return(__wrap_OS_AddSocket, 2); - - expect_string(__wrap__mdebug2, formatted_msg, "TCP socket 1 added to keystore."); - - expect_function_call(__wrap_key_unlock); - - expect_value(__wrap_save_controlmsg, key, key); - expect_string(__wrap_save_controlmsg, r_msg, "agent startup "); - expect_value(__wrap_save_controlmsg, wdb_sock, &wdb_sock); - - expect_string(__wrap_rem_inc_recv_ctrl, agent_id, key->id); - - //OS_FreeKey - expect_value(__wrap_OS_FreeKey, key, key); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key); - os_free(keyentries); -} - - -void test_HandleSecureMessage_OldMessage_NoShutdownMessage(void **state) -{ - char buffer[OS_MAXSTR + 1] = "#!-agent startup "; - message_t message = { .buffer = buffer, .size = 17, .sock = 1, .counter = 5 }; - struct sockaddr_in peer_info; - int wdb_sock; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("009"); - key->sock = 1; - key->keyid = 1; - - keys.keyentries[0] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0100007F; - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 0); - - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, "#!-agent startup "); - expect_value(__wrap_ReadSecMSG, id, 0); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, "#!-agent startup "); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_value(__wrap_rem_getCounter, fd, 1); - will_return(__wrap_rem_getCounter, 10); - - expect_function_call(__wrap_key_unlock); - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_invalid_message(void **state) -{ - char buffer[OS_MAXSTR + 1] = "!1234!"; - message_t message = { .buffer = buffer, .size = 6, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("001"); - key->sock = 1; - key->keyid = 1; - - keys.keyentries[0] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0100007F; - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedDynamicID, id, "1234"); - expect_string(__wrap_OS_IsAllowedDynamicID, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedDynamicID, 0); - - expect_string(__wrap__mwarn, formatted_msg, "Received message is empty"); - - expect_function_call(__wrap_key_unlock); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, message.sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, message.sock); - expect_value(__wrap_nb_close, sock, message.sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 1); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [1]"); - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_different_sock(void **state) -{ - char buffer[OS_MAXSTR + 1] = "!12!"; - message_t message = { .buffer = buffer, .size = 4, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - - keys.keyentries[0] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedDynamicID, id, "12"); - expect_string(__wrap_OS_IsAllowedDynamicID, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedDynamicID, 0); - - expect_function_call(__wrap_key_unlock); - - expect_string(__wrap__mwarn, formatted_msg, "Agent key already in use: agent ID '001'"); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, message.sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, message.sock); - expect_value(__wrap_nb_close, sock, message.sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 1); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [1]"); - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_different_sock_2(void **state) -{ - char buffer[OS_MAXSTR + 1] = "12!"; - message_t message = { .buffer = buffer, .size = 4, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - - keys.keyentries[0] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 0); - - expect_function_call(__wrap_key_unlock); - - expect_string(__wrap__mwarn, formatted_msg, "Agent key already in use: agent ID '001'"); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, message.sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, message.sock); - expect_value(__wrap_nb_close, sock, message.sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 1); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [1]"); - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_idle_sock(void **state) -{ - char buffer[OS_MAXSTR + 1] = "12!"; - message_t message = { .buffer = buffer, .size = 4, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - os_calloc(1, sizeof(os_ip), key->ip); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - key->rcvd = 0; - key->ip->ip = "127.0.0.1"; - key->name = strdup("name"); - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Idle socket [4] from agent ID '001' will be closed."); - - // ReadSecMSG - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, buffer); - expect_value(__wrap_ReadSecMSG, id, 1); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, buffer); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_function_call(__wrap_key_unlock); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, key->sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, key->sock); - expect_value(__wrap_nb_close, sock, key->sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 4); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [4]"); - - // SendMSG - expect_string(__wrap_SendMSG, message, "12!"); - expect_string(__wrap_SendMSG, locmsg, "[001] (name) 127.0.0.1"); - expect_any(__wrap_SendMSG, loc); - will_return(__wrap_SendMSG, 0); - - expect_function_call(__wrap_rem_inc_recv_evt); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->name); - os_free(key->ip); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_idle_sock_2(void **state) -{ - char buffer[OS_MAXSTR + 1] = "!12!AAA"; - message_t message = { .buffer = buffer, .size = 7, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - os_calloc(1, sizeof(os_ip), key->ip); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - key->rcvd = 0; - key->ip->ip = "127.0.0.1"; - key->name = strdup("name"); - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedDynamicID, id, "12"); - expect_string(__wrap_OS_IsAllowedDynamicID, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedDynamicID, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Idle socket [4] from agent ID '001' will be closed."); - - // ReadSecMSG - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, "AAA"); - expect_value(__wrap_ReadSecMSG, id, 1); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, "AAA"); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_function_call(__wrap_key_unlock); - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, key->sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, key->sock); - expect_value(__wrap_nb_close, sock, key->sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 4); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [4]"); - - // SendMSG - expect_string(__wrap_SendMSG, message, "AAA"); - expect_string(__wrap_SendMSG, locmsg, "[001] (name) 127.0.0.1"); - expect_any(__wrap_SendMSG, loc); - will_return(__wrap_SendMSG, 0); - - expect_function_call(__wrap_rem_inc_recv_evt); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->ip); - os_free(key->name); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_idle_sock_disabled(void **state) -{ - char buffer[OS_MAXSTR + 1] = "12!"; - message_t message = { .buffer = buffer, .size = 4, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 0; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - key->rcvd = 0; - key->name = strdup("name"); - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 1); - - expect_function_call(__wrap_key_unlock); - - expect_string(__wrap__mwarn, formatted_msg, "Agent key already in use: agent ID '001'"); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, message.sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, message.sock); - expect_value(__wrap_nb_close, sock, message.sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 1); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [1]"); - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->name); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_idle_sock_disabled_2(void **state) -{ - char buffer[OS_MAXSTR + 1] = "!12!AAA"; - message_t message = { .buffer = buffer, .size = 7, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 0; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - key->rcvd = 0; - key->name = strdup("name"); - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedDynamicID, id, "12"); - expect_string(__wrap_OS_IsAllowedDynamicID, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedDynamicID, 1); - - expect_function_call(__wrap_key_unlock); - - expect_string(__wrap__mwarn, formatted_msg, "Agent key already in use: agent ID '001'"); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, message.sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, message.sock); - expect_value(__wrap_nb_close, sock, message.sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 1); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [1]"); - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->name); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_idle_sock_recv_fail(void **state) -{ - char buffer[OS_MAXSTR + 1] = "12!"; - message_t message = { .buffer = buffer, .size = 0, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - os_calloc(1, sizeof(os_ip), key->ip); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - key->rcvd = 0; - key->ip->ip = "127.0.0.1"; - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Idle socket [4] from agent ID '001' will be closed."); - - expect_string(__wrap__mwarn, formatted_msg, "Received message is empty"); - - expect_function_call(__wrap_key_unlock); - - //Close new socket - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, message.sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, message.sock); - expect_value(__wrap_nb_close, sock, message.sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 1); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [1]"); - - //Close idle socket - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, key->sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, key->sock); - expect_value(__wrap_nb_close, sock, key->sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 4); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [4]"); - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->ip); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_idle_sock_decrypt_fail(void **state) -{ - char buffer[OS_MAXSTR + 1] = "12!"; - message_t message = { .buffer = buffer, .size = 4, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - os_calloc(1, sizeof(os_ip), key->ip); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - key->rcvd = 0; - key->ip->ip = "127.0.0.1"; - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Idle socket [4] from agent ID '001' will be closed."); - - // ReadSecMSG - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, buffer); - expect_value(__wrap_ReadSecMSG, id, 1); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, buffer); - will_return(__wrap_ReadSecMSG, -1); - - expect_function_call(__wrap_key_unlock); - - expect_string(__wrap__mwarn, formatted_msg, "Decrypt the message fail, socket 1"); - - //Close new socket - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, message.sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, message.sock); - expect_value(__wrap_nb_close, sock, message.sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 1); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [1]"); - - //Close idle socket - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, key->sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, key->sock); - expect_value(__wrap_nb_close, sock, key->sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 4); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [4]"); - - expect_function_call(__wrap_rem_inc_recv_unknown); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->ip); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_idle_sock_control_msg_succes(void **state) -{ - char buffer[OS_MAXSTR + 1] = "#!-12!"; - message_t message = { .buffer = buffer, .size = 7, .sock = 1, .counter = 11 }; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - os_calloc(1, sizeof(os_ip), key->ip); - - key->id = strdup("001"); - key->sock = 4; - key->keyid = 1; - key->rcvd = 0; - key->ip->ip = "127.0.0.1"; - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "Idle socket [4] from agent ID '001' will be closed."); - - // ReadSecMSG - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, buffer); - expect_value(__wrap_ReadSecMSG, id, 1); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, buffer); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_value(__wrap_rem_getCounter, fd, 1); - will_return(__wrap_rem_getCounter, 10); - - //OS_DupKeyEntry - expect_value(__wrap_OS_DupKeyEntry, key, key); - will_return(__wrap_OS_DupKeyEntry, key); - - //OS_AddSocket - expect_value(__wrap_OS_AddSocket, keys, &keys); - expect_value(__wrap_OS_AddSocket, i, 1); - expect_value(__wrap_OS_AddSocket, sock, message.sock); - will_return(__wrap_OS_AddSocket, OS_ADDSOCKET_KEY_ADDED); - - expect_string(__wrap__mdebug2, formatted_msg, "TCP socket 1 added to keystore."); - - expect_function_call(__wrap_key_unlock); - - //Close idle socket - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, key->sock); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, key->sock); - expect_value(__wrap_nb_close, sock, key->sock); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, 4); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [4]"); - - //save_controlmsg - expect_value(__wrap_save_controlmsg, key, key); - expect_string(__wrap_save_controlmsg, r_msg, "12!"); - expect_value(__wrap_save_controlmsg, wdb_sock, &wdb_sock); - - expect_string(__wrap_rem_inc_recv_ctrl, agent_id, "001"); - - //OS_FreeKey - expect_value(__wrap_OS_FreeKey, key, key); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->ip); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_same_sock(void **state) -{ - char buffer[OS_MAXSTR + 1] = "12!"; - message_t message = { .buffer = buffer, .size = 4, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - os_calloc(1, sizeof(os_ip), key->ip); - - key->id = strdup("001"); - key->sock = 1; - key->keyid = 1; - key->rcvd = 0; - key->ip->ip = "127.0.0.1"; - key->name = strdup("name"); - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedIP, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedIP, 1); - - // ReadSecMSG - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, buffer); - expect_value(__wrap_ReadSecMSG, id, 1); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, buffer); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_function_call(__wrap_key_unlock); - - // SendMSG - expect_string(__wrap_SendMSG, message, "12!"); - expect_string(__wrap_SendMSG, locmsg, "[001] (name) 127.0.0.1"); - expect_any(__wrap_SendMSG, loc); - will_return(__wrap_SendMSG, 0); - - expect_function_call(__wrap_rem_inc_recv_evt); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->ip); - os_free(key->name); - os_free(key); - os_free(keyentries); -} - -void test_HandleSecureMessage_close_same_sock_2(void **state) -{ - char buffer[OS_MAXSTR + 1] = "!12!AAA"; - message_t message = { .buffer = buffer, .size = 7, .sock = 1}; - struct sockaddr_in peer_info; - int wdb_sock; - - current_ts = 61; - - logr.connection_overtake_time = 60; - - keyentry** keyentries; - os_calloc(2, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - - os_calloc(1, sizeof(os_ip), key->ip); - - key->id = strdup("001"); - key->sock = 1; - key->keyid = 1; - key->rcvd = 0; - key->ip->ip = "127.0.0.1"; - key->name = strdup("name"); - - keys.keyentries[1] = key; - - global_counter = 0; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = inet_addr("127.0.0.1"); - memcpy(&message.addr, &peer_info, sizeof(peer_info)); - - expect_function_call(__wrap_key_lock_read); - - // OS_IsAllowedDynamicID - expect_string(__wrap_OS_IsAllowedDynamicID, id, "12"); - expect_string(__wrap_OS_IsAllowedDynamicID, srcip, "127.0.0.1"); - will_return(__wrap_OS_IsAllowedDynamicID, 1); - - // ReadSecMSG - expect_value(__wrap_ReadSecMSG, keys, &keys); - expect_string(__wrap_ReadSecMSG, buffer, "AAA"); - expect_value(__wrap_ReadSecMSG, id, 1); - expect_string(__wrap_ReadSecMSG, srcip, "127.0.0.1"); - will_return(__wrap_ReadSecMSG, message.size); - will_return(__wrap_ReadSecMSG, "AAA"); - will_return(__wrap_ReadSecMSG, KS_VALID); - - expect_function_call(__wrap_key_unlock); - - // SendMSG - expect_string(__wrap_SendMSG, message, "AAA"); - expect_string(__wrap_SendMSG, locmsg, "[001] (name) 127.0.0.1"); - expect_any(__wrap_SendMSG, loc); - will_return(__wrap_SendMSG, 0); - - expect_function_call(__wrap_rem_inc_recv_evt); - - HandleSecureMessage(&message, &wdb_sock); - - os_free(key->id); - os_free(key->ip); - os_free(key->name); - os_free(key); - os_free(keyentries); -} - -void test_handle_new_tcp_connection_success(void **state) -{ - struct sockaddr_in peer_info; - int sock_client = 12; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0A00A8C0; - - will_return(__wrap_accept, AF_INET); - will_return(__wrap_accept, sock_client); - - // nb_open - expect_value(__wrap_nb_open, sock, sock_client); - expect_value(__wrap_nb_open, peer_info, (struct sockaddr_storage *)&peer_info); - expect_value(__wrap_nb_open, sock, sock_client); - expect_value(__wrap_nb_open, peer_info, (struct sockaddr_storage *)&peer_info); - - expect_function_call(__wrap_rem_inc_tcp); - - expect_string(__wrap__mdebug1, formatted_msg, "New TCP connection [12]"); - - // wnotify_add - expect_value(__wrap_wnotify_add, notify, notify); - expect_value(__wrap_wnotify_add, fd, sock_client); - expect_value(__wrap_wnotify_add, op, WO_READ); - will_return(__wrap_wnotify_add, 0); - - handle_new_tcp_connection(notify, (struct sockaddr_storage *)&peer_info); -} - -void test_handle_new_tcp_connection_wnotify_fail(void **state) -{ - struct sockaddr_in peer_info; - int sock_client = 12; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0A00A8C0; - - will_return(__wrap_accept, AF_INET); - will_return(__wrap_accept, sock_client); - - // nb_open - expect_value(__wrap_nb_open, sock, sock_client); - expect_value(__wrap_nb_open, peer_info, (struct sockaddr_storage *)&peer_info); - expect_value(__wrap_nb_open, sock, sock_client); - expect_value(__wrap_nb_open, peer_info, (struct sockaddr_storage *)&peer_info); - - expect_function_call(__wrap_rem_inc_tcp); - - expect_string(__wrap__mdebug1, formatted_msg, "New TCP connection [12]"); - - // wnotify_add - expect_value(__wrap_wnotify_add, notify, notify); - expect_value(__wrap_wnotify_add, fd, sock_client); - expect_value(__wrap_wnotify_add, op, WO_READ); - will_return(__wrap_wnotify_add, -1); - - expect_string(__wrap__merror, formatted_msg, "wnotify_add(0, 12): Success (0)"); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, sock_client); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, sock_client); - expect_value(__wrap_nb_close, sock, sock_client); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, sock_client); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [12]"); - - handle_new_tcp_connection(notify, (struct sockaddr_storage *)&peer_info); -} - -void test_handle_new_tcp_connection_socket_fail(void **state) -{ - struct sockaddr_in peer_info; - int sock_client = 12; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0A00A8C0; - - will_return(__wrap_accept, AF_INET); - will_return(__wrap_accept, -1); - errno = -1; - expect_string(__wrap__merror, formatted_msg, "(1242): Couldn't accept TCP connections: Unknown error -1 (-1)"); - - handle_new_tcp_connection(notify, (struct sockaddr_storage *)&peer_info); -} - -void test_handle_new_tcp_connection_socket_fail_err(void **state) -{ - struct sockaddr_in peer_info; - int sock_client = 12; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0A00A8C0; - - will_return(__wrap_accept, AF_INET); - will_return(__wrap_accept, -1); - errno = ECONNABORTED; - expect_string(__wrap__mdebug1, formatted_msg, "(1242): Couldn't accept TCP connections: Software caused connection abort (103)"); - - handle_new_tcp_connection(notify, (struct sockaddr_storage *)&peer_info); -} - -void test_handle_incoming_data_from_udp_socket_0(void **state) -{ - struct sockaddr_in peer_info; - logr.udp_sock = 1; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0A00A8C0; - - will_return(__wrap_recvfrom, 0); - - handle_incoming_data_from_udp_socket((struct sockaddr_storage *)&peer_info); -} - -void test_handle_incoming_data_from_udp_socket_success(void **state) -{ - struct sockaddr_in peer_info; - logr.udp_sock = 1; - - peer_info.sin_family = AF_INET; - peer_info.sin_addr.s_addr = 0x0A00A8C0; - - will_return(__wrap_recvfrom, 10); - - expect_value(__wrap_rem_msgpush, size, 10); - expect_value(__wrap_rem_msgpush, addr, (struct sockaddr_storage *)&peer_info); - expect_value(__wrap_rem_msgpush, sock, USING_UDP_NO_CLIENT_SOCKET); - will_return(__wrap_rem_msgpush, 0); - - expect_value(__wrap_rem_add_recv, bytes, 10); - - handle_incoming_data_from_udp_socket((struct sockaddr_storage *)&peer_info); -} - -void test_handle_incoming_data_from_tcp_socket_too_big_message(void **state) -{ - int sock_client = 8; - - expect_value(__wrap_nb_recv, sock, sock_client); - will_return(__wrap_nb_recv, -2); - - expect_string(__wrap__mwarn, formatted_msg, "Too big message size from socket [8]."); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, sock_client); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, sock_client); - expect_value(__wrap_nb_close, sock, sock_client); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, sock_client); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [8]"); - - handle_incoming_data_from_tcp_socket(sock_client); -} - -void test_handle_incoming_data_from_tcp_socket_case_0(void **state) -{ - int sock_client = 7; - - expect_value(__wrap_nb_recv, sock, sock_client); - will_return(__wrap_nb_recv, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "handle incoming close socket [7]."); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, sock_client); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, sock_client); - expect_value(__wrap_nb_close, sock, sock_client); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, sock_client); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [7]"); - - handle_incoming_data_from_tcp_socket(sock_client); -} - -void test_handle_incoming_data_from_tcp_socket_case_1(void **state) -{ - int sock_client = 7; - - expect_value(__wrap_nb_recv, sock, sock_client); - will_return(__wrap_nb_recv, -1); - - errno = ETIMEDOUT; - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer [7]: Connection timed out (110)"); - - expect_string(__wrap__mdebug1, formatted_msg, "handle incoming close socket [7]."); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, sock_client); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, sock_client); - expect_value(__wrap_nb_close, sock, sock_client); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, sock_client); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [7]"); - - handle_incoming_data_from_tcp_socket(sock_client); -} - -void test_handle_incoming_data_from_tcp_socket_success(void **state) -{ - int sock_client = 12; - - expect_value(__wrap_nb_recv, sock, sock_client); - will_return(__wrap_nb_recv, 100); - - expect_value(__wrap_rem_add_recv, bytes, 100); - - handle_incoming_data_from_tcp_socket(sock_client); -} - -void test_handle_outgoing_data_to_tcp_socket_case_1_EAGAIN(void **state) -{ - int sock_client = 10; - - expect_value(__wrap_nb_send, sock, sock_client); - will_return(__wrap_nb_send, -1); - - errno = EAGAIN; - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer [10]: Resource temporarily unavailable (11)"); - - handle_outgoing_data_to_tcp_socket(sock_client); -} - -void test_handle_outgoing_data_to_tcp_socket_case_1_EPIPE(void **state) -{ - int sock_client = 10; - - expect_value(__wrap_nb_send, sock, sock_client); - will_return(__wrap_nb_send, -1); - - errno = EPIPE; - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer [10]: Broken pipe (32)"); - - expect_string(__wrap__mdebug1, formatted_msg, "handle outgoing close socket [10]."); - - expect_function_call(__wrap_key_lock_read); - - // OS_DeleteSocket - expect_value(__wrap_OS_DeleteSocket, sock, sock_client); - will_return(__wrap_OS_DeleteSocket, 0); - - expect_function_call(__wrap_key_unlock); - - will_return(__wrap_close, 0); - - // nb_close - expect_value(__wrap_nb_close, sock, sock_client); - expect_value(__wrap_nb_close, sock, sock_client); - expect_function_call(__wrap_rem_dec_tcp); - - // rem_setCounter - expect_value(__wrap_rem_setCounter, fd, sock_client); - expect_value(__wrap_rem_setCounter, counter, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "TCP peer disconnected [10]"); - - handle_outgoing_data_to_tcp_socket(sock_client); -} - -void test_handle_outgoing_data_to_tcp_socket_success(void **state) -{ - int sock_client = 10; - - expect_value(__wrap_nb_send, sock, sock_client); - will_return(__wrap_nb_send, 100); - - expect_value(__wrap_rem_add_send, bytes, 100); - - handle_outgoing_data_to_tcp_socket(sock_client); -} - -// Tests router_message_forward -void test_router_message_forward_non_syscollector_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "1:nonsyscollector:{\"message\":\"test\"}"; - - // No function call is expected in this case - router_message_forward(message, data->agent_id, NULL, NULL); -} - -void test_router_message_forward_create_sync_handle_fail(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "5:syscollector:{\"message\":\"valid\"}"; - - expect_string(__wrap__mdebug2, formatted_msg, "Router handle for 'rsync' not available."); - router_rsync_handle = NULL; - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_malformed_sync_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "5:syscollector:{\"message\":fail"; - - router_rsync_handle = (ROUTER_PROVIDER_HANDLE)(1); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_invalid_sync_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "5:syscollector:{\"message\":\"not_valid\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"}}"; - - router_rsync_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_synchronization_SCHEMA); - will_return(__wrap_router_provider_send_fb, -1); - - expect_string(__wrap__mdebug2, formatted_msg, "Unable to forward message for agent 001"); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_integrity_check_global(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "5:syscollector:{\"component\":\"syscollector_hwinfo\",\"data\":{\"begin\":\"0\",\"checksum\":\"b66d0703ee882571cd1865f393bd34f7d5940339\"," - "\"end\":\"0\",\"id\":1691259777},\"type\":\"integrity_check_global\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"integrity_check_global\",\"data\":" - "{\"attributes_type\":\"syscollector_hwinfo\",\"begin\":\"0\",\"checksum\":\"b66d0703ee882571cd1865f393bd34f7d5940339\",\"end\":\"0\",\"id\":1691259777}}"; - - router_rsync_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_synchronization_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_integrity_check_left(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "5:syscollector:{\"component\":\"syscollector_packages\",\"data\":{\"begin\":\"01113a00fcdafa43d111ecb669202119c946ebe5\",\"checksum\":\"54c13892eb9ee18b0012086b76a89f41e73d64a1\"," - "\"end\":\"40795337f16a208e4d0a2280fbd5c794c9877dcb\",\"id\":1693338981,\"tail\":\"408cb243d2d52ad6414ba602e375b3b6b5f5cd77\"},\"type\":\"integrity_check_global\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"integrity_check_global\",\"data\":" - "{\"attributes_type\":\"syscollector_packages\",\"begin\":\"01113a00fcdafa43d111ecb669202119c946ebe5\",\"checksum\":\"54c13892eb9ee18b0012086b76a89f41e73d64a1\",\"end\":\"40795337f16a208e4d0a2280fbd5c794c9877dcb\",\"id\":1693338981,\"tail\":\"408cb243d2d52ad6414ba602e375b3b6b5f5cd77\"}}"; - - router_rsync_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_synchronization_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_integrity_check_right(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "5:syscollector:{\"component\":\"syscollector_packages\",\"data\":{\"begin\":\"85c5676f6e5082ef99bba397b90559cd36fbbeca\",\"checksum\":\"d33c176f028188be38b394af5eed1e66bb8ad40e\"," - "\"end\":\"ffee8da05f37fa760fc5eee75dd0ea9e71228d05\",\"id\":1693338981},\"type\":\"integrity_check_right\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"integrity_check_right\",\"data\":" - "{\"attributes_type\":\"syscollector_packages\",\"begin\":\"85c5676f6e5082ef99bba397b90559cd36fbbeca\",\"checksum\":\"d33c176f028188be38b394af5eed1e66bb8ad40e\",\"end\":\"ffee8da05f37fa760fc5eee75dd0ea9e71228d05\",\"id\":1693338981}}"; - - router_rsync_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_synchronization_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_integrity_clear(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "5:syscollector:{\"component\":\"syscollector_hwinfo\",\"data\":{\"id\":1693338619},\"type\":\"integrity_check_clear\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"integrity_check_clear\",\"data\":" - "{\"attributes_type\":\"syscollector_hwinfo\",\"id\":1693338619}}"; - - router_rsync_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_synchronization_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_create_delta_handle_fail(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"message\":\"valid\"}"; - - expect_string(__wrap__mdebug2, formatted_msg, "Router handle for 'syscollector' not available."); - router_syscollector_handle = NULL; - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_malformed_delta_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"message\":fail"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_invalid_delta_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"message\":\"not_valid\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"}}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, -1); - - expect_string(__wrap__mdebug2, formatted_msg, "Unable to forward message for agent 001"); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_packages_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_packages\",\"data\":{\"architecture\":\"amd64\",\"checksum\":\"1e6ce14f97f57d1bbd46ff8e5d3e133171a1bbce\"" - ",\"description\":\"library for GIF images (library)\",\"format\":\"deb\",\"groups\":\"libs\",\"item_id\":\"ec465b7eb5fa011a336e95614072e4c7f1a65a53\"" - ",\"multiarch\":\"same\",\"name\":\"libgif7\",\"priority\":\"optional\",\"scan_time\":\"2023/08/04 19:56:11\",\"size\":72,\"source\":\"giflib\"" - ",\"vendor\":\"Ubuntu Developers \",\"version\":\"5.1.9-1\"},\"operation\":\"INSERTED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_packages\",\"data\":{\"architecture\":\"amd64\",\"checksum\":\"1e6ce14f97f57d1bbd46ff8e5d3e133171a1bbce\"" - ",\"description\":\"library for GIF images (library)\",\"format\":\"deb\",\"groups\":\"libs\",\"item_id\":\"ec465b7eb5fa011a336e95614072e4c7f1a65a53\"" - ",\"multiarch\":\"same\",\"name\":\"libgif7\",\"priority\":\"optional\",\"scan_time\":\"2023/08/04 19:56:11\",\"size\":72,\"source\":\"giflib\"" - ",\"vendor\":\"Ubuntu Developers \",\"version\":\"5.1.9-1\"},\"operation\":\"INSERTED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_os_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_packages\",\"data\":{\"architecture\":\"amd64\",\"checksum\":\"1e6ce14f97f57d1bbd46ff8e5d3e133171a1bbce\"" - ",\"description\":\"library for GIF images (library)\",\"format\":\"deb\",\"groups\":\"libs\",\"item_id\":\"ec465b7eb5fa011a336e95614072e4c7f1a65a53\"" - ",\"multiarch\":\"same\",\"name\":\"libgif7\",\"priority\":\"optional\",\"scan_time\":\"2023/08/04 19:56:11\",\"size\":72,\"source\":\"giflib\"" - ",\"vendor\":\"Ubuntu Developers \",\"version\":\"5.1.9-1\"},\"operation\":\"INSERTED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_packages\",\"data\":{\"architecture\":\"amd64\",\"checksum\":\"1e6ce14f97f57d1bbd46ff8e5d3e133171a1bbce\"" - ",\"description\":\"library for GIF images (library)\",\"format\":\"deb\",\"groups\":\"libs\",\"item_id\":\"ec465b7eb5fa011a336e95614072e4c7f1a65a53\"" - ",\"multiarch\":\"same\",\"name\":\"libgif7\",\"priority\":\"optional\",\"scan_time\":\"2023/08/04 19:56:11\",\"size\":72,\"source\":\"giflib\"" - ",\"vendor\":\"Ubuntu Developers \",\"version\":\"5.1.9-1\"},\"operation\":\"INSERTED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_netiface_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_network_iface\",\"data\":{\"adapter\":null,\"checksum\":\"078143285c1aff98e196c8fe7e01f5677f44bd44\"" - ",\"item_id\":\"7a60750dd3c25c53f21ff7f44b4743664ddbb66a\",\"mac\":\"02:bf:67:45:e4:dd\",\"mtu\":1500,\"name\":\"enp0s3\",\"rx_bytes\":972800985" - ",\"rx_dropped\":0,\"rx_errors\":0,\"rx_packets\":670863,\"scan_time\":\"2023/08/04 19:56:11\",\"state\":\"up\",\"tx_bytes\":6151606,\"tx_dropped\":0" - ",\"tx_errors\":0,\"tx_packets\":84746,\"type\":\"ethernet\"},\"operation\":\"MODIFIED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_network_iface\",\"data\":{\"adapter\":null,\"checksum\":\"078143285c1aff98e196c8fe7e01f5677f44bd44\"" - ",\"item_id\":\"7a60750dd3c25c53f21ff7f44b4743664ddbb66a\",\"mac\":\"02:bf:67:45:e4:dd\",\"mtu\":1500,\"name\":\"enp0s3\",\"rx_bytes\":972800985" - ",\"rx_dropped\":0,\"rx_errors\":0,\"rx_packets\":670863,\"scan_time\":\"2023/08/04 19:56:11\",\"state\":\"up\",\"tx_bytes\":6151606,\"tx_dropped\":0" - ",\"tx_errors\":0,\"tx_packets\":84746,\"type\":\"ethernet\"},\"operation\":\"MODIFIED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_netproto_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_network_protocol\",\"data\":{\"checksum\":\"ddd971d57316a79738a2cf93143966a4e51ede08\",\"dhcp\":\"unknown\"" - ",\"gateway\":\" \",\"iface\":\"enp0s9\",\"item_id\":\"33228317ee8778628d0f2f4fde53b75b92f15f1d\",\"metric\":\"0\",\"scan_time\":\"2023/08/07 15:02:36\"" - ",\"type\":\"ipv4\"},\"operation\":\"DELETED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_network_protocol\",\"data\":{\"checksum\":\"ddd971d57316a79738a2cf93143966a4e51ede08\",\"dhcp\":\"unknown\"" - ",\"gateway\":\" \",\"iface\":\"enp0s9\",\"item_id\":\"33228317ee8778628d0f2f4fde53b75b92f15f1d\",\"metric\":\"0\",\"scan_time\":\"2023/08/07 15:02:36\"" - ",\"type\":\"ipv4\"},\"operation\":\"DELETED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_netaddr_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_network_address\",\"data\":{\"address\":\"192.168.0.80\",\"broadcast\":\"192.168.0.255\"" - ",\"checksum\":\"c1f9511fa37815d19cee496f21524725ba84ab10\",\"iface\":\"enp0s9\",\"item_id\":\"b333013c47d28eb3878068dd59c42e00178bd475\"" - ",\"netmask\":\"255.255.255.0\",\"proto\":0,\"scan_time\":\"2023/08/07 15:02:36\"},\"operation\":\"DELETED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_network_address\",\"data\":{\"address\":\"192.168.0.80\",\"broadcast\":\"192.168.0.255\"" - ",\"checksum\":\"c1f9511fa37815d19cee496f21524725ba84ab10\",\"iface\":\"enp0s9\",\"item_id\":\"b333013c47d28eb3878068dd59c42e00178bd475\"" - ",\"netmask\":\"255.255.255.0\",\"proto\":0,\"scan_time\":\"2023/08/07 15:02:36\"},\"operation\":\"DELETED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_hardware_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_hwinfo\",\"data\":{\"board_serial\":\"0\",\"checksum\":\"f6eea592bc11465ecacc92ddaea188ef3faf0a1f\",\"cpu_cores\":8" - ",\"cpu_mhz\":2592.0,\"cpu_name\":\"Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz\",\"ram_free\":11547184,\"ram_total\":12251492,\"ram_usage\":6" - ",\"scan_time\":\"2023/08/04 19:56:11\"},\"operation\":\"MODIFIED\"}"; - // Trailing zeros are truncated. - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_hwinfo\",\"data\":{\"board_serial\":\"0\",\"checksum\":\"f6eea592bc11465ecacc92ddaea188ef3faf0a1f\",\"cpu_cores\":8" - ",\"cpu_mhz\":2592,\"cpu_name\":\"Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz\",\"ram_free\":11547184,\"ram_total\":12251492,\"ram_usage\":6" - ",\"scan_time\":\"2023/08/04 19:56:11\"},\"operation\":\"MODIFIED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_ports_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_ports\",\"data\":{\"checksum\":\"03f522cdccc8dfbab964981db59b176b178b9dfd\",\"inode\":39968" - ",\"item_id\":\"7f98c21162b40ca7871a8292d177a1812ca97547\",\"local_ip\":\"10.0.2.15\",\"local_port\":68,\"pid\":0,\"process\":null,\"protocol\":\"udp\"" - ",\"remote_ip\":\"0.0.0.0\",\"remote_port\":0,\"rx_queue\":0,\"scan_time\":\"2023/08/07 12:42:41\",\"state\":null,\"tx_queue\":0},\"operation\":\"INSERTED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_ports\",\"data\":{\"checksum\":\"03f522cdccc8dfbab964981db59b176b178b9dfd\",\"inode\":39968" - ",\"item_id\":\"7f98c21162b40ca7871a8292d177a1812ca97547\",\"local_ip\":\"10.0.2.15\",\"local_port\":68,\"pid\":0,\"process\":null,\"protocol\":\"udp\"" - ",\"remote_ip\":\"0.0.0.0\",\"remote_port\":0,\"rx_queue\":0,\"scan_time\":\"2023/08/07 12:42:41\",\"state\":null,\"tx_queue\":0},\"operation\":\"INSERTED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_processes_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_processes\",\"data\":{\"checksum\":\"5ca21c17ae78a0ef7463b3b2454126848473cf5b\",\"cmd\":\"C:\\\\Windows\\\\System32\\\\winlogon.exe\"" - ",\"name\":\"winlogon.exe\",\"nlwp\":6,\"pid\":\"604\",\"ppid\":496,\"priority\":13,\"scan_time\":\"2023/08/07 15:01:57\",\"session\":1,\"size\":3387392" - ",\"start_time\":1691420428,\"stime\":0,\"utime\":0,\"vm_size\":14348288},\"operation\":\"MODIFIED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_processes\",\"data\":{\"checksum\":\"5ca21c17ae78a0ef7463b3b2454126848473cf5b\",\"cmd\":\"C:\\\\Windows\\\\System32\\\\winlogon.exe\"" - ",\"name\":\"winlogon.exe\",\"nlwp\":6,\"pid\":\"604\",\"ppid\":496,\"priority\":13,\"scan_time\":\"2023/08/07 15:01:57\",\"session\":1,\"size\":3387392" - ",\"start_time\":1691420428,\"stime\":0,\"utime\":0,\"vm_size\":14348288},\"operation\":\"MODIFIED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_valid_delta_hotfixes_json_message(void **state) -{ - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"dbsync_hotfixes\",\"data\":{\"checksum\":\"f6eea592bc11465ecacc92ddaea188ef3faf0a1f\",\"hotfix\":\"KB4502496\"" - ",\"scan_time\":\"2023/08/0419:56:11\"},\"operation\":\"MODIFIED\"}"; - char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\",\"agent_ip\":\"192.168.33.20\",\"agent_name\":\"focal\"},\"data_type\":\"dbsync_hotfixes\",\"data\":{\"checksum\":\"f6eea592bc11465ecacc92ddaea188ef3faf0a1f\",\"hotfix\":\"KB4502496\"" - ",\"scan_time\":\"2023/08/0419:56:11\"},\"operation\":\"MODIFIED\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - expect_string(__wrap_router_provider_send_fb, msg, expected_message); - expect_string(__wrap_router_provider_send_fb, schema, syscollector_deltas_SCHEMA); - will_return(__wrap_router_provider_send_fb, 0); - - will_return(__wrap_OSHash_Get_ex_dup, NULL); - expect_value(__wrap_OSHash_Get_ex_dup, self, (OSHash*)1); - expect_string(__wrap_OSHash_Get_ex_dup, key, data->agent_id); - - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_legacy_agent_message(void **state) { - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"program\",\"ID\":710378877,\"timestamp\":\"2024/01/12 22:47:29\",\"program\":{\"format\":\"deb\"," - "\"name\":\"isc-dhcp-common\",\"priority\":\"important\",\"group\":\"net\",\"size\":163,\"vendor\":\"Ubuntu Developers \"" - ",\"architecture\":\"amd64\",\"source\":\"isc-dhcp\",\"version\":\"4.4.1-2.1ubuntu9\",\"description\":\"common manpages relevant to all of the isc-dhcp packages\"}}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - // This type of message must be discarded - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -void test_router_message_forward_legacy_agent_end_message(void **state) { - test_agent_info* data = (test_agent_info*)(*state); - char* message = "d:syscollector:{\"type\":\"process_end\",\"ID\":1998297930,\"timestamp\":\"2024/01/13 00:08:55\"}"; - - router_syscollector_handle = (ROUTER_PROVIDER_HANDLE)(1); - - // This type of message must be discarded - router_message_forward(message, data->agent_id, data->agent_ip, data->agent_name); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests close_fp_main - cmocka_unit_test_setup_teardown(test_close_fp_main_queue_empty, setup_config, teardown_config), - cmocka_unit_test_setup_teardown(test_close_fp_main_first_node_no_close_first, setup_config, teardown_config), - cmocka_unit_test_setup_teardown(test_close_fp_main_close_first, setup_config, teardown_config), - cmocka_unit_test_setup_teardown(test_close_fp_main_close_first_queue_2, setup_config, teardown_config), - cmocka_unit_test_setup_teardown(test_close_fp_main_close_first_queue_2_close_2, setup_config, teardown_config), - cmocka_unit_test_setup_teardown(test_close_fp_main_close_fp_null, setup_config, teardown_config), - // Tests HandleSecureMessage - cmocka_unit_test(test_HandleSecureMessage_invalid_family_address_af_unspec), - cmocka_unit_test(test_HandleSecureMessage_invalid_family_address_af_netlink), - cmocka_unit_test(test_HandleSecureMessage_invalid_family_address_af_unix), - cmocka_unit_test(test_HandleSecureMessage_invalid_family_address_af_x25), - cmocka_unit_test(test_HandleSecureMessage_invalid_family_address_not_found), - cmocka_unit_test(test_HandleSecureMessage_invalid_message), - cmocka_unit_test(test_HandleSecureMessage_shutdown_message), - cmocka_unit_test(test_HandleSecureMessage_NewMessage_NoShutdownMessage), - cmocka_unit_test(test_HandleSecureMessage_OldMessage_NoShutdownMessage), - cmocka_unit_test(test_HandleSecureMessage_different_sock), - cmocka_unit_test(test_HandleSecureMessage_different_sock_2), - cmocka_unit_test(test_HandleSecureMessage_close_idle_sock), - cmocka_unit_test(test_HandleSecureMessage_close_idle_sock_2), - cmocka_unit_test(test_HandleSecureMessage_close_idle_sock_disabled), - cmocka_unit_test(test_HandleSecureMessage_close_idle_sock_disabled_2), - cmocka_unit_test(test_HandleSecureMessage_close_idle_sock_recv_fail), - cmocka_unit_test(test_HandleSecureMessage_close_idle_sock_decrypt_fail), - cmocka_unit_test(test_HandleSecureMessage_close_idle_sock_control_msg_succes), - cmocka_unit_test(test_HandleSecureMessage_close_same_sock), - cmocka_unit_test(test_HandleSecureMessage_close_same_sock_2), - // Tests handle_new_tcp_connection - cmocka_unit_test_setup_teardown(test_handle_new_tcp_connection_success, setup_new_tcp, teardown_new_tcp), - cmocka_unit_test_setup_teardown(test_handle_new_tcp_connection_wnotify_fail, setup_new_tcp, teardown_new_tcp), - cmocka_unit_test_setup_teardown(test_handle_new_tcp_connection_socket_fail, setup_new_tcp, teardown_new_tcp), - cmocka_unit_test_setup_teardown(test_handle_new_tcp_connection_socket_fail_err, setup_new_tcp, teardown_new_tcp), - // Tests handle_incoming_data_from_udp_socket - cmocka_unit_test(test_handle_incoming_data_from_udp_socket_0), - cmocka_unit_test(test_handle_incoming_data_from_udp_socket_success), - // Tests handle_incoming_data_from_tcp_socket - cmocka_unit_test(test_handle_incoming_data_from_tcp_socket_too_big_message), - cmocka_unit_test(test_handle_incoming_data_from_tcp_socket_case_0), - cmocka_unit_test(test_handle_incoming_data_from_tcp_socket_case_1), - cmocka_unit_test(test_handle_incoming_data_from_tcp_socket_success), - // Tests handle_outgoing_data_to_tcp_socket - cmocka_unit_test(test_handle_outgoing_data_to_tcp_socket_case_1_EAGAIN), - cmocka_unit_test(test_handle_outgoing_data_to_tcp_socket_case_1_EPIPE), - cmocka_unit_test(test_handle_outgoing_data_to_tcp_socket_success), - // Tests router_message_forward - cmocka_unit_test_setup_teardown(test_router_message_forward_create_sync_handle_fail, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_non_syscollector_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_malformed_sync_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_invalid_sync_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_integrity_check_global, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_integrity_check_left, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_integrity_check_right, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_integrity_clear, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_create_delta_handle_fail, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_malformed_delta_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_invalid_delta_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_packages_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_os_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_hardware_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_netiface_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_netproto_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_netaddr_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_ports_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_processes_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_valid_delta_hotfixes_json_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_legacy_agent_message, setup_remoted_configuration, teardown_remoted_configuration), - cmocka_unit_test_setup_teardown(test_router_message_forward_legacy_agent_end_message, setup_remoted_configuration, teardown_remoted_configuration), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/remoted/test_sendmsg.c b/src/unit_tests/remoted/test_sendmsg.c deleted file mode 100644 index 5b8033ad8ca..00000000000 --- a/src/unit_tests/remoted/test_sendmsg.c +++ /dev/null @@ -1,541 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../remoted/remoted.h" -#include "../remoted/state.h" -#include "../headers/shared.h" - -#include "../wrappers/common.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/wazuh/os_crypto/keys_wrappers.h" -#include "../wrappers/wazuh/os_crypto/msgs_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/time_op_wrappers.h" -#include "../wrappers/wazuh/remoted/netbuffer_wrappers.h" - -extern remoted_state_t remoted_state; - -/* setup/teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -static int test_setup_keys(void ** state) { - test_mode = 1; - - keyentry *node_key = NULL; - os_calloc(1, sizeof(keyentry), node_key); - node_key->rcvd = 10; - node_key->sock = 15; - os_strdup("001",node_key->id); - - os_calloc(2, sizeof(keyentry*), keys.keyentries); - keys.keyentries[0] = node_key; - keys.keyentries[1] = NULL; - - return 0; -} - -static int test_teardown_keys(void **state){ - test_mode = 0; - - os_free(keys.keyentries[0]->id); - os_free(keys.keyentries[0]); - os_free(keys.keyentries); - - return 0; -} - -static int test_setup_tcp(void ** state) { - - test_setup_keys(state); - keys.keyentries[0]->net_protocol = REMOTED_NET_PROTOCOL_TCP; - - return 0; -} - -static int test_teardown_tcp(void ** state) { - return test_teardown_keys(state); -} - -static int test_setup_udp(void ** state) { - - test_setup_keys(state); - keys.keyentries[0]->net_protocol = REMOTED_NET_PROTOCOL_UDP; - - return 0; -} - -static int test_teardown_udp(void ** state) { - return test_teardown_keys(state); -} - -/* Tests */ - -void test_send_msg_invalid_agent(void ** state) { - (void) state; - - const char *const agent_id = "555"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - - // Setup invalid agent error - will_return(__wrap_OS_IsAllowedID, -1); - - expect_function_call(__wrap_rwlock_unlock); - - expect_string(__wrap__merror, formatted_msg, "(1320): Agent '555' not found."); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_disconnected_agent(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - - const int key = 0; - - // Setup disconnected agent - const time_t now = 1000; - logr.global.agents_disconnection_time = 300; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, now); - - expect_function_call(__wrap_rwlock_unlock); - - expect_string(__wrap__mdebug1, formatted_msg, "(1245): Sending message to disconnected agent '001'."); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_encryption_error(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - const int key = 0; - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - - // Setup message encryption error - const char *const crypto_msg = ""; - const ssize_t crypto_size = 0; - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_rwlock_unlock); - - expect_string(__wrap__merror,formatted_msg,"(1217): Error creating encrypted message."); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_tcp_ok(void ** state) { - (void) state; - - char *agent_id = "001"; - char *msg = "abcdefghijk"; - ssize_t msg_length = strlen(msg); - int key = 0; - - char *crypto_msg = "!@#123abc"; - ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_nb_queue, socket, 15); - expect_string(__wrap_nb_queue, crypt_msg, crypto_msg); - expect_value(__wrap_nb_queue, msg_size, crypto_size); - expect_string(__wrap_nb_queue, agent_id, agent_id); - will_return(__wrap_nb_queue, 0); - - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_rwlock_unlock); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, 0); -} - -void test_send_msg_tcp_err(void ** state) { - (void) state; - - char *agent_id = "001"; - char *msg = "abcdefghijk"; - ssize_t msg_length = strlen(msg); - int key = 0; - - char *crypto_msg = "!@#123abc"; - ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_nb_queue, socket, 15); - expect_string(__wrap_nb_queue, crypt_msg, crypto_msg); - expect_value(__wrap_nb_queue, msg_size, crypto_size); - expect_string(__wrap_nb_queue, agent_id, agent_id); - will_return(__wrap_nb_queue, -1); - - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_rwlock_unlock); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_tcp_err_closed_socket(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - const int key = 0; - - const char *const crypto_msg = "!@#123abc"; - const ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - // Setup closed socket - keys.keyentries[0]->sock=-1; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_rwlock_unlock); - - expect_string(__wrap__mdebug1, formatted_msg, "Send operation cancelled due to closed socket."); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_udp_ok(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - const int key = 0; - - const char *const crypto_msg = "!@#123abc"; - const ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - will_return(__wrap_sendto, crypto_size); - - expect_value(__wrap_rem_add_send, bytes, crypto_size); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_rwlock_unlock); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, 0); -} - -void test_send_msg_udp_error(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - const int key = 0; - - const char *const crypto_msg = "!@#123abc"; - const ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - // Setup udp connection error - will_return(__wrap_sendto, 0); - errno = 0; - - expect_string(__wrap__mwarn,formatted_msg,"(1218): Unable to send message to '001': A message could not be delivered completely. [15]"); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_rwlock_unlock); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_udp_error_connection_reset(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - const int key = 0; - - const char *const crypto_msg = "!@#123abc"; - const ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - // Setup udp connection reset error - will_return(__wrap_sendto, 0); - errno = ECONNRESET; - - expect_string(__wrap__mdebug1,formatted_msg,"(1218): Unable to send message to '001': Agent may have disconnected. [15]"); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_rwlock_unlock); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_udp_error_agent_not_responding(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - const int key = 0; - - const char *const crypto_msg = "!@#123abc"; - const ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - // Setup udp connection reset error - will_return(__wrap_sendto, 0); - errno = EAGAIN; - - expect_string(__wrap__mwarn,formatted_msg,"(1218): Unable to send message to '001': Agent is not responding. [15]"); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_rwlock_unlock); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -void test_send_msg_udp_error_generic(void ** state) { - (void) state; - - const char *const agent_id = "001"; - const char *const msg = "abcdefghijk"; - const ssize_t msg_length = strlen(msg); - const int key = 0; - - const char *const crypto_msg = "!@#123abc"; - const ssize_t crypto_size = strlen(crypto_msg); - - logr.global.agents_disconnection_time = 0; - - expect_function_call(__wrap_rwlock_lock_read); - - expect_string(__wrap_OS_IsAllowedID, id, agent_id); - will_return(__wrap_OS_IsAllowedID, key); - - will_return(__wrap_time, (time_t)0); - - expect_string(__wrap_CreateSecMSG, msg, msg); - expect_value(__wrap_CreateSecMSG, msg_length, msg_length); - expect_value(__wrap_CreateSecMSG, id, key); - will_return(__wrap_CreateSecMSG, crypto_size); - will_return(__wrap_CreateSecMSG, crypto_msg); - - expect_function_call(__wrap_pthread_mutex_lock); - - // Setup udp error - will_return(__wrap_sendto, 0); - errno = EACCES; - - expect_string(__wrap__merror,formatted_msg,"(1218): Unable to send message to '001': Permission denied [15]"); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_rwlock_unlock); - - int ret = send_msg(agent_id, msg, msg_length); - - assert_int_equal(ret, -1); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Guard clauses tests - cmocka_unit_test_setup_teardown(test_send_msg_invalid_agent, test_setup_keys, test_teardown_keys), - cmocka_unit_test_setup_teardown(test_send_msg_disconnected_agent, test_setup_keys, test_teardown_keys), - cmocka_unit_test_setup_teardown(test_send_msg_encryption_error, test_setup_keys, test_teardown_keys), - - // TCP tests - cmocka_unit_test_setup_teardown(test_send_msg_tcp_ok, test_setup_tcp, test_teardown_tcp), - cmocka_unit_test_setup_teardown(test_send_msg_tcp_err, test_setup_tcp, test_teardown_tcp), - cmocka_unit_test_setup_teardown(test_send_msg_tcp_err_closed_socket, test_setup_tcp, test_teardown_tcp), - - // UDP tests - cmocka_unit_test_setup_teardown(test_send_msg_udp_ok, test_setup_udp, test_teardown_udp), - cmocka_unit_test_setup_teardown(test_send_msg_udp_error, test_setup_udp, test_teardown_udp), - cmocka_unit_test_setup_teardown(test_send_msg_udp_error_connection_reset, test_setup_udp, test_teardown_udp), - cmocka_unit_test_setup_teardown(test_send_msg_udp_error_agent_not_responding, test_setup_udp, test_teardown_udp), - cmocka_unit_test_setup_teardown(test_send_msg_udp_error_generic, test_setup_udp, test_teardown_udp), - - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/remoted/test_syslogtcp.c b/src/unit_tests/remoted/test_syslogtcp.c deleted file mode 100644 index 1837f247659..00000000000 --- a/src/unit_tests/remoted/test_syslogtcp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../remoted/remoted.h" -#include "../../headers/shared.h" -#include "../../os_net/os_net.h" - - -/* Forward declarations */ -size_t w_get_pri_header_len(const char * syslog_msg); - -/* setup/teardown */ - -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -/* Wrappers */ - -/* Tests */ - -// w_get_pri_header_len - -void test_w_get_pri_header_len_null(void ** state) { - - const ssize_t expected_retval = 0; - ssize_t retval = w_get_pri_header_len(NULL); - - assert_int_equal(retval, expected_retval); -} - -void test_w_get_pri_header_len_no_pri(void ** state) { - - const ssize_t expected_retval = 0; - ssize_t retval = w_get_pri_header_len("test log"); - - assert_int_equal(retval, expected_retval); -} - -void test_w_get_pri_header_len_w_pri(void ** state) { - - const ssize_t expected_retval = 4; - ssize_t retval = w_get_pri_header_len("<18>test log"); - - assert_int_equal(retval, expected_retval); -} - -void test_w_get_pri_header_len_not_end(void ** state) { - - const ssize_t expected_retval = 0; - ssize_t retval = w_get_pri_header_len("<18 test log"); - - assert_int_equal(retval, expected_retval); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test w_get_pri_header_len - cmocka_unit_test(test_w_get_pri_header_len_null), - cmocka_unit_test(test_w_get_pri_header_len_no_pri), - cmocka_unit_test(test_w_get_pri_header_len_w_pri), - cmocka_unit_test(test_w_get_pri_header_len_not_end), - - }; - - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/shared/test_agent_op.c b/src/unit_tests/shared/test_agent_op.c deleted file mode 100644 index 3686d173bcf..00000000000 --- a/src/unit_tests/shared/test_agent_op.c +++ /dev/null @@ -1,599 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../headers/sec.h" -#include "../../addagent/manage_agents.h" - -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/libc/string_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "cJSON.h" - -/* redefinitons/wrapping */ - -extern cJSON* w_create_agent_add_payload(const char *name, const char *ip, const char *groups, const char *key_hash, const char *key, const char *id, authd_force_options_t *force_options); -extern cJSON* w_create_agent_remove_payload(const char *id, const int purge); -extern cJSON* w_create_sendsync_payload(const char *daemon_name, cJSON *message); -extern int w_parse_agent_add_response(const char* buffer, char *err_response, char* id, char* key, const int json_format, const int exit_on_error); -extern int w_parse_agent_remove_response(const char* buffer, char *err_response, const int json_format, const int exit_on_error); - -static void test_create_agent_add_payload(void **state) { - char* agent = "agent1"; - char* ip = "192.0.0.0"; - char* groups = "Group1,Group2"; - char* key = "1234"; - char* key_hash = "7110eda4d09e062aa5e4a390b0a572ac0d2c0220"; - authd_force_options_t force_options = {0}; - char* id = "001"; - cJSON* payload = NULL; - char* expected_force_payload = "{\"disconnected_time\":{\"enabled\":false,\"value\":0}," - "\"enabled\":true,\"key_mismatch\":false,\"after_registration_time\":0}"; - - force_options.disconnected_time_enabled = false; - force_options.disconnected_time = 0; - force_options.enabled = true; - force_options.key_mismatch = false; - force_options.after_registration_time = 0; - - payload = w_create_agent_add_payload(agent, ip, groups, key_hash, key, id, &force_options); - - assert_non_null(payload); - cJSON* function = cJSON_GetObjectItem(payload, "function"); - assert_non_null(function); - assert_string_equal(function->valuestring, "add"); - - cJSON* arguments = cJSON_GetObjectItem(payload, "arguments"); - assert_non_null(arguments); - - cJSON* item = NULL; - item = cJSON_GetObjectItem(arguments, "groups"); - assert_non_null(item); - assert_string_equal(item->valuestring, groups); - - item = cJSON_GetObjectItem(arguments, "key"); - assert_non_null(item); - assert_string_equal(item->valuestring, key); - - item = cJSON_GetObjectItem(arguments, "key_hash"); - assert_non_null(item); - assert_string_equal(item->valuestring, key_hash); - - item = cJSON_GetObjectItem(arguments, "id"); - assert_non_null(item); - assert_string_equal(item->valuestring, id); - - cJSON* j_force = cJSON_GetObjectItem(arguments, "force"); - assert_non_null(j_force); - - char* str_force = cJSON_PrintUnformatted(j_force); - assert_string_equal(str_force, expected_force_payload); - - cJSON_Delete(payload); - os_free(str_force); -} - -#ifndef WIN32 -static void test_create_agent_remove_payload(void **state) { - char* id = "001"; - int purge = 1; - cJSON* payload = NULL; - payload = w_create_agent_remove_payload(id, purge); - - assert_non_null(payload); - cJSON* function = cJSON_GetObjectItem(payload, "function"); - assert_non_null(function); - assert_string_equal(function->valuestring, "remove"); - - cJSON* arguments = cJSON_GetObjectItem(payload, "arguments"); - assert_non_null(arguments); - - cJSON* item = NULL; - item = cJSON_GetObjectItem(arguments, "id"); - assert_non_null(item); - assert_string_equal(item->valuestring, id); - - - item = cJSON_GetObjectItem(arguments, "purge"); - assert_non_null(item); - assert_int_equal(item->valueint, purge); - - cJSON_Delete(payload); -} - -static void test_create_sendsync_payload(void **state) { - char* daemon = "daemon_test"; - char* id = "001"; - int purge = 1; - cJSON* payload = NULL; - cJSON* message = NULL; - cJSON* item = NULL; - /* NULL message */ - payload = w_create_sendsync_payload(daemon, message); - - assert_non_null(payload); - - item = cJSON_GetObjectItem(payload, "daemon_name"); - assert_non_null(item); - assert_string_equal(item->valuestring, daemon); - - item = cJSON_GetObjectItem(payload, "message"); - assert_null(item); - - cJSON_Delete(payload); - - /* non NULL message */ - message = w_create_agent_remove_payload(id,purge); - payload = w_create_sendsync_payload(daemon, message); - - assert_non_null(payload); - - item = cJSON_GetObjectItem(payload, "daemon_name"); - assert_non_null(item); - assert_string_equal(item->valuestring, daemon); - - item = cJSON_GetObjectItem(payload, "message"); - assert_non_null(item); - - cJSON_Delete(payload); -} - -static void test_parse_agent_remove_response(void **state) { - char* success_response = "{\"error\":0}"; - char* error_response = "{\"error\":9009,\"message\":\"ERROR_MESSAGE\"}"; - char* unknown_response = "{\"message \":\"any_message\"}"; - int err = 0; - char err_response[OS_MAXSTR + 1]; - - // Remove _merror checks - expect_any_always(__wrap__merror, formatted_msg); - - /* Success parse */ - err = w_parse_agent_remove_response(success_response, err_response, FALSE, FALSE); - assert_int_equal(err, 0); - - /* Error parse */ - err = w_parse_agent_remove_response(error_response, err_response, FALSE, FALSE); - assert_int_equal(err, -1); - assert_string_equal(err_response, "ERROR: ERROR_MESSAGE"); - - /* Unknown parse */ - err = w_parse_agent_remove_response(unknown_response, err_response, FALSE, FALSE); - assert_int_equal(err, -2); - assert_string_equal(err_response, "ERROR: Invalid message format"); -} - -/* Tests w_send_clustered_message */ - -void test_w_send_clustered_message_connection_error(void **state) { - char response[OS_MAXSTR + 1]; - - for (int i=0; i < CLUSTER_SEND_MESSAGE_ATTEMPTS; ++i) { - will_return(__wrap_external_socket_connect, -1); - - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mwarn, formatted_msg, "Could not connect to socket 'queue/cluster/c-internal.sock': ERROR (0)."); - } - expect_value_count(__wrap_sleep, seconds, 1, 9); - - expect_string(__wrap__merror, formatted_msg, "Could not send message through the cluster after '10' attempts."); - - assert_int_equal(w_send_clustered_message("command", "payload", response), -2); -} - -void test_w_send_clustered_message_send_error(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - for (int i=0; i < CLUSTER_SEND_MESSAGE_ATTEMPTS; ++i) { - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, -1); - - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mwarn, formatted_msg, "OS_SendSecureTCPCluster(): ERROR"); - } - expect_value_count(__wrap_sleep, seconds, 1, 9); - - expect_string(__wrap__merror, formatted_msg, "Could not send message through the cluster after '10' attempts."); - - assert_int_equal(w_send_clustered_message(command, payload, response), -2); -} - -void test_w_send_clustered_message_recv_cluster_error_detected(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - for (int i=0; i < CLUSTER_SEND_MESSAGE_ATTEMPTS; ++i) { - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, -2); - - expect_string(__wrap__mwarn, formatted_msg, "Cluster error detected"); - } - expect_value_count(__wrap_sleep, seconds, 1, 9); - - expect_string(__wrap__merror, formatted_msg, "Could not send message through the cluster after '10' attempts."); - - assert_int_equal(w_send_clustered_message(command, payload, response), -1); -} - -void test_w_send_clustered_message_recv_error(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - for (int i=0; i < CLUSTER_SEND_MESSAGE_ATTEMPTS; ++i) { - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, -1); - - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mwarn, formatted_msg, "OS_RecvSecureClusterTCP(): ERROR"); - } - expect_value_count(__wrap_sleep, seconds, 1, 9); - - expect_string(__wrap__merror, formatted_msg, "Could not send message through the cluster after '10' attempts."); - - assert_int_equal(w_send_clustered_message(command, payload, response), -1); -} - -void test_w_send_clustered_message_recv_empty_message(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Empty message from local client."); - - assert_int_equal(w_send_clustered_message(command, payload, response), -1); -} - -void test_w_send_clustered_message_recv_max_len(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, OS_MAXLEN); - - expect_string(__wrap__merror, formatted_msg, "Received message > 65536"); - - assert_int_equal(w_send_clustered_message(command, payload, response), -1); -} - -void test_w_send_clustered_message_success(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, strlen(recv_response)); - - assert_int_equal(w_send_clustered_message(command, payload, response), 0); - assert_string_equal(recv_response, response); -} - -void test_w_send_clustered_message_success_after_connection_error(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - will_return(__wrap_external_socket_connect, -1); - - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mwarn, formatted_msg, "Could not connect to socket 'queue/cluster/c-internal.sock': ERROR (0)."); - expect_value(__wrap_sleep, seconds, 1); - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, strlen(recv_response)); - - assert_int_equal(w_send_clustered_message(command, payload, response), 0); - assert_string_equal(recv_response, response); -} - -void test_w_send_clustered_message_success_after_send_error(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, -1); - - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mwarn, formatted_msg, "OS_SendSecureTCPCluster(): ERROR"); - - expect_value(__wrap_sleep, seconds, 1); - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, strlen(recv_response)); - - assert_int_equal(w_send_clustered_message(command, payload, response), 0); - assert_string_equal(recv_response, response); -} - -void test_w_send_clustered_message_success_after_cluster_error(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, -2); - - expect_string(__wrap__mwarn, formatted_msg, "Cluster error detected"); - expect_value(__wrap_sleep, seconds, 1); - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, strlen(recv_response)); - - assert_int_equal(w_send_clustered_message(command, payload, response), 0); - assert_string_equal(recv_response, response); -} - -void test_w_send_clustered_message_success_after_recv_error(void **state) { - char response[OS_MAXSTR + 1]; - char *command = "command"; - char *payload = "payload"; - char *recv_response = "response"; - size_t payload_size = strlen(payload); - int sock_num = 3; - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, -1); - - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mwarn, formatted_msg, "OS_RecvSecureClusterTCP(): ERROR"); - expect_value(__wrap_sleep, seconds, 1); - - will_return(__wrap_external_socket_connect, sock_num); - - expect_value(__wrap_OS_SendSecureTCPCluster, sock, sock_num); - expect_value(__wrap_OS_SendSecureTCPCluster, command, command); - expect_string(__wrap_OS_SendSecureTCPCluster, payload, payload); - expect_value(__wrap_OS_SendSecureTCPCluster, length, payload_size); - will_return(__wrap_OS_SendSecureTCPCluster, 1); - - expect_value(__wrap_OS_RecvSecureClusterTCP, sock, sock_num); - expect_value(__wrap_OS_RecvSecureClusterTCP, length, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureClusterTCP, recv_response); - will_return(__wrap_OS_RecvSecureClusterTCP, strlen(recv_response)); - - assert_int_equal(w_send_clustered_message(command, payload, response), 0); - assert_string_equal(recv_response, response); -} -#endif - -static void test_parse_agent_add_response(void **state) { - char* success_response = "{\"error\":0,\"data\":{\"id\":\"001\",\"name\":\"agent1\",\"ip\":\"any\",\"key\":\"347e2dc688148aec8544c9777ff291b8868b885\"}}"; - char* missingdata_response = "{\"error\":0}"; - char* missingkey_response = "{\"error\":0,\"data\":{\"id\":\"001\",\"name\":\"agent1\",\"ip\":\"any\"}}"; - char* missingid_response = "{\"error\":0,\"data\":{\"name\":\"agent1\",\"ip\":\"any\",\"key\":\"347e2dc688148aec8544c9777ff291b8868b885\"}}"; - char* error_response = "{\"error\":9009,\"message\":\"ERROR_MESSAGE\"}"; - char* unknown_response = "{\"message \":\"any_message\"}"; - char new_id[FILE_SIZE+1] = { '\0' }; - char new_key[KEYSIZE+1] = { '\0' }; - int err = 0; - char err_response[OS_MAXSTR + 1]; - - // Remove _mwarn checks - expect_any_always(__wrap__mwarn, formatted_msg); - - /* Success parse */ - err = w_parse_agent_add_response(success_response, err_response, new_id, new_key, FALSE, FALSE); - assert_int_equal(err, 0); - assert_string_equal(new_id, "001"); - assert_string_equal(new_key, "347e2dc688148aec8544c9777ff291b8868b885"); - - err = w_parse_agent_add_response(success_response, err_response, new_id, NULL, FALSE, FALSE); - assert_int_equal(err, 0); - assert_string_equal(new_id, "001"); - - err = w_parse_agent_add_response(success_response, err_response, NULL, new_key, FALSE, FALSE); - assert_int_equal(err, 0); - assert_string_equal(new_key, "347e2dc688148aec8544c9777ff291b8868b885"); - - /* Error parse */ - err = w_parse_agent_add_response(error_response, err_response, new_id, new_key, FALSE, FALSE); - assert_int_equal(err, -1); - assert_string_equal(err_response, "ERROR: ERROR_MESSAGE"); - - /* Unknown parse */ - err = w_parse_agent_add_response(unknown_response, err_response, new_id, new_key, FALSE, FALSE); - assert_int_equal(err, -2); - assert_string_equal(err_response, "ERROR: Invalid message format"); - - /* Missing Data parse */ - err = w_parse_agent_add_response(missingdata_response, err_response, new_id, new_key, FALSE, FALSE); - assert_int_equal(err, -2); - assert_string_equal(err_response, "ERROR: Invalid message format"); - - /* Missing ID parse */ - err = w_parse_agent_add_response(missingid_response, err_response, new_id, new_key, FALSE, FALSE); - assert_int_equal(err, -2); - assert_string_equal(err_response, "ERROR: Invalid message format"); - - /* Missing key parse */ - err = w_parse_agent_add_response(missingkey_response, err_response, new_id, new_key, FALSE, FALSE); - assert_int_equal(err, -2); - assert_string_equal(err_response, "ERROR: Invalid message format"); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_create_agent_add_payload), - cmocka_unit_test(test_parse_agent_add_response), - #ifndef WIN32 - cmocka_unit_test(test_create_agent_remove_payload), - cmocka_unit_test(test_create_sendsync_payload), - cmocka_unit_test(test_parse_agent_remove_response), - // Tests w_send_clustered_message - cmocka_unit_test(test_w_send_clustered_message_connection_error), - cmocka_unit_test(test_w_send_clustered_message_send_error), - cmocka_unit_test(test_w_send_clustered_message_recv_cluster_error_detected), - cmocka_unit_test(test_w_send_clustered_message_recv_error), - cmocka_unit_test(test_w_send_clustered_message_recv_empty_message), - cmocka_unit_test(test_w_send_clustered_message_recv_max_len), - cmocka_unit_test(test_w_send_clustered_message_success), - cmocka_unit_test(test_w_send_clustered_message_success_after_connection_error), - cmocka_unit_test(test_w_send_clustered_message_success_after_send_error), - cmocka_unit_test(test_w_send_clustered_message_success_after_cluster_error), - cmocka_unit_test(test_w_send_clustered_message_success_after_recv_error), - #endif - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/shared/test_bqueue.c b/src/unit_tests/shared/test_bqueue.c deleted file mode 100644 index b1cde88f243..00000000000 --- a/src/unit_tests/shared/test_bqueue.c +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../headers/bqueue_op.h" - -static const char * MESSAGE = "AB"; - - -static int test_setup_2(void **state) { - test_mode = 1; - - bqueue_t *bqueue = bqueue_init(2, BQUEUE_NOFLAG); - *state = bqueue; - return 0; -} - -static int test_setup_3(void **state) { - test_mode = 1; - - bqueue_t *bqueue = bqueue_init(3, BQUEUE_NOFLAG); - *state = bqueue; - return 0; -} - -static int test_setup_20(void **state) { - test_mode = 1; - - bqueue_t *bqueue = bqueue_init(20, BQUEUE_NOFLAG); - *state = bqueue; - return 0; -} - -static int test_setup_1024(void **state) { - test_mode = 1; - - bqueue_t *bqueue = bqueue_init(1024+1, BQUEUE_SHRINK); - *state = bqueue; - return 0; -} - -static int test_teardown(void **state) { - test_mode = 0; - - bqueue_t *bqueue = *state; - bqueue_destroy(bqueue); - return 0; -} - -static void test_bqueue_init_fail(void **state) { - (void) state; - - // 1-byte queue is forbidden - bqueue_t * queue = bqueue_init(1, BQUEUE_NOFLAG); - assert_null(queue); - - free(queue); -} - -static void test_bqueue_init_ok(void **state) { - (void) state; - - // 2-byte queue is allowed - bqueue_t * queue = bqueue_init(2, BQUEUE_NOFLAG); - assert_non_null(queue); - bqueue_destroy(queue); -} - -static void test_bqueue_destroy_fail(void **state) { - (void) state; - - bqueue_t * queue = NULL; - bqueue_destroy(queue); - assert_null(queue); -} - -static void test_bqueue_destroy_ok(void **state) { - (void) state; - - bqueue_t * queue = bqueue_init(2, BQUEUE_NOFLAG); - bqueue_destroy(queue); - assert_non_null(queue); -} - -static void test_bqueue_push_fail(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), -1); -} - -static void test_bqueue_push_fail_non_space(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), -1); -} - -static void test_bqueue_push_ok(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); -} - -static void test_bqueue_push_pop_ok(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); - - char buffer[3] = ""; - assert_int_equal(bqueue_pop(queue, buffer, sizeof(buffer), BQUEUE_NOFLAG), strlen(MESSAGE)); - assert_string_equal(MESSAGE, buffer); -} - -static void test_bqueue_push_second_pop_fail(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); - - char buffer[3] = ""; - assert_int_equal(bqueue_pop(queue, buffer, sizeof(buffer), BQUEUE_NOFLAG), strlen(MESSAGE)); - assert_int_equal(bqueue_pop(queue, buffer, sizeof(buffer), BQUEUE_NOFLAG), 0); -} - -static void test_bqueue_push_pop_used_ok(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - // Push 2 char - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); - - char buffer[3] = ""; - // Try to pop 3 bytes, but it should return 2 - assert_int_equal(bqueue_pop(queue, buffer, sizeof(buffer), BQUEUE_WAIT), strlen(MESSAGE)); - // queue should be 0 - assert_int_equal(bqueue_used(queue), 0); - assert_string_equal(MESSAGE, buffer); -} - -static void test_bqueue_push_second_peek_empty(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - // Push 2 char - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); - - char buffer[3] = ""; - // Try to peek 3 bytes, but it should return 2 - assert_int_equal(bqueue_peek(queue, buffer, sizeof(buffer), BQUEUE_WAIT), strlen(MESSAGE)); - // drop more bytes than used. - assert_int_equal(bqueue_drop(queue, 2), 0); - // second peek - assert_int_equal(bqueue_peek(queue, buffer, sizeof(buffer), BQUEUE_NOFLAG), 0); -} - -static void test_bqueue_push_peek_drop_ok(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - - // Push 2 char - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); - - char buffer[3] = ""; - // Try to peek 3 bytes, but it should return 2 - assert_int_equal(bqueue_peek(queue, buffer, sizeof(buffer), BQUEUE_NOFLAG), strlen(MESSAGE)); - // drop peeked bytes - assert_int_equal(bqueue_drop(queue, 2), 0); - // queue should be 0 - assert_int_equal(bqueue_used(queue), 0); - assert_string_equal(MESSAGE, buffer); -} - -static void test_bqueue_push_peek_drop_fail(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - // Push 2 char - assert_int_equal(bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG), 0); - - char buffer[3] = ""; - // Try to peek 3 bytes, but it should return 2 - assert_int_equal(bqueue_peek(queue, buffer, sizeof(buffer), BQUEUE_WAIT), strlen(MESSAGE)); - // drop more bytes than used. - assert_int_equal(bqueue_drop(queue, 4), -1); -} - -static void test_bqueue_push_clear_ok(void **state) { - bqueue_t *queue = *state; - - assert_non_null(queue); - - // Push 2 char - int push = bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_WAIT); - assert_int_equal(push, 0); - - size_t used = bqueue_used(queue); - assert_int_equal(used, strlen(MESSAGE)); - - bqueue_clear(queue); - used = bqueue_used(queue); - assert_int_equal(used, 0); -} - -static void test_bqueue_push_pop_full_buff(void **state) { - /* This test will complete 1024 bytes of bufer with AB string, - pop and validate last 2 bytes - - Buffer: |ABABABAB........ABABAB| - ^^ - */ - bqueue_t *queue = *state; - - for (int a = 0; a < (1024 / strlen(MESSAGE)); a++) { - if (bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG) != 0) { - assert_null(queue); - break; - } - } - - assert_int_equal(bqueue_used(queue), 1024); - - char buffer[3] = ""; - - for (int a = 0; a < (1024 / strlen(MESSAGE)); a++) { - if (bqueue_pop(queue, buffer, strlen(MESSAGE), BQUEUE_NOFLAG) != strlen(MESSAGE)) { - assert_null(queue); - break; - } - } - - assert_string_equal(MESSAGE, buffer); - assert_int_equal(bqueue_used(queue), 0); - assert_non_null(queue); -} - -static void test_bqueue_push_pop_rollover(void **state) { - /* This test will complete 1022 spaces of 1024 bufer with AB string, - and pop first 3 bytes, then push 5 new bytes and validate last 5 bytes - - Buffer: |345BABAB........ABAB12| - ^^^ ^^ - */ - bqueue_t *queue = *state; - - char buffer[1024] = ""; - // complete fist 1022 buffer spaces with "AB" - for (int a = 0; a < (1024 / strlen(MESSAGE) -1 ); a++) { - if (bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG) != 0) { - assert_null(queue); - break; - } - } - assert_int_equal(bqueue_used(queue), 1022); - - // pop first 3 bytes. - bqueue_pop(queue, buffer, 3, BQUEUE_NOFLAG); - assert_string_equal(buffer, "ABA"); - - // push new string "12345" to roll over buffer - assert_int_equal(bqueue_push(queue, "12345", 5, BQUEUE_NOFLAG), 0); - - // pop 1022 - 3 bytes to point before last bytes of the buffer "1" - assert_int_equal(bqueue_pop(queue, buffer, 1019, BQUEUE_NOFLAG), 1019); - - memset(buffer, 0, sizeof(buffer)); - /* pop 5 bytes, before last and last byte of the buffer, - and first 3 bytes of the buffer "12345" */ - assert_int_equal(bqueue_pop(queue, buffer, 5, BQUEUE_NOFLAG), 5); - - assert_string_equal("12345", buffer); - assert_non_null(queue); -} - -static void test_bqueue_push_drop_cross_pointers(void **state) { - /* - Buffer: |345...AB12| - T H - */ - bqueue_t *queue = *state; - - char buffer[11] = ""; - assert_non_null(queue); - - // complete fist 10 buffer spaces with "AB" - for (int a = 0; a < (10 / strlen(MESSAGE)-1); a++) { - if (bqueue_push(queue, MESSAGE, strlen(MESSAGE), BQUEUE_NOFLAG) != 0) { - assert_null(queue); - break; - } - } - assert_int_equal(bqueue_used(queue), 8); - - // drop first 6 bytes. - assert_int_equal(bqueue_drop(queue, 6), 0); - - // push new string "12345" to roll over buffer - assert_int_equal(bqueue_push(queue, "12345", 5, BQUEUE_NOFLAG), 0); - - // push another string "67890" to roll over buffer - assert_int_equal(bqueue_push(queue, "67890", 5, BQUEUE_NOFLAG), 0); - - // pop 2 bytes - assert_int_equal(bqueue_pop(queue, buffer, 2, BQUEUE_NOFLAG), 2); - assert_string_equal("AB", buffer); - - memset(buffer, 0, sizeof(buffer)); - /* pop 5 bytes, before last and last byte of the buffer, - and first 3 bytes of the buffer "12345" */ - assert_int_equal(bqueue_pop(queue, buffer, 10, BQUEUE_NOFLAG), 10); - - assert_string_equal("1234567890", buffer); -} - -static void test_bqueue_push_drop_to_expand(void **state) { - - bqueue_t *queue = *state; - - char buffer[10] = ""; - assert_non_null(queue); - - // push 10 elements into the table. - assert_int_equal(bqueue_push(queue, "1234567890", 10, BQUEUE_NOFLAG), 0); - assert_int_equal(bqueue_used(queue), 10); - - // drop first 6 bytes. - assert_int_equal(bqueue_drop(queue, 6), 0); - - // push new string "12345" to roll over buffer - assert_int_equal(bqueue_push(queue, "12345", 5, BQUEUE_NOFLAG), 0); - - // pop 3 bytes - assert_int_equal(bqueue_pop(queue, buffer, 3, BQUEUE_NOFLAG), 3); - assert_string_equal("789", buffer); - - // push another string "67890" - assert_int_equal(bqueue_push(queue, "67890", 5, BQUEUE_NOFLAG), 0); - - memset(buffer, 0, sizeof(buffer)); - // pop 2 bytes - assert_int_equal(bqueue_pop(queue, buffer, 2, BQUEUE_NOFLAG), 2); - assert_string_equal("01", buffer); - - memset(buffer, 0, sizeof(buffer)); - // pop 7 bytes - assert_int_equal(bqueue_pop(queue, buffer, 7, BQUEUE_NOFLAG), 7); - - assert_string_equal("2345678", buffer); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_bqueue_init_fail), - cmocka_unit_test(test_bqueue_init_ok), - cmocka_unit_test(test_bqueue_destroy_fail), - cmocka_unit_test(test_bqueue_destroy_ok), - cmocka_unit_test_setup_teardown(test_bqueue_push_fail, test_setup_2, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_fail_non_space, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_ok, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_pop_ok, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_second_pop_fail, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_pop_used_ok, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_second_peek_empty, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_peek_drop_ok, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_peek_drop_fail, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_clear_ok, test_setup_3, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_pop_full_buff, test_setup_1024, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_pop_rollover, test_setup_1024, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_drop_cross_pointers, test_setup_20, test_teardown), - cmocka_unit_test_setup_teardown(test_bqueue_push_drop_to_expand, test_setup_20, test_teardown), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/syscheckd/CMakeLists.txt b/src/unit_tests/syscheckd/CMakeLists.txt deleted file mode 100644 index 374fbb14fd1..00000000000 --- a/src/unit_tests/syscheckd/CMakeLists.txt +++ /dev/null @@ -1,389 +0,0 @@ -# Generate syscheck library -if(${TARGET} STREQUAL "winagent") - file(GLOB sysfiles ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd-event.dir/src/*.obj - ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd-event.dir/src/*/*.obj) - list(REMOVE_ITEM sysfiles ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd.dir/src/main.c.obj) -else() - file(GLOB sysfiles ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd.dir/src/*.o - ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd.dir/src/*/*.o) - list(REMOVE_ITEM sysfiles ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd.dir/src/main.c.o) -endif() - -file(GLOB rootfiles ${SRC_FOLDER}/rootcheck/*.o) - -if(${TARGET} STREQUAL "winagent") - # Exclude winagent file - list(FILTER rootfiles EXCLUDE REGEX ".*_rk.o$") - - # Add test wrappers - file(GLOB test_wrapper_files - ${SRC_FOLDER}/unit_tests/wrappers/externals/*.o - ${SRC_FOLDER}/unit_tests/wrappers/externals/audit/*.o - ${SRC_FOLDER}/unit_tests/wrappers/externals/bzip2/*.o - ${SRC_FOLDER}/unit_tests/wrappers/externals/cJSON/*.o - ${SRC_FOLDER}/unit_tests/wrappers/externals/openssl/*.o - ${SRC_FOLDER}/unit_tests/wrappers/externals/procpc/*.o - ${SRC_FOLDER}/unit_tests/wrappers/externals/sqlite/*.o - ${SRC_FOLDER}/unit_tests/wrappers/libc/*.o - ${SRC_FOLDER}/unit_tests/wrappers/linux/*.o - ${SRC_FOLDER}/unit_tests/wrappers/posix/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/os_crypto/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/os_net/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/os_regex/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/syscheckd/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/wazuh_db/*.o - ${SRC_FOLDER}/unit_tests/wrappers/wazuh/wazuh_modules/*.o - ${SRC_FOLDER}/unit_tests/wrappers/windows/*.o - ${SRC_FOLDER}/unit_tests/wrappers/windows/libc/*.o - ) - list(APPEND sysfiles ${test_wrapper_files}) -endif() - -add_library(SYSCHECK_O STATIC ${sysfiles}) -add_library(ROOTCHECK_O STATIC ${rootfiles}) - -set_source_files_properties( - ${sysfiles} - ${rootfiles} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - SYSCHECK_O - ROOTCHECK_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(SYSCHECK_O ROOTCHECK_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -# Add fim_tools library to compilation -include_directories(${SRC_FOLDER}/syscheckd/include) -include_directories(${SRC_FOLDER}/syscheckd/src) -include_directories(${SRC_FOLDER}/unit_tests) -include_directories(${SRC_FOLDER}/unit_tests/syscheckd) -include_directories(${SRC_FOLDER}/config) - -add_library(fim_shared STATIC expect_run_check.c - expect_fim_diff_changes.c - utils.c) - -set_target_properties(fim_shared PROPERTIES LINKER_LANGUAGE C ) - - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate syscheckd-event library -if(${TARGET} STREQUAL "winagent") - file(GLOB syscheck_event_files ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd-event.dir/src/*.obj - ${SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd-event.dir/src/*/*.obj) - list(REMOVE_ITEM sysfiles {SRC_FOLDER}/syscheckd/build/CMakeFiles/wazuh-syscheckd-event.dir/src/main.obj) - add_library(SYSCHECK_EVENT_O STATIC ${syscheck_event_files}) - - set_source_files_properties( - ${syscheck_event_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - - set_target_properties( - SYSCHECK_EVENT_O - ROOTCHECK_O - PROPERTIES - LINKER_LANGUAGE C - ) - - target_link_libraries(SYSCHECK_EVENT_O ROOTCHECK_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - add_subdirectory(registry) -endif() - -add_subdirectory(whodata) - -# Generate Syscheckd tests -# syscom.c tests -list(APPEND syscheckd_tests_names "syscom") -set(FIM_SYSCOM_BASE_FLAGS "-Wl,--wrap,getSyscheckConfig -Wl,--wrap,getRootcheckConfig -Wl,--wrap,getSyscheckInternalOptions \ - -Wl,--wrap,getpid -Wl,--wrap,fim_sync_push_msg ${DEBUG_OP_WRAPPERS}") - -if(${TARGET} STREQUAL "winagent") - list(APPEND syscheckd_tests_flags "${FIM_SYSCOM_BASE_FLAGS} -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap=fim_db_init -Wl,--wrap,fim_sync_push_msg \ - -Wl,--wrap=fim_db_get_count_registry_data -Wl,--wrap=fim_db_get_count_registry_key \ - -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_pattern_search -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_db_transaction_deleted_rows \ - -Wl,--wrap=fim_db_file_update -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=is_fim_shutdown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") -else() - list(APPEND syscheckd_tests_flags "${FIM_SYSCOM_BASE_FLAGS}") -endif() - -# fim_diff_changes.c tests -set(FIM_DIFF_CHANGES_BASE_FLAGS "-Wl,--wrap,lstat -Wl,--wrap,stat \ - -Wl,--wrap,fopen -Wl,--wrap,fread -Wl,--wrap,fclose -Wl,--wrap,fwrite -Wl,--wrap,wfopen \ - -Wl,--wrap,w_compress_gzfile -Wl,--wrap,IsDir -Wl,--wrap,mkdir_ex -Wl,--wrap,fflush \ - -Wl,--wrap,w_uncompress_gzfile -Wl,--wrap,OS_MD5_File -Wl,--wrap,File_DateofChange \ - -Wl,--wrap,rename -Wl,--wrap,system -Wl,--wrap,fseek -Wl,--wrap,remove,--wrap=fprintf \ - -Wl,--wrap=fgets -Wl,--wrap,atexit -Wl,--wrap,getpid,--wrap=_mdebug2,--wrap=rmdir_ex,--wrap=rename_ex \ - -Wl,--wrap=DirSize,--wrap=remove_empty_folders,--wrap=abspath,--wrap=getpid \ - -Wl,--wrap,fgetpos -Wl,--wrap=fgetc -Wl,--wrap=pthread_rwlock_wrlock -Wl,--wrap=pthread_mutex_lock \ - -Wl,--wrap=pthread_mutex_unlock -Wl,--wrap=pthread_rwlock_unlock -Wl,--wrap=pthread_rwlock_rdlock \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_db_init -Wl,--wrap=fim_run_integrity \ - -Wl,--wrap=fim_db_transaction_start -Wl,--wrap=fim_db_transaction_sync_row \ - -Wl,--wrap=fim_db_transaction_deleted_rows -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS}") - -list(APPEND syscheckd_tests_names "fim_diff_changes") -if(${TARGET} STREQUAL "winagent") - list(APPEND syscheckd_tests_flags "${FIM_DIFF_CHANGES_BASE_FLAGS} -Wl,--wrap=FileSizeWin -Wl,--wrap,fim_sync_push_msg \ - -Wl,--wrap=fim_db_get_count_registry_data -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") -else() - list(APPEND syscheckd_tests_flags "${FIM_DIFF_CHANGES_BASE_FLAGS} -Wl,--wrap=unlink -Wl,--wrap=FileSize") -endif() - -# run_realtime.c tests -set(RUN_REALTIME_BASE_FLAGS "-Wl,--wrap,inotify_init -Wl,--wrap,inotify_add_watch -Wl,--wrap,fim_db_get_path -Wl,--wrap,fim_db_file_pattern_search \ - -Wl,--wrap,read -Wl,--wrap,rbtree_insert -Wl,--wrap,fim_db_init -Wl,--wrap,fim_db_file_update \ - -Wl,--wrap,W_Vector_insert_unique -Wl,--wrap,send_log_msg -Wl,--wrap,fim_db_remove_path \ - -Wl,--wrap,rbtree_keys -Wl,--wrap,fim_realtime_event -Wl,--wrap=pthread_mutex_lock -Wl,--wrap,wfopen \ - -Wl,--wrap=pthread_mutex_unlock -Wl,--wrap=getpid -Wl,--wrap=atexit -Wl,--wrap=os_random \ - -Wl,--wrap,inotify_rm_watch -Wl,--wrap,pthread_rwlock_wrlock -Wl,--wrap,pthread_rwlock_unlock \ - -Wl,--wrap,fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode -Wl,--wrap,fim_db_get_count_file_entry \ - -Wl,--wrap,pthread_rwlock_rdlock -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - ${HASH_OP_WRAPPERS} ${DEBUG_OP_WRAPPERS}") - -list(APPEND syscheckd_tests_names "run_realtime") -if(${TARGET} STREQUAL "winagent") - list(APPEND syscheckd_tests_flags "${RUN_REALTIME_BASE_FLAGS} -Wl,--wrap=fim_configuration_directory -Wl,--wrap,fim_sync_push_msg \ - -Wl,--wrap=fim_db_get_count_registry_data -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") - - # Create event channel tests for run_realtime - list(APPEND syscheckd_event_tests_names "test_run_realtime_event") - list(APPEND syscheckd_event_tests_flags "${RUN_REALTIME_BASE_FLAGS} -Wl,--wrap=whodata_audit_start \ - -Wl,--wrap=check_path_type,--wrap=set_winsacl,--wrap=w_directory_exists \ - -Wl,--wrap,fim_sync_push_msg -Wl,--wrap=fim_db_get_count_registry_data \ - -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") -else() - list(APPEND syscheckd_tests_flags "${RUN_REALTIME_BASE_FLAGS}") -endif() - -# syscheck_config.c tests -set(SYSCHECK_CONFIG_BASE_FLAGS "-Wl,--wrap,pthread_rwlock_rdlock -Wl,--wrap,pthread_rwlock_unlock \ - -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,fim_db_init \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND syscheckd_tests_names "config") -if(${TARGET} STREQUAL "agent") - list(APPEND syscheckd_tests_flags "${SYSCHECK_CONFIG_BASE_FLAGS}") -else() - if(${TARGET} STREQUAL "winagent") - list(APPEND syscheckd_tests_flags "${SYSCHECK_CONFIG_BASE_FLAGS} -Wl,--wrap,fim_sync_push_msg \ - -Wl,--wrap=fim_db_get_count_registry_data \ - -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") - else() - list(APPEND syscheckd_tests_flags "${SYSCHECK_CONFIG_BASE_FLAGS} -Wl,--wrap,getpid") - endif() -endif() - -# syscheck.c tests -set(SYSCHECK_BASE_FLAGS "-Wl,--wrap,fim_db_init -Wl,--wrap,getDefine_Int -Wl,--wrap,wfopen \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - ${DEBUG_OP_WRAPPERS}") -list(APPEND syscheckd_tests_names "syscheck") -if(${TARGET} STREQUAL "winagent") - list(APPEND syscheckd_tests_flags "${SYSCHECK_BASE_FLAGS} \ - -Wl,--wrap=Read_Syscheck_Config \ - -Wl,--wrap=rootcheck_init \ - -Wl,--wrap=start_daemon \ - -Wl,--wrap=File_DateofChange \ - -Wl,--wrap,getpid,--wrap,realtime_start \ - -Wl,--wrap,pthread_rwlock_rdlock -Wl,--wrap,pthread_rwlock_unlock \ - -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,fim_sync_push_msg \ - -Wl,--wrap=fim_db_get_count_registry_data \ - -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") - -else() - list(APPEND syscheckd_tests_flags "${SYSCHECK_BASE_FLAGS}") -endif() - -# run_check.c tests -set(RUN_CHECK_BASE_FLAGS "-Wl,--wrap,sleep -Wl,--wrap,SendMSGPredicated -Wl,--wrap,StartMQ \ - -Wl,--wrap,realtime_adddir -Wl,--wrap,audit_set_db_consistency -Wl,--wrap,fim_checker \ - -Wl,--wrap,lstat -Wl,--wrap,fim_db_file_pattern_search \ - -Wl,--wrap,fim_configuration_directory -Wl,--wrap,inotify_rm_watch -Wl,--wrap,os_random \ - -Wl,--wrap,stat -Wl,--wrap,getpid -Wl,--wrap,gettime \ - -Wl,--wrap,remove_audit_rule_syscheck -Wl,--wrap,realtime_process -Wl,--wrap,FOREVER \ - -Wl,--wrap,select -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap=fim_db_init,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - -Wl,--wrap=fim_generate_delete_event ${DEBUG_OP_WRAPPERS}") - -list(APPEND syscheckd_tests_names "run_check") -if(${TARGET} STREQUAL "agent") - list(APPEND syscheckd_tests_flags "${RUN_CHECK_BASE_FLAGS} -Wl,--wrap=sleep -Wl,--wrap,time") -elseif(${TARGET} STREQUAL "winagent") - list(APPEND syscheckd_tests_flags "${RUN_CHECK_BASE_FLAGS} -Wl,--wrap=realtime_start \ - -Wl,--wrap,WaitForSingleObjectEx -Wl,--wrap,pthread_rwlock_rdlock \ - -Wl,--wrap,pthread_rwlock_unlock -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,fim_sync_push_msg -Wl,--wrap=fim_db_get_count_registry_data \ - -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") - - # Create event channel tests for run_check - list(APPEND syscheckd_event_tests_names "test_run_check_event") - list(APPEND syscheckd_event_tests_flags "${RUN_CHECK_BASE_FLAGS} -Wl,--wrap=realtime_start,--wrap=run_whodata_scan \ - -Wl,--wrap=audit_restore - -Wl,--wrap,pthread_rwlock_rdlock \ - -Wl,--wrap,pthread_rwlock_unlock \ - -Wl,--wrap,pthread_mutex_lock \ - -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap,fim_sync_push_msg \ - -Wl,--wrap=fim_db_get_count_registry_data \ - -Wl,--wrap=fim_db_get_count_registry_key \ - -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=fim_generate_delete_event \ - -Wl,--wrap=is_fim_shutdown \ - -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize \ - -Wl,--wrap=fim_db_teardown") -else() - list(APPEND syscheckd_tests_flags "${RUN_CHECK_BASE_FLAGS} -Wl,--wrap=sleep,--wrap,time") -endif() - -# Compiling tests -list(LENGTH syscheckd_tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET syscheckd_tests_names ${counter} test_name) - list(GET syscheckd_tests_flags ${counter} test_flags) - - add_executable(test_${test_name} test_${test_name}.c) - target_link_libraries( - test_${test_name} - SYSCHECK_O - ${TEST_DEPS} - ) - - if(${TARGET} STREQUAL "winagent") - target_link_libraries(test_${test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - test_${test_name} - ${test_flags} - ) - endif() - add_test(NAME test_${test_name} COMMAND test_${test_name}) -endforeach() - -if(${TARGET} STREQUAL "winagent") - # Compile event channel tests - list(LENGTH syscheckd_event_tests_names count) - math(EXPR count "${count} - 1") - foreach(counter RANGE ${count}) - list(GET syscheckd_event_tests_names ${counter} test_name) - list(GET syscheckd_event_tests_flags ${counter} test_flags) - - string(REPLACE "_event" ".c" test_file ${test_name}) - add_executable(${test_name} ${test_file}) - - target_link_libraries( - ${test_name} - SYSCHECK_EVENT_O - ${TEST_EVENT_DEPS} - fimdb - ) - - target_compile_definitions(${test_name} PUBLIC WIN_WHODATA) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) - endforeach() -endif() - -# create_db.c tests -add_executable(test_create_db test_create_db.c) - -target_compile_options(test_create_db PRIVATE "-Wall") - -set(CREATE_DB_BASE_FLAGS "-Wl,--wrap,fim_send_scan_info -Wl,--wrap,send_syscheck_msg \ - -Wl,--wrap,readdir -Wl,--wrap,opendir -Wl,--wrap,closedir -Wl,--wrap,realtime_adddir \ - -Wl,--wrap,HasFilesystem -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap,delete_target_file -Wl,--wrap,OS_MD5_SHA1_SHA256_File \ - -Wl,--wrap,seechanges_addfile -Wl,--wrap,fim_db_delete_not_scanned \ - -Wl,--wrap,get_group,--wrap,mdebug2 -Wl,--wrap,wfopen \ - -Wl,--wrap,send_log_msg -Wl,--wrap,IsDir \ - -Wl,--wrap,DirSize -Wl,--wrap,seechanges_get_diff_path -Wl,--wrap,stat \ - -Wl,--wrap,fim_file_diff -Wl,--wrap,fim_diff_process_delete_file \ - -Wl,--wrap,fim_db_get_count_entries \ - -Wl,--wrap,fim_db_file_is_scanned -Wl,--wrap,fim_db_data_exists \ - -Wl,--wrap,fim_db_append_paths_from_inode -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,pthread_rwlock_unlock -Wl,--wrap,pthread_rwlock_rdlock \ - -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap,expand_wildcards -Wl,--wrap,fim_add_inotify_watch \ - -Wl,--wrap,realtime_sanitize_watch_map,--wrap=fim_db_remove_path \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_init \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - ${DEBUG_OP_WRAPPERS}") - -target_link_libraries(test_create_db SYSCHECK_O ${TEST_DEPS} fim_shared) -if(${TARGET} STREQUAL "winagent") - target_link_libraries(test_create_db "${CREATE_DB_BASE_FLAGS} -Wl,--wrap=w_get_file_permissions - -Wl,--wrap,getpid -Wl,--wrap=fim_db_get_count_registry_data \ - -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=decode_win_acl_json,--wrap=w_get_file_attrs -Wl,--wrap=os_winreg_check \ - -Wl,--wrap,get_file_user -Wl,--wrap,fim_registry_scan \ - -Wl,--wrap,get_UTC_modification_time -Wl,--wrap,fim_sync_push_msg \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown" - fimdb) -else() - target_link_libraries(test_create_db "${CREATE_DB_BASE_FLAGS} -Wl,--wrap=lstat -Wl,--wrap=count_watches \ - -Wl,--wrap,get_user -Wl,--wrap,realpath -Wl,--wrap,add_whodata_directory \ - -Wl,--wrap,atexit -Wl,--wrap,remove_audit_rule_syscheck") -endif() - -add_test(NAME test_create_db COMMAND test_create_db) diff --git a/src/unit_tests/syscheckd/expect_fim_diff_changes.c b/src/unit_tests/syscheckd/expect_fim_diff_changes.c deleted file mode 100644 index 1fc42120dba..00000000000 --- a/src/unit_tests/syscheckd/expect_fim_diff_changes.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "test_fim.h" - -void expect_fim_diff_delete_compress_folder(struct dirent *dir) { - expect_any(__wrap_IsDir, file); - will_return(__wrap_IsDir, 0); - - expect_any(__wrap_DirSize, path); - will_return(__wrap_DirSize, 0); - - expect_any(__wrap_rmdir_ex, name); - will_return(__wrap_rmdir_ex, 0); - expect_any(__wrap__mdebug2, formatted_msg); - - will_return(__wrap_opendir, 1); - will_return(__wrap_readdir, dir); - will_return(__wrap_readdir, NULL); -} diff --git a/src/unit_tests/syscheckd/expect_run_check.c b/src/unit_tests/syscheckd/expect_run_check.c deleted file mode 100644 index ee2b66075f2..00000000000 --- a/src/unit_tests/syscheckd/expect_run_check.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "test_fim.h" - -void expect_fim_send_msg(char mq, const char *location, const char *msg, int retval) { - if (msg == NULL) { - expect_any(__wrap_SendMSG, message); - } else { - expect_string(__wrap_SendMSG, message, msg); - } - expect_string(__wrap_SendMSG, locmsg, location); - expect_value(__wrap_SendMSG, loc, mq); - will_return(__wrap_SendMSG, retval); -} - -void expect_send_syscheck_msg(const char *msg) { - expect_any(__wrap__mdebug2, formatted_msg); - - expect_fim_send_msg(SYSCHECK_MQ, SYSCHECK, msg, 0); -} diff --git a/src/unit_tests/syscheckd/registry/CMakeLists.txt b/src/unit_tests/syscheckd/registry/CMakeLists.txt deleted file mode 100644 index 3a82a4cb071..00000000000 --- a/src/unit_tests/syscheckd/registry/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -include_directories(${SRC_FOLDER}/syscheckd/src) -include_directories(${SRC_FOLDER}/syscheckd/include) - -link_directories(${SRC_FOLDER}/unit_tests/wrappers/syscheckd/registry) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -# registry.c tests -add_executable(test_registry test_registry.c) - -target_compile_options(test_registry PRIVATE "-Wall") -target_compile_options(test_registry PRIVATE "-g") - -target_link_libraries(test_registry SYSCHECK_O ${TEST_DEPS} fim_shared) -target_link_libraries(test_registry "${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap=send_syscheck_msg -Wl,--wrap=os_random -Wl,--wrap,getpid \ - -Wl,--wrap=fim_registry_value_diff -Wl,--wrap=get_registry_permissions \ - -Wl,--wrap=decode_win_acl_json -Wl,--wrap=pthread_mutex_lock -Wl,--wrap=pthread_mutex_unlock \ - -Wl,--wrap,fim_db_init -Wl,--wrap=fim_sync_push_msg -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=fim_db_get_count_registry_data -Wl,--wrap=fim_db_get_count_registry_key \ - -Wl,--wrap=fim_db_file_pattern_search -Wl,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update -Wl,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") - -if(${TARGET} STREQUAL "winagent") - target_link_libraries(test_registry fimdb) -endif(${TARGET} STREQUAL "winagent") - -add_test(NAME test_registry COMMAND test_registry) - -# events.c tests -add_executable(test_events test_events.c) - -target_compile_options(test_events PRIVATE "-Wall") - -target_link_libraries(test_events SYSCHECK_O ${TEST_DEPS} fim_shared) -target_link_libraries(test_events "${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows -Wl,--wrap=fim_run_integrity \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_db_transaction_start -Wl,--wrap,fim_db_init \ - -Wl,--wrap=fim_db_get_count_registry_data -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=fim_db_file_update -Wl,--wrap,fim_db_get_path -Wl,--wrap=fim_db_file_pattern_search -Wl,--wrap=fim_db_remove_path \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown") - -if(${TARGET} STREQUAL "winagent") - target_link_libraries(test_events fimdb) -endif(${TARGET} STREQUAL "winagent") - -add_test(NAME test_events COMMAND test_events) diff --git a/src/unit_tests/syscheckd/registry/test_events.c b/src/unit_tests/syscheckd/registry/test_events.c deleted file mode 100644 index 3571ff00ec1..00000000000 --- a/src/unit_tests/syscheckd/registry/test_events.c +++ /dev/null @@ -1,528 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include "../../../syscheckd/include/syscheck.h" -#include "../../../syscheckd/src/registry/registry.h" -#include "test_fim.h" - -#define CHECK_REGISTRY_ALL \ - CHECK_SIZE | CHECK_PERM | CHECK_OWNER | CHECK_GROUP | CHECK_MTIME | CHECK_MD5SUM | CHECK_SHA1SUM | \ - CHECK_SHA256SUM | CHECK_SEECHANGES | CHECK_TYPE - -fim_registry_key DEFAULT_REGISTRY_KEY = { .id = 3, .path = "HKEY_USERS\\Some\\random\\key", .perm_json = NULL, .perm = "", .uid = "110", .gid = "220", .user_name = "user_old_name", .group_name = "group_old_name", .mtime = 1100, .arch = ARCH_64BIT, .scanned = 0, .last_event = 1234, .checksum = "234567890ABCDEF1234567890ABCDEF123456789", .hash_full_path = "234567890ABCDEF1234567890ABCDEF123456111"}; -fim_registry_value_data DEFAULT_REGISTRY_VALUE = { .id = 3, .path = "key\\path", .hash_full_path = "234567890ABCDEF1234567890ABCDEF123456111", .arch = ARCH_64BIT, .name = "the\\value", .type = REG_SZ, .size = 50, .hash_md5 = "1234567890ABCDEF1234567890ABCDEF", . hash_sha1 = "1234567890ABCDEF1234567890ABCDEF12345678", .hash_sha256 = "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF", .scanned = 0, .last_event = 10000, .checksum = "1234567890ABCDEF1234567890ABCDEF12345678", .mode = FIM_MODIFICATION }; -typedef struct fim_key_txn_context_s { - event_data_t *evt_data; - fim_registry_key *key; -} fim_key_txn_context_t; - -typedef struct fim_val_txn_context_s { - event_data_t *evt_data; - fim_registry_value_data *data; - char* diff; -} fim_val_txn_context_t; - -typedef struct key_difference_s { - cJSON *old_data; - cJSON *changed_attributes; - cJSON *old_attributes; -} key_difference_t; - -typedef struct json_data_s { - cJSON *data1; - cJSON *data2; -} json_data_t; - -static int setup_dbsync_difference(void **state) { - key_difference_t *data = calloc(1, sizeof(key_difference_t)); - if (data == NULL) { - return 1; - } - - data->old_data = cJSON_CreateObject(); - - if (data->old_data == NULL) { - return 1; - } - - data->changed_attributes = cJSON_CreateArray(); - if (data->changed_attributes == NULL) { - return 1; - } - - data->old_attributes = cJSON_CreateObject(); - if (data->old_attributes == NULL) { - return 1; - } - *state = data; - return 0; -} - -static int teardown_dbsync_difference(void **state) { - key_difference_t * data = (key_difference_t*) *state; - - cJSON_Delete(data->changed_attributes); - cJSON_Delete(data->old_attributes); - cJSON_Delete(data->old_data); - - free(data); - return 0; -} - -static int teardown_cjson_object(void **state) { - cJSON *object = *state; - - cJSON_Delete(object); - - return 0; -} - -static int teardown_cjson_data(void **state) { - json_data_t *data = *state; - - cJSON_Delete(data->data2); - free(data); - - return 0; -} - -cJSON* fim_dbsync_registry_value_json_event(const cJSON* dbsync_event, - const fim_registry_value_data *value, - const registry_t *configuration, - fim_event_mode mode, - const event_data_t *evt_data, - __attribute__((unused)) whodata_evt *w_evt, - const char* diff); -cJSON* fim_registry_compare_key_attrs(const fim_registry_key *new_data, - const fim_registry_key *old_data, - const registry_t *configuration); -cJSON* fim_registry_compare_value_attrs(const fim_registry_value_data *new_data, - const fim_registry_value_data *old_data, - const registry_t *configuration); - - - -static void test_fim_registry_compare_key_attrs(void **state){ - cJSON *permissions = create_win_permissions_object(); - fim_registry_key new_key = { .id = 3, - .path = "HKEY_USERS\\Some\\random\\key", - .perm_json = permissions, - .perm = cJSON_PrintUnformatted(permissions), - .uid = "100", - .gid = "200", - .user_name = "user_name", - .group_name = "group_name", - .mtime = 1000, - .arch = ARCH_64BIT, - .scanned = 0, - .last_event = 1234, - .checksum = "1234567890ABCDEF1234567890ABCDEF12345678" }; - cJSON *saved_permissions = cJSON_CreateObject(); - fim_registry_key saved_key = { .id = 3, - .path = "HKEY_USERS\\Some\\random\\key", - .perm_json = saved_permissions, - .perm = cJSON_PrintUnformatted(saved_permissions), - .uid = "110", - .gid = "220", - .user_name = "user_old_name", - .group_name = "group_old_name", - .mtime = 1100, - .arch = ARCH_64BIT, - .scanned = 0, - .last_event = 1234, - .checksum = "234567890ABCDEF1234567890ABCDEF123456789" }; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *ret, *it; - char *changed_attributes[] = { "permission", "uid", "user_name", "gid", "group_name", "mtime" }; - int attributes_it = 0; - - - ret = fim_registry_compare_key_attrs(&new_key, &saved_key, &configuration); - - *state = ret; - - cJSON_ArrayForEach(it, ret) { - assert_string_equal(cJSON_GetStringValue(it), changed_attributes[attributes_it++]); - } - - free(new_key.perm); - free(saved_key.perm); - cJSON_Delete(permissions); - cJSON_Delete(saved_permissions); -} - -static void test_fim_registry_compare_value_attrs(void **state){ - fim_registry_value_data new_value = { 3, - "key\\path", - "234567890ABCDEF1234567890ABCDEF123456111", - ARCH_64BIT, - "the\\value", - REG_SZ, - 50, - "1234567890ABCDEF1234567890ABCDEF", - "1234567890ABCDEF1234567890ABCDEF12345678", - "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF", - 0, - 10000, - "1234567890ABCDEF1234567890ABCDEF12345678", - FIM_MODIFICATION }; - - fim_registry_value_data saved_value = { 3, - "key\\path", - "234567890ABCDEF1234567890ABCDEF123456111", - ARCH_64BIT, - "the\\value", - REG_DWORD, - 49, - "234567890ABCDEF1234567890ABCDEF1", - "234567890ABCDEF1234567890ABCDEF123456789", - "234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1", - 0, - 11000, - "234567890ABCDEF1234567890ABCDEF123456789", - FIM_MODIFICATION }; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *ret, *it; - char *changed_attributes[] = { "size", "type", "md5", "sha1", "sha256", "last_event", "checksum" }; - int attributes_it = 0; - - ret = fim_registry_compare_value_attrs(&new_value, &saved_value, &configuration); - - *state = ret; - - cJSON_ArrayForEach(it, ret) { - assert_string_equal(cJSON_GetStringValue(it), changed_attributes[attributes_it++]); - } -} - -void test_calculate_dbsync_difference_key_perm_change(void **state) { - - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - const char* old_entry_str = "{\"type\":\"registry_key\",\"perm\":{\"S-1-5-32-545\":{\"name\":\"Users\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]},\"S-1-5-32-544\":{\"name\":\"Administrators\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-5-18\":{\"name\":\"SYSTEM\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-3-0\":{\"name\":\"CREATOR OWNER\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-15-2-1\":{\"name\":\"ALL APPLICATION PACKAGES\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]}},\"uid\":\"110\",\"user_name\":\"user_old_name\",\"gid\":\"110\",\"group_name\":\"group_old_name\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - char *perm_string = "{\"S-1-5-32-545\":{\"name\":\"Users\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]},\"S-1-5-32-544\":{\"name\":\"Administrators\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-5-18\":{\"name\":\"SYSTEM\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-3-0\":{\"name\":\"CREATOR OWNER\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-15-2-1\":{\"name\":\"ALL APPLICATION PACKAGES\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]}}"; - cJSON_AddItemToObject(old_data, "perm", cJSON_CreateString(perm_string)); - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"permission\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_entry_str); -} - -void test_calculate_dbsync_difference_key_no_change(void **state) { - - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[]"); -} - -void test_calculate_dbsync_difference_key_uid_change(void **state) { - - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - const char *old_attributes_str = "{\"type\":\"registry_key\",\"uid\":\"210\",\"user_name\":\"user_old_name\",\"gid\":\"110\",\"group_name\":\"group_old_name\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddStringToObject(old_data, "uid", "210"); - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"uid\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_key_username_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - const char* old_attributes_str = "{\"type\":\"registry_key\",\"uid\":\"110\",\"user_name\":\"previous_username\",\"gid\":\"110\",\"group_name\":\"group_old_name\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddStringToObject(old_data, "user_name", "previous_username"); - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"user_name\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_key_username_no_change_empty(void **state) { - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - cJSON_AddStringToObject(old_data, "user_name", ""); - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[]"); -} - - -void test_calculate_dbsync_difference_key_gid_change(void **state) { - - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - const char *old_attributes_str = "{\"type\":\"registry_key\",\"uid\":\"110\",\"user_name\":\"user_old_name\",\"gid\":\"210\",\"group_name\":\"group_old_name\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddStringToObject(old_data, "gid", "210"); - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"gid\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_key_groupname_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - const char* old_attributes_str = "{\"type\":\"registry_key\",\"uid\":\"110\",\"user_name\":\"user_old_name\",\"gid\":\"110\",\"group_name\":\"previous_groupname\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddStringToObject(old_data, "group_name", "previous_groupname"); - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"group_name\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_key_mtime_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - const char* old_attributes_str = "{\"type\":\"registry_key\",\"uid\":\"110\",\"user_name\":\"user_old_name\",\"gid\":\"110\",\"group_name\":\"group_old_name\",\"mtime\":98765432,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddNumberToObject(old_data, "mtime", 98765432); - - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - fim_calculate_dbsync_difference_key(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"mtime\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_value_size_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - const char *old_attributes_str = "{\"type\":\"registry_value\",\"size\":98765432,\"value_type\":\"REG_SZ\",\"hash_md5\":\"1234567890ABCDEF1234567890ABCDEF\",\"hash_sha1\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_sha256\":\"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF\"}"; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddNumberToObject(old_data, "size", 98765432); - - fim_registry_value_data registry_data = DEFAULT_REGISTRY_VALUE; - - fim_calculate_dbsync_difference_value(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"size\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); - -} - -void test_calculate_dbsync_difference_value_type_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - const char *old_attributes_str = "{\"type\":\"registry_value\",\"size\":50,\"value_type\":\"REG_EXPAND_SZ\",\"hash_md5\":\"1234567890ABCDEF1234567890ABCDEF\",\"hash_sha1\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_sha256\":\"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF\"}"; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddNumberToObject(old_data, "value_type", 2); - fim_registry_value_data registry_data = DEFAULT_REGISTRY_VALUE; - - fim_calculate_dbsync_difference_value(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"value_type\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_value_md5_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - const char *old_attributes_str = "{\"type\":\"registry_value\",\"size\":50,\"value_type\":\"REG_SZ\",\"hash_md5\":\"FEDCBA0987654321FEDCBA0987654321\",\"hash_sha1\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_sha256\":\"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF\"}"; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddStringToObject(old_data, "hash_md5", "FEDCBA0987654321FEDCBA0987654321"); - - fim_registry_value_data registry_data = DEFAULT_REGISTRY_VALUE; - - fim_calculate_dbsync_difference_value(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"md5\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_value_sha1_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - const char *old_attributes_str = "{\"type\":\"registry_value\",\"size\":50,\"value_type\":\"REG_SZ\",\"hash_md5\":\"1234567890ABCDEF1234567890ABCDEF\",\"hash_sha1\":\"FEDCBA0987654321FEDCBA0987654321FEDCBA09\",\"hash_sha256\":\"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF\"}"; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddStringToObject(old_data, "hash_sha1", "FEDCBA0987654321FEDCBA0987654321FEDCBA09"); - - fim_registry_value_data registry_data = DEFAULT_REGISTRY_VALUE; - - fim_calculate_dbsync_difference_value(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"sha1\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - - -void test_calculate_dbsync_difference_value_sha256_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - const char *old_attributes_str = "{\"type\":\"registry_value\",\"size\":50,\"value_type\":\"REG_SZ\",\"hash_md5\":\"1234567890ABCDEF1234567890ABCDEF\",\"hash_sha1\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_sha256\":\"FEDCBA0987654321FEDCBA0987654321FEDCBA0987654321FEDCBA0987654321\"}"; - - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - cJSON_AddStringToObject(old_data, "hash_sha256", "FEDCBA0987654321FEDCBA0987654321FEDCBA0987654321FEDCBA0987654321"); - - fim_registry_value_data registry_data = DEFAULT_REGISTRY_VALUE; - - fim_calculate_dbsync_difference_value(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[\"sha256\"]"); - assert_string_equal(cJSON_PrintUnformatted(old_attributes), old_attributes_str); -} - -void test_calculate_dbsync_difference_value_no_change(void **state) { - key_difference_t *data = (key_difference_t *) *state; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - cJSON *old_data = data->old_data; - cJSON *changed_attributes = data->changed_attributes; - cJSON *old_attributes = data->old_attributes; - - fim_registry_value_data registry_data = DEFAULT_REGISTRY_VALUE; - - fim_calculate_dbsync_difference_value(®istry_data, &configuration, old_data, changed_attributes, old_attributes); - assert_string_equal(cJSON_PrintUnformatted(changed_attributes), "[]"); -} - -void test_registry_key_attributes_json_entry(void **state) { - json_data_t *data = calloc(1, sizeof(json_data_t)); - char perm_data[OS_MAXSTR] = "{\"S-1-5-32-545\":{\"name\":\"Users\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]},\"S-1-5-32-544\":{\"name\":\"Administrators\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-5-18\":{\"name\":\"SYSTEM\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-3-0\":{\"name\":\"CREATOR OWNER\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-15-2-1\":{\"name\":\"ALL APPLICATION PACKAGES\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]}}"; - - const char* event_str = "{\"type\":\"registry_key\",\"perm\":{\"S-1-5-32-545\":{\"name\":\"Users\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]},\"S-1-5-32-544\":{\"name\":\"Administrators\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-5-18\":{\"name\":\"SYSTEM\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-3-0\":{\"name\":\"CREATOR OWNER\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-15-2-1\":{\"name\":\"ALL APPLICATION PACKAGES\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]}},\"uid\":\"110\",\"user_name\":\"user_old_name\",\"gid\":\"220\",\"group_name\":\"group_old_name\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - fim_registry_key registry_data = DEFAULT_REGISTRY_KEY; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - - registry_data.perm = perm_data; - - cJSON *event = fim_registry_key_attributes_json(NULL, ®istry_data, &configuration); - - data->data2 = event; - *state = data; - - assert_string_equal(event_str, cJSON_PrintUnformatted(event)); -} - -void test_registry_key_attributes_json_dbsync(void **state) { - json_data_t *data = calloc(1, sizeof(json_data_t)); - cJSON *dbsync_event = cJSON_Parse("{\"perm\":\"{\\\"S-1-5-32-545\\\":{\\\"name\\\":\\\"Users\\\",\\\"allowed\\\":[\\\"read_control\\\",\\\"read_data\\\",\\\"read_ea\\\",\\\"write_ea\\\"]},\\\"S-1-5-32-544\\\":{\\\"name\\\":\\\"Administrators\\\",\\\"allowed\\\":[\\\"delete\\\",\\\"read_control\\\",\\\"write_dac\\\",\\\"write_owner\\\",\\\"read_data\\\",\\\"write_data\\\",\\\"append_data\\\",\\\"read_ea\\\",\\\"write_ea\\\",\\\"execute\\\"]},\\\"S-1-5-18\\\":{\\\"name\\\":\\\"SYSTEM\\\",\\\"allowed\\\":[\\\"delete\\\",\\\"read_control\\\",\\\"write_dac\\\",\\\"write_owner\\\",\\\"read_data\\\",\\\"write_data\\\",\\\"append_data\\\",\\\"read_ea\\\",\\\"write_ea\\\",\\\"execute\\\"]},\\\"S-1-3-0\\\":{\\\"name\\\":\\\"CREATOR OWNER\\\",\\\"allowed\\\":[\\\"delete\\\",\\\"read_control\\\",\\\"write_dac\\\",\\\"write_owner\\\",\\\"read_data\\\",\\\"write_data\\\",\\\"append_data\\\",\\\"read_ea\\\",\\\"write_ea\\\",\\\"execute\\\"]},\\\"S-1-15-2-1\\\":{\\\"name\\\":\\\"ALL APPLICATION PACKAGES\\\",\\\"allowed\\\":[\\\"read_control\\\",\\\"read_data\\\",\\\"read_ea\\\",\\\"write_ea\\\"]}}\",\"uid\":\"110\",\"user_name\":\"user_old_name\",\"gid\":\"220\",\"group_name\":\"group_old_name\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"); - const char* event_str = "{\"type\":\"registry_key\",\"perm\":{\"S-1-5-32-545\":{\"name\":\"Users\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]},\"S-1-5-32-544\":{\"name\":\"Administrators\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-5-18\":{\"name\":\"SYSTEM\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-3-0\":{\"name\":\"CREATOR OWNER\",\"allowed\":[\"delete\",\"read_control\",\"write_dac\",\"write_owner\",\"read_data\",\"write_data\",\"append_data\",\"read_ea\",\"write_ea\",\"execute\"]},\"S-1-15-2-1\":{\"name\":\"ALL APPLICATION PACKAGES\",\"allowed\":[\"read_control\",\"read_data\",\"read_ea\",\"write_ea\"]}},\"uid\":\"110\",\"user_name\":\"user_old_name\",\"gid\":\"220\",\"group_name\":\"group_old_name\",\"mtime\":1100,\"checksum\":\"234567890ABCDEF1234567890ABCDEF123456789\"}"; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - - cJSON *event = fim_registry_key_attributes_json(dbsync_event, NULL, &configuration); - - data->data1 = dbsync_event; - data->data2 = event; - *state = data; - assert_string_equal(event_str, cJSON_PrintUnformatted(event)); -} - - -void test_registry_value_attributes_json_entry(void **state) { - json_data_t *data = calloc(1, sizeof(json_data_t)); - const char* event_str = "{\"type\":\"registry_value\",\"value_type\":\"REG_SZ\",\"size\":50,\"hash_md5\":\"1234567890ABCDEF1234567890ABCDEF\",\"hash_sha1\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_sha256\":\"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF\",\"checksum\":\"1234567890ABCDEF1234567890ABCDEF12345678\"}"; - fim_registry_value_data registry_data = DEFAULT_REGISTRY_VALUE; - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - - cJSON *event = fim_registry_value_attributes_json(NULL, ®istry_data, &configuration); - - data->data1 = event; - *state = data; - - assert_string_equal(event_str, cJSON_PrintUnformatted(event)); -} - -void test_registry_value_attributes_json_dbsync(void **state) { - json_data_t *data = calloc(1, sizeof(json_data_t)); - const char* event_str = "{\"type\":\"registry_value\",\"value_type\":\"REG_SZ\",\"size\":50,\"hash_md5\":\"1234567890ABCDEF1234567890ABCDEF\",\"hash_sha1\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_sha256\":\"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF\",\"checksum\":\"1234567890ABCDEF1234567890ABCDEF12345678\"}"; - cJSON *dbsync_event = cJSON_Parse("{\"arch\":\"[x64]\",\"checksum\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_md5\":\"1234567890ABCDEF1234567890ABCDEF\",\"hash_sha1\":\"1234567890ABCDEF1234567890ABCDEF12345678\",\"hash_sha256\":\"1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF\",\"last_event\":1645700674,\"name\":\"New Value 1\",\"path\":\"HKEY_USERS\\\\Some\",\"scanned\":0,\"size\":50,\"type\":1}"); - registry_t configuration = { "HKEY_USERS\\Some", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL }; - - - cJSON *event = fim_registry_value_attributes_json(dbsync_event, NULL, &configuration); - data->data1 = dbsync_event; - data->data2 = event; - *state = data; - - assert_string_equal(event_str, cJSON_PrintUnformatted(event)); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - // tests registry key transaction callback - cmocka_unit_test_teardown(test_fim_registry_compare_key_attrs, teardown_cjson_object), - cmocka_unit_test_teardown(test_fim_registry_compare_value_attrs, teardown_cjson_object), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_perm_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_no_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_uid_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_username_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_username_no_change_empty, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_gid_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_groupname_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_key_mtime_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_value_size_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_value_type_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_value_md5_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_value_sha1_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_value_sha256_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_setup_teardown(test_calculate_dbsync_difference_value_no_change, setup_dbsync_difference, teardown_dbsync_difference), - cmocka_unit_test_teardown(test_registry_key_attributes_json_entry, teardown_cjson_data), - cmocka_unit_test_teardown(test_registry_key_attributes_json_dbsync, teardown_cjson_data), - cmocka_unit_test_teardown(test_registry_value_attributes_json_entry, teardown_cjson_data), - cmocka_unit_test_teardown(test_registry_value_attributes_json_dbsync, teardown_cjson_data), - - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/syscheckd/registry/test_registry.c b/src/unit_tests/syscheckd/registry/test_registry.c deleted file mode 100644 index 8be5c707b7f..00000000000 --- a/src/unit_tests/syscheckd/registry/test_registry.c +++ /dev/null @@ -1,1190 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "syscheck.h" -#include "registry/registry.h" -#include "registry/registry.c" - -#include "../../wrappers/common.h" -#include "../../wrappers/windows/sddl_wrappers.h" -#include "../../wrappers/windows/aclapi_wrappers.h" -#include "../../wrappers/windows/winreg_wrappers.h" -#include "../../wrappers/windows/winbase_wrappers.h" -#include "../../wrappers/windows/securitybaseapi_wrappers.h" -#include "../../wrappers/wazuh/syscheckd/fim_db_wrappers.h" -#include "../../wrappers/wazuh/shared/syscheck_op_wrappers.h" -#include "../../wrappers/wazuh/syscheckd/fim_diff_changes_wrappers.h" - -#include "test_fim.h" - -#define CHECK_REGISTRY_ALL \ - CHECK_SIZE | CHECK_PERM | CHECK_OWNER | CHECK_GROUP | CHECK_MTIME | CHECK_MD5SUM | CHECK_SHA1SUM | \ - CHECK_SHA256SUM | CHECK_SEECHANGES | CHECK_TYPE - -char inv_hKey[50]; - -static registry_t default_config[] = { - { "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { "HKEY_LOCAL_MACHINE\\Software\\RecursionLevel0", ARCH_64BIT, CHECK_REGISTRY_ALL, 0, 0, NULL, NULL, NULL }, - { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { inv_hKey, ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { "HKEY_LOCAL_MACHINE\\Software\\FailToInsert", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { NULL, 0, 0, 320, 0, NULL, NULL, NULL } -}; - -static registry_t one_entry_config[] = { - { "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { NULL, 0, 0, 320, 0, NULL, NULL, NULL } -}; - -static registry_ignore default_ignore[] = { { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_32BIT}, - { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_64BIT}, - { NULL, 0} }; - -static char *default_ignore_regex_patterns[] = { "IgnoreRegex", "IgnoreRegex", NULL }; - -static registry_ignore_regex default_ignore_regex[] = { { NULL, ARCH_32BIT }, { NULL, ARCH_64BIT }, { NULL, 0 } }; - -extern int _base_line; - -typedef struct tmp_file_entry_s { - fim_tmp_file *file; - fim_entry *entry; -} tmp_file_entry_t; - -void registry_key_transaction_callback(ReturnTypeCallback resultType, const cJSON* result_json, void* user_data); -void registry_value_transaction_callback(ReturnTypeCallback resultType, const cJSON* result_json, void* user_data); -int fim_set_root_key(HKEY *root_key_handle, const char *full_key, const char **sub_key); -registry_t *fim_registry_configuration(const char *key, int arch); -int fim_registry_validate_recursion_level(const char *key_path, const registry_t *configuration); -int fim_registry_validate_ignore(const char *entry, const registry_t *configuration, int key); -void fim_registry_free_entry(fim_entry *entry); -void fim_registry_free_key(fim_registry_key *key); -void fim_registry_free_value_data(fim_registry_value_data *data); -fim_registry_key *fim_registry_get_key_data(HKEY key_handle, const char *path, const registry_t *configuration); -void fim_registry_calculate_hashes(fim_entry *entry, registry_t *configuration, BYTE *data_buffer); -void expect_SendMSG_call(const char *message_expected, const char *locmsg_expected, char loc_expected, int ret){ - expect_string(__wrap_SendMSG, message, message_expected); - expect_string(__wrap_SendMSG, locmsg, locmsg_expected); - expect_value(__wrap_SendMSG, loc, loc_expected); - will_return(__wrap_SendMSG, ret); -} - -void expect_fim_registry_get_key_data_call(LPSTR usid, - LPSTR gsid, - char *uname, - char *gname, - const char *permissions, - FILETIME last_write_time) { - expect_GetSecurityInfo_call((PSID) "userid", NULL, ERROR_SUCCESS); - expect_ConvertSidToStringSid_call(usid, 1); - expect_LookupAccountSid_call((PSID)uname, "domain", 1); - - expect_GetSecurityInfo_call(NULL, (PSID) "groupid", ERROR_SUCCESS); - expect_ConvertSidToStringSid_call(gsid, 1); - expect_LookupAccountSid_call((PSID)gname, "domain", 1); - - expect_get_registry_permissions(create_win_permissions_object(), ERROR_SUCCESS); - - expect_any(__wrap_decode_win_acl_json, perms); - - expect_RegQueryInfoKeyA_call(&last_write_time, ERROR_SUCCESS); -} - -fim_registry_key *create_reg_key(int id, const char *path, int arch, const char *perm, const char *uid, const char *gid, const char *user_name, - const char *group_name) { - fim_registry_key *ret; - - os_calloc(1, sizeof(fim_registry_key), ret); - - ret->id = id; - os_strdup(path, ret->path); - ret->arch = arch; - os_strdup(perm, ret->perm); - os_strdup(uid, ret->uid); - os_strdup(gid, ret->gid); - os_strdup(user_name, ret->user_name); - os_strdup(group_name, ret->group_name); - - return ret; -} - -fim_registry_value_data *create_reg_value_data(int id, char *name, unsigned int type, unsigned int size) { - fim_registry_value_data *ret; - - os_calloc(1, sizeof(fim_registry_value_data), ret); - - ret->id = id; - os_strdup(name, ret->name); - ret->type = type; - ret->size = size; - - return ret; -} - -int delete_tables(){ - char *err_msg = NULL; - // DELETE TABLES - sqlite3_exec(syscheck.database->db, "DELETE FROM registry_data;", NULL, NULL, &err_msg); - if (err_msg) { - fail_msg("%s", err_msg); - sqlite3_free(err_msg); - - return -1; - } - sqlite3_exec(syscheck.database->db, "DELETE FROM registry_key;", NULL, NULL, &err_msg); - if (err_msg) { - fail_msg("%s", err_msg); - sqlite3_free(err_msg); - - return -1; - } - return 0; -} - -static int setup_group(void **state) { - int i; - time_mock_value = 9999999; - strcpy(inv_hKey, "HKEY_LOCAL_MACHINE_Invalid_key\\Software\\Ignore"); - - syscheck.registry = default_config; - syscheck.key_ignore = default_ignore; - - for (i = 0; default_ignore_regex_patterns[i]; i++) { - default_ignore_regex[i].regex = calloc(1, sizeof(OSMatch)); - - if (default_ignore_regex[i].regex == NULL) { - return -1; - } - - if (!OSMatch_Compile(default_ignore_regex_patterns[i], default_ignore_regex[i].regex, 0)) { - return -1; - } - } - - syscheck.key_ignore_regex = default_ignore_regex; - - return 0; -} - -static int teardown_group(void **state) { - int i; - - syscheck.registry = NULL; - syscheck.key_ignore = NULL; - syscheck.value_ignore = NULL; - - for (i = 0; syscheck.key_ignore_regex[i].regex; i++) { - OSMatch_FreePattern(syscheck.key_ignore_regex[i].regex); - } - syscheck.key_ignore_regex = NULL; - - return 0; -} - -static int setup_test_hashes(void **state) { - syscheck.registry = default_config; - - fim_entry *entry; - os_calloc(1, sizeof(fim_entry), entry); - - fim_registry_key *key; - os_calloc(1, sizeof(fim_registry_key), key); - key->id = 3; - os_strdup("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile", key->path); - os_strdup("sid (allowed): delete|write_dac|write_data|append_data|write_attributes", key->perm); - os_strdup("100", key->uid); - os_strdup("200", key->gid); - os_strdup("username", key->user_name); - os_strdup("groupname", key->group_name); - key->arch = 1; - - fim_registry_value_data *value; - os_calloc(1, sizeof(fim_registry_value_data), value); - value->id = 3; - os_strdup("valuename", value->name); - strcpy(value->hash_md5, "1234567890ABCDEF1234567890ABCDEF"); - strcpy(value->hash_sha1, "1234567890ABCDEF1234567890ABCDEF12345678"); - strcpy(value->hash_sha256, "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF"); - strcpy(value->checksum, "1234567890ABCDEF1234567890ABCDEF12345678"); - - entry->type = FIM_TYPE_REGISTRY; - entry->registry_entry.key = key; - entry->registry_entry.value = value; - - *state = entry; - return 0; -} - -static int teardown_test_hashes(void **state) { - fim_entry *entry = *state; - - if (entry){ - fim_registry_free_key(entry->registry_entry.key); - fim_registry_free_value_data(entry->registry_entry.value); - free(entry); - } - - return 0; -} - -// TESTS - -static void test_fim_set_root_key_null_root_key(void **state) { - int ret; - char *full_key = NULL; - const char *sub_key; - - ret = fim_set_root_key(NULL, full_key, &sub_key); - - assert_int_equal(ret, -1); -} - -static void test_fim_set_root_key_null_full_key(void **state) { - int ret; - HKEY root_key; - const char *sub_key; - - ret = fim_set_root_key(&root_key, NULL, &sub_key); - - assert_int_equal(ret, -1); -} - -static void test_fim_set_root_key_null_sub_key(void **state) { - int ret; - HKEY root_key; - char *full_key = NULL; - - ret = fim_set_root_key(&root_key, full_key, NULL); - - assert_int_equal(ret, -1); -} - -static void test_fim_set_root_key_invalid_key(void **state) { - int ret; - HKEY root_key; - char *full_key = "This wont match to any root key"; - const char *sub_key; - - ret = fim_set_root_key(&root_key, full_key, &sub_key); - - assert_int_equal(ret, -1); - assert_null(root_key); -} - -static void test_fim_set_root_key_invalid_root_key(void **state) { - int ret; - HKEY root_key; - char *full_key = "HKEY_LOCAL_MACHINE_This_is_almost_valid\\but\\not\\quite\\valid"; - const char *sub_key; - - ret = fim_set_root_key(&root_key, full_key, &sub_key); - - assert_int_equal(ret, -1); - assert_null(root_key); -} - -static void test_fim_set_root_key_valid_HKEY_LOCAL_MACHINE_key(void **state) { - int ret; - HKEY root_key; - char *full_key = "HKEY_LOCAL_MACHINE\\This\\is_a_valid\\key"; - const char *sub_key; - - ret = fim_set_root_key(&root_key, full_key, &sub_key); - - assert_int_equal(ret, 0); - assert_ptr_equal(root_key, HKEY_LOCAL_MACHINE); - assert_ptr_equal(sub_key, full_key + 19); -} - -static void test_fim_set_root_key_valid_HKEY_CLASSES_ROOT_key(void **state) { - int ret; - HKEY root_key; - char *full_key = "HKEY_CLASSES_ROOT\\This\\is_a_valid\\key"; - const char *sub_key; - - ret = fim_set_root_key(&root_key, full_key, &sub_key); - - assert_int_equal(ret, 0); - assert_ptr_equal(root_key, HKEY_CLASSES_ROOT); - assert_ptr_equal(sub_key, full_key + 18); -} - -static void test_fim_set_root_key_valid_HKEY_CURRENT_CONFIG_key(void **state) { - int ret; - HKEY root_key; - char *full_key = "HKEY_CURRENT_CONFIG\\This\\is_a_valid\\key"; - const char *sub_key; - - ret = fim_set_root_key(&root_key, full_key, &sub_key); - - assert_int_equal(ret, 0); - assert_ptr_equal(root_key, HKEY_CURRENT_CONFIG); - assert_ptr_equal(sub_key, full_key + 20); -} - -static void test_fim_set_root_key_valid_HKEY_USERS_key(void **state) { - int ret; - HKEY root_key; - char *full_key = "HKEY_USERS\\This\\is_a_valid\\key"; - const char *sub_key; - - ret = fim_set_root_key(&root_key, full_key, &sub_key); - - assert_int_equal(ret, 0); - assert_ptr_equal(root_key, HKEY_USERS); - assert_ptr_equal(sub_key, full_key + 11); -} - -static void test_fim_registry_configuration_registry_found(void **state) { - registry_t *configuration; - - configuration = fim_registry_configuration("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\something", ARCH_64BIT); - assert_non_null(configuration); - assert_string_equal(configuration->entry, "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"); - assert_int_equal(configuration->arch, ARCH_64BIT); -} - -static void test_fim_registry_configuration_registry_not_found_arch_does_not_match(void **state) { - registry_t *configuration; - - expect_any_always(__wrap__mdebug2, formatted_msg); - - configuration = fim_registry_configuration("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\something", ARCH_32BIT); - assert_null(configuration); -} - -static void test_fim_registry_configuration_registry_not_found_path_does_not_match(void **state) { - registry_t *configuration; - - expect_any_always(__wrap__mdebug2, formatted_msg); - - configuration = fim_registry_configuration("HKEY_LOCAL_MACHINE\\Software\\Classes\\something", ARCH_64BIT); - assert_null(configuration); -} - -static void test_fim_registry_configuration_null_key(void **state) { - registry_t *configuration; - - expect_any_always(__wrap__mdebug2, formatted_msg); - - configuration = fim_registry_configuration(NULL, ARCH_64BIT); - assert_null(configuration); -} - -static void test_fim_registry_validate_recursion_level_null_configuration(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\something"; - int ret; - - ret = fim_registry_validate_recursion_level(path, NULL); - - assert_int_equal(ret, -1); -} - -static void test_fim_registry_validate_recursion_level_null_entry_path(void **state) { - registry_t *configuration = &syscheck.registry[0]; - int ret; - - ret = fim_registry_validate_recursion_level(NULL, configuration); - - assert_int_equal(ret, -1); -} - -static void test_fim_registry_validate_recursion_level_valid_entry_path(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\Some\\valid\\path"; - registry_t *configuration = &syscheck.registry[0]; - int ret; - - ret = fim_registry_validate_recursion_level(path, configuration); - - assert_int_equal(ret, 0); -} - -static void test_fim_registry_validate_recursion_level_invalid_recursion_level(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\RecursionLevel0\\This\\must\\fail"; - registry_t *configuration = &syscheck.registry[1]; - int ret; - expect_string(__wrap__mdebug2, formatted_msg, - "(6217): Maximum level of recursion reached. Depth:3 recursion_level:0 " - "'HKEY_LOCAL_MACHINE\\Software\\RecursionLevel0\\This\\must\\fail'"); - - ret = fim_registry_validate_recursion_level(path, configuration); - - assert_int_equal(ret, -1); -} - -static void test_fim_registry_validate_ignore_null_configuration(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\something"; - int ret; - - ret = fim_registry_validate_ignore(path, NULL, 1); - - assert_int_equal(ret, -1); -} - -static void test_fim_registry_validate_ignore_null_entry_path(void **state) { - registry_t *configuration = &syscheck.registry[0]; - int ret; - - ret = fim_registry_validate_ignore(NULL, configuration, 1); - - assert_int_equal(ret, -1); -} - -static void test_fim_registry_validate_ignore_valid_entry_path(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\Some\\valid\\path"; - registry_t *configuration = &syscheck.registry[0]; - int ret; - - ret = fim_registry_validate_ignore(path, configuration, 1); - - assert_int_equal(ret, 0); -} - -static void test_fim_registry_validate_ignore_ignore_entry(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Ignore"; - registry_t *configuration = &syscheck.registry[2]; - int ret; - - expect_string(__wrap__mdebug2, formatted_msg, - "(6260): Ignoring 'registry' '[x64] HKEY_LOCAL_MACHINE\\Software\\Ignore' due to " - "'HKEY_LOCAL_MACHINE\\Software\\Ignore'"); - - ret = fim_registry_validate_ignore(path, configuration, 1); - - assert_int_equal(ret, -1); -} - -static void test_fim_registry_validate_ignore_regex_ignore_entry(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\IgnoreRegex\\This\\must\\fail"; - registry_t *configuration = &syscheck.registry[0]; - int ret; - - expect_string(__wrap__mdebug2, formatted_msg, - "(6259): Ignoring 'registry' '[x64] " - "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\IgnoreRegex\\This\\must\\fail' due to sregex " - "'IgnoreRegex'"); - - ret = fim_registry_validate_ignore(path, configuration, 1); - - assert_int_equal(ret, -1); -} - -static void test_fim_registry_get_key_data_check_owner(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_OWNER; - HKEY key_handle = HKEY_LOCAL_MACHINE; - fim_registry_key *ret_key; - - expect_GetSecurityInfo_call((PSID)"userid", NULL, ERROR_SUCCESS); - expect_ConvertSidToStringSid_call((LPSTR)"userid", 1); - expect_LookupAccountSid_call((PSID)"username", "domain", 1); - - ret_key = fim_registry_get_key_data(key_handle, path, configuration); - - assert_string_equal(ret_key->uid, "userid"); - assert_string_equal(ret_key->user_name, "username"); - assert_null(ret_key->gid); - assert_null(ret_key->group_name); - assert_null(ret_key->perm); - assert_null(ret_key->mtime); -} - -static void test_fim_registry_get_key_data_check_group(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_GROUP; - HKEY key_handle = HKEY_LOCAL_MACHINE; - fim_registry_key *ret_key; - - expect_GetSecurityInfo_call((PSID)"groupid", NULL, ERROR_SUCCESS); - expect_ConvertSidToStringSid_call((LPSTR)"groupid", 1); - expect_LookupAccountSid_call((PSID)"groupname", "domain", 1); - - ret_key = fim_registry_get_key_data(key_handle, path, configuration); - - assert_null(ret_key->uid); - assert_null(ret_key->user_name); - assert_string_equal(ret_key->gid, "groupid"); - assert_string_equal(ret_key->group_name, "groupname"); - assert_null(ret_key->perm); - assert_null(ret_key->mtime); -} - -static void test_fim_registry_get_key_data_check_perm(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_PERM; - HKEY key_handle = HKEY_LOCAL_MACHINE; - fim_registry_key *ret_key; - cJSON *permissions = create_win_permissions_object(); - - expect_get_registry_permissions(permissions, ERROR_SUCCESS); - - expect_string(__wrap_decode_win_acl_json, perms, permissions); - - ret_key = fim_registry_get_key_data(key_handle, path, configuration); - - assert_null(ret_key->uid); - assert_null(ret_key->user_name); - assert_null(ret_key->gid); - assert_null(ret_key->group_name); - assert_non_null(ret_key->perm); - assert_non_null(ret_key->perm_json); - assert_null(ret_key->mtime); -} - -static void test_fim_registry_get_key_data_check_mtime(void **state) { - char *path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_MTIME; - HKEY key_handle = HKEY_LOCAL_MACHINE; - fim_registry_key *ret_key; - FILETIME last_write_time = { 0, 1000 }; - - expect_RegQueryInfoKeyA_call(&last_write_time, ERROR_SUCCESS); - - ret_key = fim_registry_get_key_data(key_handle, path, configuration); - - assert_null(ret_key->uid); - assert_null(ret_key->user_name); - assert_null(ret_key->gid); - assert_null(ret_key->group_name); - assert_null(ret_key->perm); - assert_int_equal(ret_key->mtime, 1240857784); -} - -static void test_fim_registry_calculate_hashes_CHECK_MD5SUM(void **state) { - fim_entry *entry = *state; - - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_MD5SUM; - BYTE *data_buffer = (unsigned char *)"value_data"; - entry->registry_entry.value->type = REG_EXPAND_SZ; - - fim_registry_calculate_hashes(entry, configuration, data_buffer); - - assert_string_equal(entry->registry_entry.value->hash_md5, "51718cc02664f7b131b76f8b53918927"); - assert_string_equal(entry->registry_entry.value->hash_sha1, ""); - assert_string_equal(entry->registry_entry.value->hash_sha256, ""); - assert_string_equal(entry->registry_entry.value->checksum, "1234567890ABCDEF1234567890ABCDEF12345678"); -} - -static void test_fim_registry_calculate_hashes_CHECK_SHA1SUM(void **state) { - fim_entry *entry = *state; - - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_SHA1SUM; - BYTE *data_buffer = (unsigned char *)"value_data\0"; - entry->registry_entry.value->type = REG_MULTI_SZ; - - fim_registry_calculate_hashes(entry, configuration, data_buffer); - - - assert_string_equal(entry->registry_entry.value->hash_md5, ""); - assert_string_equal(entry->registry_entry.value->hash_sha1, "ee6cf811813827f6e18d07f0fb7e22a43337d63c"); - assert_string_equal(entry->registry_entry.value->hash_sha256, ""); - assert_string_equal(entry->registry_entry.value->checksum, "1234567890ABCDEF1234567890ABCDEF12345678"); -} - -static void test_fim_registry_calculate_hashes_CHECK_SHA256SUM(void **state) { - fim_entry *entry = *state; - - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_SHA256SUM; - BYTE *data_buffer = (unsigned char *)"value_data"; - entry->registry_entry.value->type = REG_DWORD; - - fim_registry_calculate_hashes(entry, configuration, data_buffer); - - - assert_string_equal(entry->registry_entry.value->hash_md5, ""); - assert_string_equal(entry->registry_entry.value->hash_sha1, ""); - assert_string_equal(entry->registry_entry.value->hash_sha256, "482e0d08067b0965649aba1eef95350f71f60ba9079c7096f2f4e4b018f4cc09"); - assert_string_equal(entry->registry_entry.value->checksum, "1234567890ABCDEF1234567890ABCDEF12345678"); -} - -static void test_fim_registry_calculate_hashes_default_type(void **state) { - fim_entry *entry = *state; - - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = CHECK_REGISTRY_ALL; - BYTE *data_buffer = (unsigned char *)"value_data"; - entry->registry_entry.value->type = -1; - - fim_registry_calculate_hashes(entry, configuration, data_buffer); - - - assert_string_equal(entry->registry_entry.value->hash_md5, "d41d8cd98f00b204e9800998ecf8427e"); - assert_string_equal(entry->registry_entry.value->hash_sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - assert_string_equal(entry->registry_entry.value->hash_sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); - assert_string_equal(entry->registry_entry.value->checksum, "1234567890ABCDEF1234567890ABCDEF12345678"); -} - -static void test_fim_registry_calculate_hashes_no_config(void **state) { - fim_entry *entry = *state; - - syscheck.registry = one_entry_config; - registry_t *configuration = &syscheck.registry[0]; - configuration->opts = 0; - BYTE *data_buffer = (unsigned char *)"value_data"; - entry->registry_entry.value->type = -1; - - fim_registry_calculate_hashes(entry, configuration, data_buffer); - - assert_string_equal(entry->registry_entry.value->hash_md5, ""); - assert_string_equal(entry->registry_entry.value->hash_sha1, ""); - assert_string_equal(entry->registry_entry.value->hash_sha256, ""); - assert_string_equal(entry->registry_entry.value->checksum, "1234567890ABCDEF1234567890ABCDEF12345678"); -} - -static void test_fim_registry_scan_base_line_generation(void **state) { - syscheck.registry = one_entry_config; - syscheck.registry[0].opts = CHECK_REGISTRY_ALL; - - // Set value of FirstSubKey - char *value_name = "test_value"; - unsigned int value_type = REG_DWORD; - unsigned int value_size = 4; - DWORD value_data = 123456; - TXN_HANDLE mock_handle; - - LPSTR usid = "userid"; - LPSTR gsid = "groupid"; - FILETIME last_write_time = { 0, 1000 }; - - will_return(__wrap_fim_db_transaction_start, mock_handle); - will_return(__wrap_fim_db_transaction_start, mock_handle); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_START); - expect_any_always(__wrap__mdebug2, formatted_msg); - - // Scan a subkey of batfile - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\Classes\\batfile", 0, KEY_READ | KEY_WOW64_64KEY, NULL, - ERROR_SUCCESS); - expect_RegQueryInfoKey_call(1, 0, &last_write_time, ERROR_SUCCESS); - expect_RegEnumKeyEx_call("FirstSubKey", 12, ERROR_SUCCESS); - - // Scan a value of FirstSubKey - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\Classes\\batfile\\FirstSubKey", 0, - KEY_READ | KEY_WOW64_64KEY, NULL, ERROR_SUCCESS); - expect_RegQueryInfoKey_call(0, 1, &last_write_time, ERROR_SUCCESS); - - // Inside fim_registry_get_key_data - expect_fim_registry_get_key_data_call(usid, gsid, "username", "groupname", - "sid (allowed): delete|write_dac|write_data|append_data|write_attributes", - last_write_time); - will_return(__wrap_fim_db_transaction_sync_row, -1); - expect_string(__wrap__merror, formatted_msg, "Dbsync registry transaction failed due to -1"); - will_return(__wrap_fim_db_transaction_sync_row, -1); - expect_RegEnumValue_call(value_name, value_type, (LPBYTE)&value_data, value_size, ERROR_SUCCESS); - - expect_fim_registry_value_diff("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\FirstSubKey", "test_value", - (const char *)&value_data, 4, REG_DWORD, NULL); - - - - // Inside fim_registry_get_key_data - expect_fim_registry_get_key_data_call(usid, gsid, "username", "groupname", - "sid (allowed): delete|write_dac|write_data|append_data|write_attributes", - last_write_time); - - will_return(__wrap_fim_db_transaction_sync_row, 0); - - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_ENDED); - - // Test - fim_registry_scan(); - assert_int_equal(_base_line, 1); -} - -static void test_fim_registry_scan_regular_scan(void **state) { - syscheck.registry = default_config; - - // Set value of FirstSubKey - char *value_name = "test_value"; - unsigned int value_type = REG_DWORD; - unsigned int value_size = 4; - DWORD value_data = 123456; - TXN_HANDLE mock_handle; - - LPSTR usid = "userid"; - LPSTR gsid = "groupid"; - FILETIME last_write_time = { 0, 1000 }; - - will_return(__wrap_fim_db_transaction_start, &mock_handle); - will_return(__wrap_fim_db_transaction_start, &mock_handle); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_START); - expect_string(__wrap__mdebug1, formatted_msg, "(6919): Invalid syscheck registry entry: 'HKEY_LOCAL_MACHINE_Invalid_key\\Software\\Ignore' arch: '[x64] '."); - expect_any_always(__wrap__mdebug2, formatted_msg); - expect_any_always(__wrap__merror, formatted_msg); - - // Scan a subkey of batfile - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\Classes\\batfile", 0, - KEY_READ | KEY_WOW64_64KEY, NULL, ERROR_SUCCESS); - expect_RegQueryInfoKey_call(1, 0, &last_write_time, ERROR_SUCCESS); - expect_RegEnumKeyEx_call("FirstSubKey", 12, ERROR_SUCCESS); - - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\Classes\\batfile\\FirstSubKey", 0, - KEY_READ | KEY_WOW64_64KEY, NULL, ERROR_SUCCESS); - expect_RegQueryInfoKey_call(0, 1, &last_write_time, ERROR_SUCCESS); - - // Inside fim_registry_get_key_data - expect_fim_registry_get_key_data_call(usid, gsid, "username", "groupname", - "sid (allowed): delete|write_dac|write_data|append_data|write_attributes", - last_write_time); - - will_return(__wrap_fim_db_transaction_sync_row, -1); - will_return(__wrap_fim_db_transaction_sync_row, -1); - - expect_RegEnumValue_call(value_name, value_type, (LPBYTE)&value_data, value_size, ERROR_SUCCESS); - - - expect_fim_registry_value_diff("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\FirstSubKey", "test_value", - (const char *)&value_data, 4, REG_DWORD, NULL); - - // Inside fim_registry_get_key_data - expect_fim_registry_get_key_data_call(usid, gsid, "username", "groupname", - "sid (allowed): delete|write_dac|write_data|append_data|write_attributes", - last_write_time); - - will_return(__wrap_fim_db_transaction_sync_row, -1); - will_return(__wrap_fim_db_transaction_sync_row, -1); - - // Scan a subkey of RecursionLevel0 - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\RecursionLevel0", 0, KEY_READ | KEY_WOW64_64KEY, NULL, ERROR_SUCCESS); - expect_RegQueryInfoKey_call(1, 0, &last_write_time, ERROR_SUCCESS); - expect_RegEnumKeyEx_call("depth0", 7, ERROR_SUCCESS); - - // Inside fim_registry_get_key_data - expect_fim_registry_get_key_data_call(usid, gsid, "username2", "groupname2", - "sid (allowed): delete|write_dac|write_data|append_data|write_attributes", - last_write_time); - - will_return(__wrap_fim_db_transaction_sync_row, -1); - - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\FailToInsert", 0, - KEY_READ | KEY_WOW64_64KEY, NULL, ERROR_SUCCESS); - expect_RegQueryInfoKey_call(0, 0, &last_write_time, ERROR_SUCCESS); - - - // Inside fim_registry_get_key_data - expect_fim_registry_get_key_data_call(usid, gsid, "username2", "groupname2", - "sid (allowed): delete|write_dac|write_data|append_data|write_attributes", - last_write_time); - - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_ENDED); - - // Test - fim_registry_scan(); -} - -static void test_fim_registry_scan_RegOpenKeyEx_fail(void **state) { - syscheck.registry = one_entry_config; - syscheck.registry[0].opts = CHECK_REGISTRY_ALL; - TXN_HANDLE mock_handle; - - will_return(__wrap_fim_db_transaction_start, mock_handle); - will_return(__wrap_fim_db_transaction_start, mock_handle); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_START); - expect_string(__wrap__mdebug1, formatted_msg, "(6920): Unable to open registry key: 'Software\\Classes\\batfile' arch: '[x64]'."); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_ENDED); - expect_any_always(__wrap__mdebug2, formatted_msg); - - // Scan a subkey of batfile - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\Classes\\batfile", 0, - KEY_READ | KEY_WOW64_64KEY, NULL, -1); - - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - - // Test - fim_registry_scan(); -} - -static void test_fim_registry_scan_RegQueryInfoKey_fail(void **state) { - FILETIME last_write_time = { 0, 1000 }; - - syscheck.registry = one_entry_config; - syscheck.registry[0].opts = CHECK_REGISTRY_ALL; - TXN_HANDLE mock_handle; - - will_return(__wrap_fim_db_transaction_start, mock_handle); - will_return(__wrap_fim_db_transaction_start, mock_handle); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_START); - expect_string(__wrap__mdebug1, formatted_msg, FIM_WINREGISTRY_ENDED); - expect_any_always(__wrap__mdebug2, formatted_msg); - - // Scan a subkey of batfile - expect_RegOpenKeyEx_call(HKEY_LOCAL_MACHINE, "Software\\Classes\\batfile", 0, - KEY_READ | KEY_WOW64_64KEY, NULL, ERROR_SUCCESS); - expect_RegQueryInfoKey_call(1, 0, &last_write_time, -1); - - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - expect_function_call(__wrap_fim_db_transaction_deleted_rows); - - // Test - fim_registry_scan(); -} - -static void test_fim_registry_key_transaction_callback_empty_changed_attributes(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - fim_registry_key key = { - .path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile", - .arch = ARCH_64BIT, - .hash_full_path = "234567890ABCDEF1234567890ABCDEF123456111", - .last_event = 12345 - }; - ReturnTypeCallback resultType = MODIFIED; - const cJSON *result_json = cJSON_Parse("{\"new\":{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\",\"arch\":\"[x64]\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"},\"old\":{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\"}}"); - fim_key_txn_context_t user_data = {.key = &key, .evt_data = &event_data}; - - expect_string(__wrap__mdebug2, formatted_msg, "(6954): Entry 'HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile' does not have any modified fields. No event will be generated."); - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_key_transaction_callback_base_line(){ - _base_line = 0; - ReturnTypeCallback resultType = INSERTED; - const cJSON* result_json = NULL; - fim_key_txn_context_t user_data = {.key = NULL, .evt_data = NULL}; - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_key_transaction_callback_empty_json_array(){ - _base_line = 1; - ReturnTypeCallback resultType = INSERTED; - const char* json_string = "{}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_key_txn_context_t user_data = {.key = NULL, .evt_data = NULL}; - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_key_transaction_callback_null_configuration(){ - _base_line = 1; - event_data_t event_data; - ReturnTypeCallback resultType = INSERTED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x32]\", \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_key_txn_context_t user_data = {.key = NULL, .evt_data = &event_data}; - - // fim_registry_configuration - expect_any_always(__wrap__mdebug2, formatted_msg); - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_key_transaction_callback_insert(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - ReturnTypeCallback resultType = INSERTED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_key_txn_context_t user_data = {.key = NULL, .evt_data = &event_data}; - - expect_function_call(__wrap_send_syscheck_msg); - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_key_transaction_callback_modify(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - ReturnTypeCallback resultType = MODIFIED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_key_txn_context_t user_data = {.key = NULL, .evt_data = &event_data}; - - expect_function_call(__wrap_send_syscheck_msg); - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_key_transaction_callback_delete(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - ReturnTypeCallback resultType = DELETED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_key_txn_context_t user_data = {.key = NULL, .evt_data = &event_data}; - - expect_function_call(__wrap_send_syscheck_msg); - expect_string(__wrap__mdebug2, formatted_msg, "(6355): Can't remove folder 'queue/diff/registry/[x64] b9b175e8810d3475f15976dd3b5f9210f3af6604', it does not exist."); - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_key_transaction_callback_max_rows(){ - _base_line = 1; - event_data_t event_data; - fim_registry_key key; - key.path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - key.arch = ARCH_64BIT; - ReturnTypeCallback resultType = MAX_ROWS; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\", \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_key_txn_context_t user_data = {.key = &key, .evt_data = &event_data}; - - expect_string(__wrap__mdebug1, formatted_msg, "Couldn't insert 'HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile' entry into DB. The DB is full, please check your configuration."); - - registry_key_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_empty_changed_attributes(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - fim_registry_value_data value; - value.path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - value.arch = ARCH_64BIT; - value.name = "mock_value_name"; - value.hash_full_path = "234567890ABCDEF1234567890ABCDEF123456111"; - ReturnTypeCallback resultType = MODIFIED; - const cJSON *result_json = cJSON_Parse("{\"new\":{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\",\"arch\":\"[x64]\",\"name\":\"mock_name_value\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"},\"old\":{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\",\"name\":\"mock_name_value\"}}"); - fim_val_txn_context_t user_data = {.data = &value, .evt_data = &event_data, .diff = NULL}; - - expect_string(__wrap__mdebug2, formatted_msg, "(6954): Entry 'HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile' does not have any modified fields. No event will be generated."); - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_base_line(){ - _base_line = 0; - event_data_t event_data; - ReturnTypeCallback resultType = INSERTED; - const cJSON* result_json = NULL; - fim_val_txn_context_t user_data = {.data = NULL, .evt_data = &event_data, .diff = NULL}; - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_empty_json_array(){ - _base_line = 1; - ReturnTypeCallback resultType = INSERTED; - const char* json_string = "{}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_val_txn_context_t user_data = {.data = NULL, .evt_data = NULL, .diff = NULL}; - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_null_configuration(){ - _base_line = 1; - event_data_t event_data; - ReturnTypeCallback resultType = INSERTED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x32]\", \"name\":\"mock_name_value\", \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_val_txn_context_t user_data = {.data = NULL, .evt_data = &event_data, .diff = NULL}; - - // fim_registry_configuration - expect_any_always(__wrap__mdebug2, formatted_msg); - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_insert(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - ReturnTypeCallback resultType = INSERTED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\",\"arch\":\"[x64]\", \"name\":\"mock_name_value\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_val_txn_context_t user_data = {.data = NULL, .evt_data = &event_data, .diff = NULL}; - - expect_function_call(__wrap_send_syscheck_msg); - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_modify(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - ReturnTypeCallback resultType = MODIFIED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\",\"arch\":\"[x64]\",\"name\":\"mock_name_value\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_val_txn_context_t user_data = {.data = NULL, .evt_data = &event_data, .diff = NULL}; - - expect_function_call(__wrap_send_syscheck_msg); - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_modify_with_diff(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - ReturnTypeCallback resultType = MODIFIED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\",\"arch\":\"[x64]\",\"name\":\"mock_name_value\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_val_txn_context_t user_data = {.data = NULL, .evt_data = &event_data, .diff = "test diff string"}; - - expect_function_call(__wrap_send_syscheck_msg); - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_delete(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - ReturnTypeCallback resultType = DELETED; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\", \"name\":\"mock_name_value\",\"last_event\":12345, \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_val_txn_context_t user_data = {.data = NULL, .evt_data = &event_data, .diff = NULL}; - - expect_function_call(__wrap_send_syscheck_msg); - expect_string(__wrap__mdebug2, formatted_msg, "(6355): Can't remove folder 'queue/diff/registry/[x64] b9b175e8810d3475f15976dd3b5f9210f3af6604/6797a8200934259ad5d56d1eb8dd24afc4f7ae2e', it does not exist."); - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_value_transaction_callback_max_rows(){ - _base_line = 1; - event_data_t event_data = {.mode = FIM_SCHEDULED}; - fim_registry_value_data value; - value.path = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - value.arch = ARCH_64BIT; - value.name = "mock_value_name"; - ReturnTypeCallback resultType = MAX_ROWS; - const char* json_string = "{\"path\":\"HKEY_LOCAL_MACHINE\\\\Software\\\\Classes\\\\batfile\", \"arch\":\"[x64]\", \"name\":\"mock_name_value\", \"hash_full_path\":\"234567890ABCDEF1234567890ABCDEF123456111\"}"; - const cJSON* result_json = cJSON_Parse(json_string); - fim_val_txn_context_t user_data = {.data = &value, .evt_data = &event_data, .diff = NULL}; - - expect_string(__wrap__mdebug1, formatted_msg, "Couldn't insert 'HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile' entry into DB. The DB is full, please check your configuration."); - - registry_value_transaction_callback(resultType, result_json, &user_data); -} - -static void test_fim_registry_free_entry(){ - fim_entry *entry; - os_calloc(1, sizeof(fim_entry), entry); - - fim_registry_key *key; - os_calloc(1, sizeof(fim_registry_key), key); - key->id = 3; - os_strdup("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile", key->path); - os_strdup("234567890ABCDEF1234567890ABCDEF123456111", key->hash_full_path); - os_strdup("sid (allowed): delete|write_dac|write_data|append_data|write_attributes", key->perm); - os_strdup("100", key->uid); - os_strdup("200", key->gid); - os_strdup("username", key->user_name); - os_strdup("groupname", key->group_name); - key->arch = 1; - - fim_registry_value_data *value; - os_calloc(1, sizeof(fim_registry_value_data), value); - value->id = 3; - os_strdup("valuename", value->name); - strcpy(value->hash_md5, "1234567890ABCDEF1234567890ABCDEF"); - strcpy(value->hash_sha1, "1234567890ABCDEF1234567890ABCDEF12345678"); - strcpy(value->hash_sha256, "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF"); - strcpy(value->checksum, "1234567890ABCDEF1234567890ABCDEF12345678"); - - entry->type = FIM_TYPE_REGISTRY; - entry->registry_entry.key = key; - entry->registry_entry.value = value; - - fim_registry_free_entry(entry); -} - -int main(void) { - const struct CMUnitTest tests[] = { - /* fim_set_root_key test */ - cmocka_unit_test(test_fim_set_root_key_null_root_key), - cmocka_unit_test(test_fim_set_root_key_null_full_key), - cmocka_unit_test(test_fim_set_root_key_null_sub_key), - cmocka_unit_test(test_fim_set_root_key_invalid_key), - cmocka_unit_test(test_fim_set_root_key_invalid_root_key), - cmocka_unit_test(test_fim_set_root_key_valid_HKEY_LOCAL_MACHINE_key), - cmocka_unit_test(test_fim_set_root_key_valid_HKEY_CLASSES_ROOT_key), - cmocka_unit_test(test_fim_set_root_key_valid_HKEY_CURRENT_CONFIG_key), - cmocka_unit_test(test_fim_set_root_key_valid_HKEY_USERS_key), - - /* fim_registry_configuration tests */ - cmocka_unit_test(test_fim_registry_configuration_registry_found), - cmocka_unit_test(test_fim_registry_configuration_registry_not_found_arch_does_not_match), - cmocka_unit_test(test_fim_registry_configuration_registry_not_found_path_does_not_match), - cmocka_unit_test(test_fim_registry_configuration_null_key), - - /* fim_registry_validate_recursion_level tests */ - cmocka_unit_test(test_fim_registry_validate_recursion_level_null_configuration), - cmocka_unit_test(test_fim_registry_validate_recursion_level_null_entry_path), - cmocka_unit_test(test_fim_registry_validate_recursion_level_valid_entry_path), - cmocka_unit_test(test_fim_registry_validate_recursion_level_invalid_recursion_level), - - /* fim_registry_validate_ignore tests */ - cmocka_unit_test(test_fim_registry_validate_ignore_null_configuration), - cmocka_unit_test(test_fim_registry_validate_ignore_null_entry_path), - cmocka_unit_test(test_fim_registry_validate_ignore_valid_entry_path), - cmocka_unit_test(test_fim_registry_validate_ignore_ignore_entry), - cmocka_unit_test(test_fim_registry_validate_ignore_regex_ignore_entry), - - /* fim_registry_get_key_data tests */ - cmocka_unit_test(test_fim_registry_get_key_data_check_owner), - cmocka_unit_test(test_fim_registry_get_key_data_check_group), - cmocka_unit_test(test_fim_registry_get_key_data_check_perm), - cmocka_unit_test(test_fim_registry_get_key_data_check_mtime), - - /* fim_registry_calculate_hashes tests */ - cmocka_unit_test_setup_teardown(test_fim_registry_calculate_hashes_CHECK_MD5SUM, setup_test_hashes, teardown_test_hashes), - cmocka_unit_test_setup_teardown(test_fim_registry_calculate_hashes_CHECK_SHA1SUM, setup_test_hashes, teardown_test_hashes), - cmocka_unit_test_setup_teardown(test_fim_registry_calculate_hashes_CHECK_SHA256SUM, setup_test_hashes, teardown_test_hashes), - cmocka_unit_test_setup_teardown(test_fim_registry_calculate_hashes_default_type, setup_test_hashes, teardown_test_hashes), - cmocka_unit_test_setup_teardown(test_fim_registry_calculate_hashes_no_config, setup_test_hashes, teardown_test_hashes), - - /* fim_registry_scan tests */ - cmocka_unit_test(test_fim_registry_scan_base_line_generation), - cmocka_unit_test(test_fim_registry_scan_regular_scan), - cmocka_unit_test(test_fim_registry_scan_RegOpenKeyEx_fail), - cmocka_unit_test(test_fim_registry_scan_RegQueryInfoKey_fail), - - /* fim registry key transaction callback tests */ - cmocka_unit_test(test_fim_registry_key_transaction_callback_empty_changed_attributes), - cmocka_unit_test(test_fim_registry_key_transaction_callback_empty_json_array), - cmocka_unit_test(test_fim_registry_key_transaction_callback_base_line), - cmocka_unit_test(test_fim_registry_key_transaction_callback_null_configuration), - cmocka_unit_test(test_fim_registry_key_transaction_callback_insert), - cmocka_unit_test(test_fim_registry_key_transaction_callback_modify), - cmocka_unit_test(test_fim_registry_key_transaction_callback_delete), - cmocka_unit_test(test_fim_registry_key_transaction_callback_max_rows), - - /* fim registry value transaction callback tests */ - cmocka_unit_test(test_fim_registry_value_transaction_callback_empty_changed_attributes), - cmocka_unit_test(test_fim_registry_value_transaction_callback_empty_json_array), - cmocka_unit_test(test_fim_registry_value_transaction_callback_base_line), - cmocka_unit_test(test_fim_registry_value_transaction_callback_null_configuration), - cmocka_unit_test(test_fim_registry_value_transaction_callback_insert), - cmocka_unit_test(test_fim_registry_value_transaction_callback_modify), - cmocka_unit_test(test_fim_registry_value_transaction_callback_modify_with_diff), - cmocka_unit_test(test_fim_registry_value_transaction_callback_delete), - cmocka_unit_test(test_fim_registry_value_transaction_callback_max_rows), - - /* fim_registry_free_entry */ - cmocka_unit_test(test_fim_registry_free_entry) - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/syscheckd/test_config.c b/src/unit_tests/syscheckd/test_config.c deleted file mode 100644 index 6b73a287e24..00000000000 --- a/src/unit_tests/syscheckd/test_config.c +++ /dev/null @@ -1,926 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../syscheckd/include/syscheck.h" -#include "../config/syscheck-config.h" - -#include "../wrappers/common.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/wazuh/os_regex/os_regex_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" - -/* redefinitons/wrapping */ -typedef struct entry_struct_s { - directory_t *dir1; - directory_t *dir2; - char *filerestrict; -} entry_struct_t; - -static int setup_read_config(void **state) { - test_mode = 0; - - return 0; -} - -static int restart_syscheck(void **state) -{ - test_mode = 1; - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - cJSON *data = *state; - if (data) { - cJSON_Delete(data); - } - Free_Syscheck(&syscheck); - memset(&syscheck, 0, sizeof(syscheck_config)); - return 0; -} - -/* setup and teardown */ - -static int setup_group(void **state) { - test_mode = 1; - - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - - return 0; -} - -static int setup_entry(void **state) { - entry_struct_t *entries = calloc(1, sizeof(entry_struct_t)); - if (entries == NULL) { - return 1; - } - - *state = entries; - return 0; -} - -static int teardown_entry(void **state) { - entry_struct_t *entries = *state; - - if (entries->dir1) { - free_directory(entries->dir1); - } - - if (entries->dir2) { - free_directory(entries->dir2); - } - - if (entries->filerestrict) { - free(entries->filerestrict); - } - - free(entries); - return 0; -} -/* tests */ - -void test_Read_Syscheck_Config_success(void **state) -{ - (void) state; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - expect_any_always(__wrap__mwarn, formatted_msg); - - - test_mode = 0; - ret = Read_Syscheck_Config("test_syscheck_max_dir.conf"); - test_mode = 1; - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.rootcheck, 0); - - assert_int_equal(syscheck.disabled, 0); - assert_int_equal(syscheck.skip_fs.nfs, 1); - assert_int_equal(syscheck.skip_fs.dev, 1); - assert_int_equal(syscheck.skip_fs.sys, 1); - assert_int_equal(syscheck.skip_fs.proc, 1); - assert_int_equal(syscheck.scan_on_start, 1); - assert_int_equal(syscheck.time, 43200); - assert_non_null(syscheck.ignore); - assert_non_null(syscheck.ignore_regex); - assert_non_null(syscheck.nodiff); - assert_non_null(syscheck.nodiff_regex); - assert_null(syscheck.scan_day); - assert_null(syscheck.scan_time); - assert_non_null(syscheck.directories); - // Directories configuration have 100 directories in one line. It only can monitor 64 per line. - // With the first 10 directories in other lines, the count should be 74 (75 should be NULL) - for (int i = 0; i < 70; i++){ - assert_non_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, i))); - } - assert_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 74))); - assert_int_equal(syscheck.enable_synchronization, 1); - assert_int_equal(syscheck.restart_audit, 1); - assert_int_equal(syscheck.enable_whodata, 1); - assert_null(syscheck.realtime); - assert_int_equal(syscheck.audit_healthcheck, 1); - assert_int_equal(syscheck.process_priority, 10); - assert_int_equal(syscheck.allow_remote_prefilter_cmd, true); - assert_non_null(syscheck.prefilter_cmd); // It should be a valid binary absolute path - assert_int_equal(syscheck.sync_interval, 600); - assert_int_equal(syscheck.sync_queue_size, 16384); - assert_int_equal(syscheck.sync_thread_pool, 1); - assert_int_equal(syscheck.max_eps, 200); - assert_int_equal(syscheck.disk_quota_enabled, true); - assert_int_equal(syscheck.disk_quota_limit, 1024 * 1024); - assert_int_equal(syscheck.file_size_enabled, true); - assert_int_equal(syscheck.file_size_limit, 50 * 1024); - assert_int_equal(syscheck.diff_folder_size, 0); - assert_int_equal(syscheck.file_limit_enabled, 1); - assert_int_equal(syscheck.file_entry_limit, 50000); -#ifdef WIN32 - assert_int_equal(syscheck.registry_limit_enabled, 1); - assert_int_equal(syscheck.db_entry_registry_limit, 50000); -#endif -} - -void test_Read_Syscheck_Config_invalid(void **state) -{ - (void) state; - int ret; - - expect_any_always(__wrap__mdebug1, formatted_msg); - expect_string(__wrap__merror, formatted_msg, "(1226): Error reading XML file 'invalid.conf': XMLERR: File 'invalid.conf' not found. (line 0)."); - - ret = Read_Syscheck_Config("invalid.conf"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_Read_Syscheck_Config_undefined(void **state) -{ - (void) state; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - - ret = Read_Syscheck_Config("test_syscheck2.conf"); - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.rootcheck, 0); - - assert_int_equal(syscheck.disabled, 0); - assert_int_equal(syscheck.skip_fs.nfs, 0); - assert_int_equal(syscheck.skip_fs.dev, 0); - assert_int_equal(syscheck.skip_fs.sys, 0); - assert_int_equal(syscheck.skip_fs.proc, 0); - assert_int_equal(syscheck.scan_on_start, 0); - assert_int_equal(syscheck.time, 43200); - assert_null(syscheck.ignore); - assert_null(syscheck.ignore_regex); - assert_null(syscheck.nodiff); - assert_null(syscheck.nodiff_regex); - assert_null(syscheck.scan_day); - assert_null(syscheck.scan_time); - assert_non_null(syscheck.directories); - assert_int_equal(syscheck.enable_synchronization, 0); - assert_int_equal(syscheck.restart_audit, 0); - assert_int_equal(syscheck.enable_whodata, 1); - assert_null(syscheck.realtime); - assert_int_equal(syscheck.audit_healthcheck, 0); - assert_int_equal(syscheck.process_priority, 10); - assert_int_equal(syscheck.allow_remote_prefilter_cmd, false); - assert_null(syscheck.prefilter_cmd); - assert_int_equal(syscheck.sync_interval, 600); - assert_int_equal(syscheck.sync_queue_size, 16384); - assert_int_equal(syscheck.sync_thread_pool, 1); - assert_int_equal(syscheck.max_eps, 200); - assert_int_equal(syscheck.disk_quota_enabled, true); - assert_int_equal(syscheck.disk_quota_limit, 2 * 1024 * 1024); - assert_int_equal(syscheck.file_size_enabled, true); - assert_int_equal(syscheck.file_size_limit, 5); - assert_int_equal(syscheck.diff_folder_size, 0); - assert_int_equal(syscheck.file_limit_enabled, 1); - assert_int_equal(syscheck.file_entry_limit, 50000); -#ifdef WIN32 - assert_int_equal(syscheck.db_entry_registry_limit, 50000); -#endif -} - -void test_Read_Syscheck_Config_unparsed(void **state) -{ - (void) state; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - - ret = Read_Syscheck_Config("test_empty_config.conf"); - - assert_int_equal(ret, 1); - - // Default values - assert_int_equal(syscheck.rootcheck, 0); - assert_int_equal(syscheck.disabled, 1); - assert_int_equal(syscheck.skip_fs.nfs, 1); - assert_int_equal(syscheck.skip_fs.dev, 1); - assert_int_equal(syscheck.skip_fs.sys, 1); - assert_int_equal(syscheck.skip_fs.proc, 1); - assert_int_equal(syscheck.scan_on_start, 1); - assert_int_equal(syscheck.time, 43200); - assert_null(syscheck.ignore); - assert_null(syscheck.ignore_regex); - assert_null(syscheck.nodiff); - assert_null(syscheck.nodiff_regex); - assert_null(syscheck.scan_day); - assert_null(syscheck.scan_time); - assert_non_null(syscheck.directories); - assert_null(OSList_GetFirstNode(syscheck.directories)); - assert_int_equal(syscheck.enable_synchronization, 1); - assert_int_equal(syscheck.restart_audit, 1); - assert_int_equal(syscheck.enable_whodata, 0); - assert_null(syscheck.realtime); - assert_int_equal(syscheck.audit_healthcheck, 1); - assert_int_equal(syscheck.process_priority, 10); - assert_int_equal(syscheck.allow_remote_prefilter_cmd, false); - assert_null(syscheck.prefilter_cmd); - assert_int_equal(syscheck.sync_interval, 300); - assert_int_equal(syscheck.sync_queue_size, 16384); - assert_int_equal(syscheck.sync_thread_pool, 1); - assert_int_equal(syscheck.max_eps, 50); - assert_int_equal(syscheck.disk_quota_enabled, true); - assert_int_equal(syscheck.disk_quota_limit, 1024 * 1024); - assert_int_equal(syscheck.file_size_enabled, true); - assert_int_equal(syscheck.file_size_limit, 50 * 1024); - assert_int_equal(syscheck.diff_folder_size, 0); -} - -void test_getSyscheckConfig(void **state) -{ - (void) state; - cJSON * ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); -#ifdef TEST_WINAGENT - expect_string(__wrap__mdebug2, formatted_msg, "Duplicated registration entry: HKEY_SOME_KEY\\the_key9"); -#endif - - Read_Syscheck_Config("test_syscheck_config.conf"); - ret = getSyscheckConfig(); - *state = ret; - - assert_non_null(ret); - assert_int_equal(cJSON_GetArraySize(ret), 1); - - cJSON *sys_items = cJSON_GetObjectItem(ret, "syscheck"); - #if defined(TEST_SERVER) || defined(TEST_AGENT) - assert_int_equal(cJSON_GetArraySize(sys_items), 21); - #elif defined(TEST_WINAGENT) - assert_int_equal(cJSON_GetArraySize(sys_items), 29); - #endif - - cJSON *disabled = cJSON_GetObjectItem(sys_items, "disabled"); - assert_string_equal(cJSON_GetStringValue(disabled), "no"); - cJSON *frequency = cJSON_GetObjectItem(sys_items, "frequency"); - assert_int_equal(frequency->valueint, 43200); - - cJSON *db_file_entry_limit = cJSON_GetObjectItem(sys_items, "file_limit"); - cJSON *db_file_entry_limit_enabled = cJSON_GetObjectItem(db_file_entry_limit, "enabled"); - assert_string_equal(cJSON_GetStringValue(db_file_entry_limit_enabled), "yes"); - cJSON *db_entry_limit_file_limit = cJSON_GetObjectItem(db_file_entry_limit, "entries"); - assert_int_equal(db_entry_limit_file_limit->valueint, 50000); - - cJSON *diff = cJSON_GetObjectItem(sys_items, "diff"); - - cJSON *disk_quota = cJSON_GetObjectItem(diff, "disk_quota"); - cJSON *disk_quota_enabled = cJSON_GetObjectItem(disk_quota, "enabled"); - assert_string_equal(cJSON_GetStringValue(disk_quota_enabled), "yes"); - cJSON *disk_quota_limit = cJSON_GetObjectItem(disk_quota, "limit"); - assert_int_equal(disk_quota_limit->valueint, 1024 * 1024); - - cJSON *file_size = cJSON_GetObjectItem(diff, "file_size"); - cJSON *file_size_enabled = cJSON_GetObjectItem(file_size, "enabled"); - assert_string_equal(cJSON_GetStringValue(file_size_enabled), "yes"); - cJSON *file_size_limit = cJSON_GetObjectItem(file_size, "limit"); - assert_int_equal(file_size_limit->valueint, 50 * 1024); - - cJSON *skip_nfs = cJSON_GetObjectItem(sys_items, "skip_nfs"); - assert_string_equal(cJSON_GetStringValue(skip_nfs), "yes"); - cJSON *skip_dev = cJSON_GetObjectItem(sys_items, "skip_dev"); - assert_string_equal(cJSON_GetStringValue(skip_dev), "yes"); - cJSON *skip_sys = cJSON_GetObjectItem(sys_items, "skip_sys"); - assert_string_equal(cJSON_GetStringValue(skip_sys), "yes"); - cJSON *skip_proc = cJSON_GetObjectItem(sys_items, "skip_proc"); - assert_string_equal(cJSON_GetStringValue(skip_proc), "yes"); - cJSON *scan_on_start = cJSON_GetObjectItem(sys_items, "scan_on_start"); - assert_string_equal(cJSON_GetStringValue(scan_on_start), "yes"); - - cJSON *sys_dir = cJSON_GetObjectItem(sys_items, "directories"); - -#if defined(TEST_SERVER) || defined(TEST_AGENT) - assert_int_equal(cJSON_GetArraySize(sys_dir), 6); - #elif defined(TEST_WINAGENT) - assert_int_equal(cJSON_GetArraySize(sys_dir), 13); -#endif - - - cJSON *sys_nodiff = cJSON_GetObjectItem(sys_items, "nodiff"); - assert_int_equal(cJSON_GetArraySize(sys_nodiff), 1); - - cJSON *sys_ignore = cJSON_GetObjectItem(sys_items, "ignore"); -#if defined(TEST_SERVER) || defined(TEST_AGENT) - assert_int_equal(cJSON_GetArraySize(sys_ignore), 12); - #elif defined(TEST_WINAGENT) - assert_int_equal(cJSON_GetArraySize(sys_ignore), 2); -#endif - -#ifdef TEST_WINAGENT - cJSON *sys_ignore_regex = cJSON_GetObjectItem(sys_items, "ignore_sregex"); - assert_int_equal(cJSON_GetArraySize(sys_ignore_regex), 1); - - cJSON *sys_windows_audit_interval = cJSON_GetObjectItem(sys_items, "windows_audit_interval"); - assert_int_equal(sys_windows_audit_interval->valueint, 0); - - cJSON *sys_registry = cJSON_GetObjectItem(sys_items, "registry"); - assert_int_equal(cJSON_GetArraySize(sys_registry), 42); - cJSON *sys_registry_ignore = cJSON_GetObjectItem(sys_items, "key_ignore"); - assert_int_equal(cJSON_GetArraySize(sys_registry_ignore), 12); - cJSON *sys_registry_ignore_sregex = cJSON_GetObjectItem(sys_items, "key_ignore_sregex"); - assert_int_equal(cJSON_GetArraySize(sys_registry_ignore_sregex), 1); - cJSON *sys_registry_value_ignore = cJSON_GetObjectItem(sys_items, "value_ignore"); - assert_int_equal(cJSON_GetArraySize(sys_registry_value_ignore), 5); - cJSON *sys_registry_value_ignore_sregex = cJSON_GetObjectItem(sys_items, "value_ignore_sregex"); - assert_int_equal(cJSON_GetArraySize(sys_registry_value_ignore_sregex), 4); -#endif - -#ifndef TEST_WINAGENT - cJSON *sys_whodata = cJSON_GetObjectItem(sys_items, "whodata"); - cJSON *whodata_restart_audit = cJSON_GetObjectItem(sys_whodata, "restart_audit"); - assert_string_equal(cJSON_GetStringValue(whodata_restart_audit), "yes"); - cJSON *whodata_audit_key = cJSON_GetObjectItem(sys_whodata, "audit_key"); - assert_int_equal(cJSON_GetArraySize(whodata_audit_key), 2); - cJSON *whodata_startup_healthcheck = cJSON_GetObjectItem(sys_whodata, "startup_healthcheck"); - assert_string_equal(cJSON_GetStringValue(whodata_startup_healthcheck), "yes"); -#endif - - cJSON *allow_remote_prefilter_cmd = cJSON_GetObjectItem(sys_items, "allow_remote_prefilter_cmd"); - assert_string_equal(cJSON_GetStringValue(allow_remote_prefilter_cmd), "yes"); - cJSON *prefilter_cmd = cJSON_GetObjectItem(sys_items, "prefilter_cmd"); -#ifndef TEST_WINAGENT - assert_string_equal(cJSON_GetStringValue(prefilter_cmd), "/bin/ls"); -#else - assert_string_equal(cJSON_GetStringValue(prefilter_cmd), "c:\\windows\\system32\\cmd.exe"); -#endif - - cJSON *sys_synchronization = cJSON_GetObjectItem(sys_items, "synchronization"); - cJSON *synchronization_enabled = cJSON_GetObjectItem(sys_synchronization, "enabled"); - assert_string_equal(cJSON_GetStringValue(synchronization_enabled), "yes"); - cJSON *synchronization_interval = cJSON_GetObjectItem(sys_synchronization, "interval"); - assert_int_equal(synchronization_interval->valueint, 600); - - cJSON *sys_max_eps = cJSON_GetObjectItem(sys_items, "max_eps"); - assert_int_equal(sys_max_eps->valueint, 200); - cJSON *sys_process_priority = cJSON_GetObjectItem(sys_items, "process_priority"); - assert_int_equal(sys_process_priority->valueint, 10); - - cJSON *database = cJSON_GetObjectItem(sys_items, "database"); - assert_string_equal(cJSON_GetStringValue(database), "disk"); -} - -void test_getSyscheckConfig_no_audit(void **state) -{ - (void) state; - cJSON * ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - - Read_Syscheck_Config("test_syscheck2.conf"); - - ret = getSyscheckConfig(); - *state = ret; - - assert_non_null(ret); - assert_int_equal(cJSON_GetArraySize(ret), 1); - - cJSON *sys_items = cJSON_GetObjectItem(ret, "syscheck"); - #ifndef TEST_WINAGENT - assert_int_equal(cJSON_GetArraySize(sys_items), 17); - #else - assert_int_equal(cJSON_GetArraySize(sys_items), 21); - #endif - - cJSON *disabled = cJSON_GetObjectItem(sys_items, "disabled"); - assert_string_equal(cJSON_GetStringValue(disabled), "no"); - cJSON *frequency = cJSON_GetObjectItem(sys_items, "frequency"); - assert_int_equal(frequency->valueint, 43200); - - cJSON *db_file_entry_limit = cJSON_GetObjectItem(sys_items, "file_limit"); - cJSON *db_file_entry_limit_enabled = cJSON_GetObjectItem(db_file_entry_limit, "enabled"); - assert_string_equal(cJSON_GetStringValue(db_file_entry_limit_enabled), "yes"); - cJSON *db_entry_limit_file_limit = cJSON_GetObjectItem(db_file_entry_limit, "entries"); - assert_int_equal(db_entry_limit_file_limit->valueint, 50000); - - cJSON *diff = cJSON_GetObjectItem(sys_items, "diff"); - - cJSON *disk_quota = cJSON_GetObjectItem(diff, "disk_quota"); - cJSON *disk_quota_enabled = cJSON_GetObjectItem(disk_quota, "enabled"); - assert_string_equal(cJSON_GetStringValue(disk_quota_enabled), "yes"); - cJSON *disk_quota_limit = cJSON_GetObjectItem(disk_quota, "limit"); - assert_int_equal(disk_quota_limit->valueint, 2 * 1024 * 1024); - - cJSON *file_size = cJSON_GetObjectItem(diff, "file_size"); - cJSON *file_size_enabled = cJSON_GetObjectItem(file_size, "enabled"); - assert_string_equal(cJSON_GetStringValue(file_size_enabled), "yes"); - cJSON *file_size_limit = cJSON_GetObjectItem(file_size, "limit"); - assert_int_equal(file_size_limit->valueint, 5); - - cJSON *skip_nfs = cJSON_GetObjectItem(sys_items, "skip_nfs"); - assert_string_equal(cJSON_GetStringValue(skip_nfs), "no"); - cJSON *skip_dev = cJSON_GetObjectItem(sys_items, "skip_dev"); - assert_string_equal(cJSON_GetStringValue(skip_dev), "no"); - cJSON *skip_sys = cJSON_GetObjectItem(sys_items, "skip_sys"); - assert_string_equal(cJSON_GetStringValue(skip_sys), "no"); - cJSON *skip_proc = cJSON_GetObjectItem(sys_items, "skip_proc"); - assert_string_equal(cJSON_GetStringValue(skip_proc), "no"); - cJSON *scan_on_start = cJSON_GetObjectItem(sys_items, "scan_on_start"); - assert_string_equal(cJSON_GetStringValue(scan_on_start), "no"); - - cJSON *sys_dir = cJSON_GetObjectItem(sys_items, "directories"); -#ifndef TEST_WINAGENT - assert_int_equal(cJSON_GetArraySize(sys_dir), 8); -#else - assert_int_equal(cJSON_GetArraySize(sys_dir), 6); -#endif - - cJSON *sys_nodiff = cJSON_GetObjectItem(sys_items, "nodiff"); - assert_null(sys_nodiff); - - cJSON *sys_ignore = cJSON_GetObjectItem(sys_items, "ignore"); - assert_null(sys_ignore); - -#ifndef TEST_WINAGENT - cJSON *sys_whodata = cJSON_GetObjectItem(sys_items, "whodata"); - cJSON *whodata_restart_audit = cJSON_GetObjectItem(sys_whodata, "restart_audit"); - assert_string_equal(cJSON_GetStringValue(whodata_restart_audit), "no"); - cJSON *whodata_audit_key = cJSON_GetObjectItem(sys_whodata, "audit_key"); - assert_null(whodata_audit_key); - cJSON *whodata_startup_healthcheck = cJSON_GetObjectItem(sys_whodata, "startup_healthcheck"); - assert_string_equal(cJSON_GetStringValue(whodata_startup_healthcheck), "no"); -#else - cJSON *windows_audit_interval = cJSON_GetObjectItem(sys_items, "windows_audit_interval"); - assert_int_equal(windows_audit_interval->valueint, 0); - cJSON *win_registry = cJSON_GetObjectItem(sys_items, "registry"); - assert_int_equal(cJSON_GetArraySize(win_registry), 33); - cJSON *win_registry_ignore = cJSON_GetObjectItem(sys_items, "key_ignore"); - assert_int_equal(cJSON_GetArraySize(win_registry_ignore), 11); - cJSON *win_registry_ignore_regex = cJSON_GetObjectItem(sys_items, "key_ignore_sregex"); - assert_int_equal(cJSON_GetArraySize(win_registry_ignore_regex), 1); -#endif - - cJSON *allow_remote_prefilter_cmd = cJSON_GetObjectItem(sys_items, "allow_remote_prefilter_cmd"); - assert_string_equal(cJSON_GetStringValue(allow_remote_prefilter_cmd), "no"); - cJSON *prefilter_cmd = cJSON_GetObjectItem(sys_items, "prefilter_cmd"); - assert_null(prefilter_cmd); - - cJSON *sys_synchronization = cJSON_GetObjectItem(sys_items, "synchronization"); - cJSON *synchronization_enabled = cJSON_GetObjectItem(sys_synchronization, "enabled"); - assert_string_equal(cJSON_GetStringValue(synchronization_enabled), "no"); - cJSON *synchronization_interval = cJSON_GetObjectItem(sys_synchronization, "interval"); - assert_int_equal(synchronization_interval->valueint, 600); - - cJSON *database = cJSON_GetObjectItem(sys_items, "database"); - assert_string_equal(cJSON_GetStringValue(database), "memory"); -} - -#ifndef TEST_WINAGENT -void test_getSyscheckConfig_no_directories(void **state) -{ - (void) state; - cJSON * ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - - Read_Syscheck_Config("test_empty_config.conf"); - - ret = getSyscheckConfig(); - - assert_null(ret); -} -#else -void test_getSyscheckConfig_no_directories(void **state) -{ - (void) state; - cJSON * ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - - Read_Syscheck_Config("test_empty_config.conf"); - - ret = getSyscheckConfig(); - - - assert_non_null(ret); - assert_int_equal(cJSON_GetArraySize(ret), 1); - - cJSON *sys_items = cJSON_GetObjectItem(ret, "syscheck"); - assert_int_equal(cJSON_GetArraySize(sys_items), 18); - cJSON *disabled = cJSON_GetObjectItem(sys_items, "disabled"); - assert_string_equal(cJSON_GetStringValue(disabled), "yes"); - cJSON *frequency = cJSON_GetObjectItem(sys_items, "frequency"); - assert_int_equal(frequency->valueint, 43200); - - cJSON *file_limit = cJSON_GetObjectItem(sys_items, "file_limit"); - cJSON *file_limit_enabled = cJSON_GetObjectItem(file_limit, "enabled"); - assert_string_equal(cJSON_GetStringValue(file_limit_enabled), "yes"); - cJSON *file_limit_entries = cJSON_GetObjectItem(file_limit, "entries"); - assert_int_equal(file_limit_entries->valueint, 100000); - - cJSON *registry_limit = cJSON_GetObjectItem(sys_items, "registry_limit"); - cJSON *registry_limit_enabled = cJSON_GetObjectItem(registry_limit, "enabled"); - assert_string_equal(cJSON_GetStringValue(registry_limit_enabled), "yes"); - cJSON *registry_limit_entries = cJSON_GetObjectItem(registry_limit, "entries"); - - assert_int_equal(registry_limit_entries->valueint, 100000); - - cJSON *diff = cJSON_GetObjectItem(sys_items, "diff"); - - cJSON *disk_quota = cJSON_GetObjectItem(diff, "disk_quota"); - cJSON *disk_quota_enabled = cJSON_GetObjectItem(disk_quota, "enabled"); - assert_string_equal(cJSON_GetStringValue(disk_quota_enabled), "yes"); - cJSON *disk_quota_limit = cJSON_GetObjectItem(disk_quota, "limit"); - assert_int_equal(disk_quota_limit->valueint, 1024 * 1024); - - cJSON *file_size = cJSON_GetObjectItem(diff, "file_size"); - cJSON *file_size_enabled = cJSON_GetObjectItem(file_size, "enabled"); - assert_string_equal(cJSON_GetStringValue(file_size_enabled), "yes"); - cJSON *file_size_limit = cJSON_GetObjectItem(file_size, "limit"); - assert_int_equal(file_size_limit->valueint, 50 * 1024); - - cJSON *skip_nfs = cJSON_GetObjectItem(sys_items, "skip_nfs"); - assert_string_equal(cJSON_GetStringValue(skip_nfs), "yes"); - cJSON *skip_dev = cJSON_GetObjectItem(sys_items, "skip_dev"); - assert_string_equal(cJSON_GetStringValue(skip_dev), "yes"); - cJSON *skip_sys = cJSON_GetObjectItem(sys_items, "skip_sys"); - assert_string_equal(cJSON_GetStringValue(skip_sys), "yes"); - cJSON *skip_proc = cJSON_GetObjectItem(sys_items, "skip_proc"); - assert_string_equal(cJSON_GetStringValue(skip_proc), "yes"); - cJSON *scan_on_start = cJSON_GetObjectItem(sys_items, "scan_on_start"); - assert_string_equal(cJSON_GetStringValue(scan_on_start), "yes"); - cJSON *windows_audit_interval = cJSON_GetObjectItem(sys_items, "windows_audit_interval"); - assert_int_equal(windows_audit_interval->valueint, 0); - cJSON *registry = cJSON_GetObjectItem(sys_items, "registry"); - assert_int_equal(cJSON_GetArraySize(registry), 0); - cJSON *allow_remote_prefilter_cmd = cJSON_GetObjectItem(sys_items, "allow_remote_prefilter_cmd"); - assert_string_equal(cJSON_GetStringValue(allow_remote_prefilter_cmd), "no"); - cJSON *max_eps = cJSON_GetObjectItem(sys_items, "max_eps"); - assert_int_equal(max_eps->valueint, 50); - cJSON *process_priority = cJSON_GetObjectItem(sys_items, "process_priority"); - assert_int_equal(process_priority->valueint, 10); - - cJSON *synchronization = cJSON_GetObjectItem(sys_items, "synchronization"); - assert_int_equal(cJSON_GetArraySize(synchronization), 8); - cJSON *enabled = cJSON_GetObjectItem(synchronization, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "yes"); - cJSON *interval = cJSON_GetObjectItem(synchronization, "interval"); - assert_int_equal(interval->valueint, 300); - cJSON *sync_max_eps = cJSON_GetObjectItem(synchronization, "max_eps"); - assert_int_equal(sync_max_eps->valueint, 10); -} -#endif - -void test_SyscheckConf_DirectoriesWithCommas(void **state) { - (void) state; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - - ret = Read_Syscheck_Config("test_syscheck3.conf"); - assert_int_equal(ret, 0); - - #ifdef WIN32 - assert_string_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path, "c:\\,testcommas"); - assert_string_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))->path, "c:\\test,commas"); - assert_string_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 2))->path, "c:\\testcommas,"); - #else - assert_string_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path, "/,testcommas"); - assert_string_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))->path, "/test,commas"); - assert_string_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 2))->path, "/testcommas,"); - #endif -} - -void test_getSyscheckInternalOptions(void **state) -{ - (void) state; - cJSON * ret; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_any_always(__wrap__mdebug1, formatted_msg); - - Read_Syscheck_Config("test_syscheck.conf"); - - ret = getSyscheckInternalOptions(); - *state = ret; - - assert_non_null(ret); - assert_int_equal(cJSON_GetArraySize(ret), 1); - cJSON *items = cJSON_GetObjectItem(ret, "internal"); - assert_int_equal(cJSON_GetArraySize(items), 2); - cJSON *sys_items = cJSON_GetObjectItem(items, "syscheck"); - assert_int_equal(cJSON_GetArraySize(sys_items), 6); - cJSON *root_items = cJSON_GetObjectItem(items, "rootcheck"); - assert_int_equal(cJSON_GetArraySize(root_items), 1); -} - -void test_fim_create_directory_add_new_entry(void **state) { - const char *path = "./mock_path"; - int options = CHECK_FOLLOW; - const char *filerestrict = "restrict"; - int recursion_level = 0; - const char *tag = "mock_tag"; - int diff_size_limit = 0; - unsigned int is_wildcard = 0; - directory_t *new_entry; - entry_struct_t *test_struct = *state; - - new_entry = fim_create_directory(path, options, filerestrict, recursion_level, tag, diff_size_limit, is_wildcard); - test_struct->dir1 = new_entry; - - assert_non_null(new_entry); - assert_string_equal(tag, new_entry->tag); - assert_string_equal(path, new_entry->path); - assert_int_equal(is_wildcard, new_entry->is_wildcard); -} - -void test_fim_create_directory_OSMatch_Compile_fail_maxsize(void **state) { - const char *path = "./mock_path"; - int recursion_level = 0; - const char *tag = "mock_tag"; - int options = CHECK_FOLLOW; - int diff_size_limit = 0; - unsigned int is_wildcard = 0; - directory_t *new_entry; - char error_msg[OS_MAXSTR + 1]; - entry_struct_t *test_struct = *state; - - test_struct->filerestrict = calloc(OS_PATTERN_MAXSIZE + 2, sizeof(char)); - memset(test_struct->filerestrict, 'a', OS_PATTERN_MAXSIZE + 1); - - snprintf(error_msg, OS_MAXSTR, REGEX_COMPILE, test_struct->filerestrict, OS_REGEX_MAXSIZE); - - expect_string(__wrap__merror, formatted_msg, error_msg); - - new_entry = fim_create_directory(path, options, test_struct->filerestrict, recursion_level, tag, diff_size_limit, is_wildcard); - test_struct->dir1 = new_entry; - assert_non_null(new_entry); - assert_string_equal(tag, new_entry->tag); -} - -void test_fim_insert_directory_duplicate_entry(void **state) { - OSList list; - OSListNode first_list_node; - entry_struct_t *test_struct = *state; - - test_struct->dir1 = calloc(1, sizeof(directory_t)); - test_struct->dir2 = calloc(1, sizeof(directory_t)); - - test_struct->dir2->path = strdup("same_path"); - test_struct->dir2->tag = strdup("new_entry_tag"); - first_list_node.data = test_struct->dir1; - list.first_node = &first_list_node; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - test_struct->dir1->path = strdup(test_struct->dir2->path); - fim_insert_directory(&list, test_struct->dir2); - - assert_string_equal(test_struct->dir2->tag, ((directory_t*)(list.first_node->data))->tag); - // test_struct->dir1 is already freed. - test_struct->dir1 = NULL; - *state = test_struct; -} - -void test_fim_insert_directory_insert_entry_before(void **state) { - OSList list = {0}; - OSList_SetFreeDataPointer(&list, (void (*)(void *))free_directory); - OSListNode *first_list_node = calloc(1, sizeof(OSListNode)); - entry_struct_t *test_struct= *state; - - test_struct->dir1 = calloc(1, sizeof(directory_t)); - test_struct->dir2 = calloc(1, sizeof(directory_t)); - - test_struct->dir1->path = strdup("BPath"); - test_struct->dir2->path = strdup("APath"); - test_struct->dir2->tag = strdup("new_entry_tag"); - - first_list_node->data = test_struct->dir1; - list.first_node = first_list_node; - list.last_node = list.first_node; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - fim_insert_directory(&list, test_struct->dir2); - assert_string_equal(test_struct->dir2->tag, ((directory_t*)(list.first_node->data))->tag); - - OSList_CleanNodes(&list); - test_struct->dir1 = NULL; - test_struct->dir2 = NULL; -} - -void test_fim_insert_directory_insert_entry_last(void **state) { - OSList list = {0}; - - OSList_SetFreeDataPointer(&list, (void (*)(void *))free_directory); - OSListNode *first_list_node = calloc(1, sizeof(OSListNode)); - - entry_struct_t *test_struct = *state; - - test_struct->dir1 = calloc(1, sizeof(directory_t)); - test_struct->dir2 = calloc(1, sizeof(directory_t)); - - test_struct->dir1->path = strdup("APath"); - test_struct->dir2->path = strdup("BPath"); - test_struct->dir2->tag = strdup("new_entry_tag"); - - first_list_node->data = test_struct->dir1; - list.first_node = first_list_node; - list.last_node = list.first_node; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - fim_insert_directory(&list, test_struct->dir2); - assert_string_equal(test_struct->dir2->tag, ((directory_t*)(list.last_node->data))->tag); - - OSList_CleanNodes(&list); - - test_struct->dir1 = NULL; - test_struct->dir2 = NULL; -} - -void test_fim_copy_directory_null(void **state) { - directory_t *dir = NULL; - directory_t *return_dir; - - return_dir = fim_copy_directory(dir); - - assert_null(return_dir); - -} - -void test_fim_copy_directory_return_dir_copied(void **state) { - directory_t directory_copied; - directory_t *new_entry; - directory_copied.filerestrict = NULL; - directory_copied.path = "mock_path"; - directory_copied.options = 0; - directory_copied.recursion_level = 3; - directory_copied.tag = "mock_tag"; - directory_copied.diff_size_limit = 10; - directory_copied.is_wildcard = 0; - entry_struct_t *test_struct = *state; - - new_entry = fim_copy_directory(&directory_copied); - - assert_non_null(new_entry); - assert_string_equal(directory_copied.tag, new_entry->tag); - assert_string_equal(directory_copied.path, new_entry->path); - assert_int_equal(directory_copied.is_wildcard, new_entry->is_wildcard); - test_struct->dir1 = new_entry; -} - -void test_fim_adjust_path_no_changes (void **state) { - char *path = strdup("c:\\a\\path\\not\\replaced"); - - fim_adjust_path(&path); - - assert_string_equal(path, "c:\\a\\path\\not\\replaced"); - - free(path); -} - -void test_fim_adjust_path_convert_sysnative (void **state) { - char *path = strdup("C:\\windows\\sysnative\\test"); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6307): Convert 'c:\\windows\\sysnative\\test' to 'c:\\windows\\system32\\test' to process the FIM events."); - - fim_adjust_path(&path); - - assert_string_equal(path, "c:\\windows\\system32\\test"); - - free(path); -} - -void test_fim_adjust_path_convert_syswow64 (void **state) { - - char *path = strdup("C:\\windows\\syswow64\\test"); - - fim_adjust_path(&path); - - assert_string_equal(path, "c:\\windows\\syswow64\\test"); - - free(path); -} - -void test_fim_adjust_path_convert_system32 (void **state) { - - char *path = strdup("c:\\windows\\system32\\test"); - - fim_adjust_path(&path); - - assert_string_equal(path, "c:\\windows\\system32\\test"); - - free(path); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_Read_Syscheck_Config_success, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_Read_Syscheck_Config_invalid, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_Read_Syscheck_Config_undefined, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_Read_Syscheck_Config_unparsed, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_getSyscheckConfig, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_getSyscheckConfig_no_audit, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_getSyscheckConfig_no_directories, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_getSyscheckInternalOptions, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_SyscheckConf_DirectoriesWithCommas, setup_read_config, restart_syscheck), - cmocka_unit_test_setup_teardown(test_fim_create_directory_add_new_entry, setup_entry, teardown_entry), - cmocka_unit_test_setup_teardown(test_fim_create_directory_OSMatch_Compile_fail_maxsize, setup_entry, teardown_entry), - cmocka_unit_test_setup_teardown(test_fim_insert_directory_duplicate_entry, setup_entry, teardown_entry), - cmocka_unit_test_setup_teardown(test_fim_insert_directory_insert_entry_before, setup_entry, teardown_entry), - cmocka_unit_test_setup_teardown(test_fim_insert_directory_insert_entry_last, setup_entry, teardown_entry), - cmocka_unit_test(test_fim_copy_directory_null), - cmocka_unit_test_setup_teardown(test_fim_copy_directory_return_dir_copied, setup_entry, teardown_entry), - cmocka_unit_test(test_fim_adjust_path_no_changes), - cmocka_unit_test(test_fim_adjust_path_convert_sysnative), - cmocka_unit_test(test_fim_adjust_path_convert_syswow64), - cmocka_unit_test(test_fim_adjust_path_convert_system32) - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/syscheckd/test_fim.h b/src/unit_tests/syscheckd/test_fim.h deleted file mode 100644 index f5c6cbd249d..00000000000 --- a/src/unit_tests/syscheckd/test_fim.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __TEST_FIM_H -#define __TEST_FIM_H - -#include "../syscheckd/include/syscheck.h" -#include "../config/syscheck-config.h" - -#include "wrappers/posix/pthread_wrappers.h" -#include "wrappers/wazuh/shared/debug_op_wrappers.h" -#include "wrappers/wazuh/shared/mq_op_wrappers.h" - -/**********************************************************************************************************************\ - * Auxiliar expect functions -\**********************************************************************************************************************/ -void expect_fim_send_msg(char mq, const char *location, const char *msg, int retval); -void expect_send_syscheck_msg(const char *msg); - -void expect_fim_diff_delete_compress_folder(struct dirent *dir); - -cJSON *create_win_permissions_object(); - -/**********************************************************************************************************************\ - * Setups/Teardowns -\**********************************************************************************************************************/ -int setup_os_list(void **state); -int teardown_os_list(void **state); -int setup_rb_tree(void **state); -int teardown_rb_tree(void **state); - -#endif // __TEST_FIM_H diff --git a/src/unit_tests/syscheckd/test_fim_diff_changes.c b/src/unit_tests/syscheckd/test_fim_diff_changes.c deleted file mode 100644 index d19d0e18d2b..00000000000 --- a/src/unit_tests/syscheckd/test_fim_diff_changes.c +++ /dev/null @@ -1,2122 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../syscheckd/include/syscheck.h" -#include "../config/syscheck-config.h" -#include "../wrappers/wazuh/os_crypto/md5_op_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/libc/stdlib_wrappers.h" -#include "../wrappers/posix/stat_wrappers.h" - -#ifdef TEST_WINAGENT -#define CHECK_REGISTRY_ALL \ - CHECK_SIZE | CHECK_PERM | CHECK_OWNER | CHECK_GROUP | CHECK_MTIME | CHECK_MD5SUM | CHECK_SHA1SUM | \ - CHECK_SHA256SUM | CHECK_SEECHANGES | CHECK_TYPE - -static registry_t default_reg_config[] = { - { "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { "HKEY_LOCAL_MACHINE\\Software\\RecursionLevel0", ARCH_64BIT, CHECK_REGISTRY_ALL, 0, 0, NULL, NULL, NULL }, - { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { "HKEY_LOCAL_MACHINE_Invalid_key\\Software\\Ignore", ARCH_64BIT, CHECK_REGISTRY_ALL, 320, 0, NULL, NULL, NULL }, - { NULL, 0, 0, 320, 0, NULL, NULL, NULL } -}; - -static registry_ignore default_reg_ignore[] = { { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_32BIT}, - { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_64BIT}, - { NULL, 0} }; - -static registry_t default_reg_nodiff[] = { { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_32BIT}, - { "HKEY_LOCAL_MACHINE\\Software\\Ignore", ARCH_64BIT}, - { NULL, 0} }; - -static char *default_reg_ignore_regex_patterns[] = { "IgnoreRegex", "batfile", NULL }; - -static registry_ignore_regex default_reg_ignore_regex[] = { { NULL, ARCH_32BIT }, { NULL, ARCH_64BIT }, { NULL, 0 } }; - -#define KEY_NAME_HASHED "b9b175e8810d3475f15976dd3b5f9210f3af6604" -#define VALUE_NAME_HASHED "3f17670fd80d6563a3d4283adfe14140907b75b0" -#define FILE_NAME_HASHED "750621a746c8d786022a931ab9a99b918f7208f4" - -static const char GENERIC_PATH [OS_SIZE_256] = "c:\\file\\path"; -static const char COMPRESS_FOLDER_REG [OS_SIZE_256] = "queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED; -static const char COMPRESS_FOLDER [OS_SIZE_256] = "queue/diff/file/" FILE_NAME_HASHED ""; -static const char COMPRESS_FILE [OS_SIZE_256] = "queue/diff/file/" FILE_NAME_HASHED "/last-entry.gz"; -static const char UNCOMPRESS_FILE [OS_SIZE_256] = "queue/diff/tmp/tmp-entry"; -static const char COMPRESS_TMP_FILE [OS_SIZE_256] = "queue/diff/tmp/tmp-entry.gz"; - -#else - -#define FILE_NAME_HASHED "7cdbc5364a7aeb60f61d8fd2e6243056227bd6d3" - -static const char GENERIC_PATH [OS_SIZE_256] = "/path/to/file"; -static const char COMPRESS_FOLDER [OS_SIZE_256] = "queue/diff/file/" FILE_NAME_HASHED ""; -static const char COMPRESS_FILE [OS_SIZE_256] = "queue/diff/file/" FILE_NAME_HASHED "/last-entry.gz"; -static const char UNCOMPRESS_FILE [OS_SIZE_256] = "queue/diff/tmp/tmp-entry"; -static const char COMPRESS_TMP_FILE [OS_SIZE_256] = "queue/diff/tmp/tmp-entry.gz"; - -#endif - -static const char TMP_FOLDER [OS_SIZE_256] = "queue/diff/tmp"; - -static char *syscheck_nodiff[] = {"c:\\file\\nodiff", "/path/to/ignore", NULL}; - -static char *syscheck_nodiff_regex_patterns[] = {"regex", NULL}; -static OSMatch *syscheck_nodiff_regex[] = { NULL, NULL }; - -static const char *STR_MORE_CHANGES = "More changes..."; - -#define DEFAULT_OPTIONS \ - CHECK_MD5SUM | CHECK_SHA1SUM | CHECK_SHA256SUM | CHECK_PERM | CHECK_SIZE | CHECK_OWNER | CHECK_GROUP | \ - CHECK_MTIME | CHECK_INODE - -typedef struct gen_diff_struct { - diff_data *diff; - char **strarray; -} gen_diff_struct; - - -#ifdef TEST_WINAGENT -char *adapt_win_fc_output(char *command_output); -diff_data *initialize_registry_diff_data(const char *key_name, const char *value_name, const registry_t *configuration); -int fim_diff_registry_tmp(const char *value_data, DWORD data_type, const diff_data *diff); -#endif - -diff_data *initialize_file_diff_data(const char *filename); -char* filter(const char *string); -void free_diff_data(diff_data *diff); -int fim_diff_check_limits(diff_data *diff); -int fim_diff_delete_compress_folder(const char *folder); -int fim_diff_estimate_compression(float file_size); -int fim_diff_create_compress_file(const diff_data *diff); -void fim_diff_modify_compress_estimation(float compressed_size, float uncompressed_size); -int fim_diff_compare(const diff_data *diff); -void save_compress_file(const diff_data *diff); -int is_file_nodiff(const char *filename); -int is_registry_nodiff(const char *key_name, const char *value_name, int arch); -char *gen_diff_str(const diff_data *diff); -char *fim_diff_generate(const diff_data *diff); - -void expect_gen_diff_generate(gen_diff_struct *gen_diff_data_container) { - FILE *fp = (FILE*)2345; - size_t n = strlen(gen_diff_data_container->strarray[0]); - - expect_wfopen(gen_diff_data_container->diff->diff_file, "rb", fp); - - expect_fread(gen_diff_data_container->strarray[0], n); - - expect_fclose(fp, 0); - -#ifndef TEST_WINAGENT - expect_string(__wrap_unlink, file, gen_diff_data_container->diff->diff_file); - will_return(__wrap_unlink, 0); -#endif -} - -void expect_initialize_file_diff_data(const char *path, int ret_abspath){ - expect_abspath(path, ret_abspath); - if (!ret_abspath) { - expect_any(__wrap__merror, formatted_msg); - } else { -#ifdef TEST_WINAGENT - expect_abspath("queue/diff", 1); -#endif - } -} - -void expect_fim_diff_registry_tmp(const char *folder, const char *file, FILE *fp, const char *value_data) { - expect_mkdir_ex(folder, 0); - expect_wfopen(file, "w", fp); - if (fp){ - expect_fprintf(fp, value_data, 0); - expect_fclose(fp, 0); - } else { - expect_any(__wrap__merror, formatted_msg); - } - -} - -void expect_fim_diff_check_limits(const char *file_origin, const char *compress_folder, int ret) { - int file_size = 512 * 1024; - syscheck.file_size_enabled = 1; - syscheck.disk_quota_enabled = 0; - syscheck.disk_quota_limit = 1024; - - if (ret) { - file_size = 2048 * 1024; - if (ret == 2) { - syscheck.file_size_enabled = 0; - syscheck.disk_quota_enabled = 1; - } - } - - expect_FileSize(file_origin, file_size); - - if (ret == 1){ - expect_string(__wrap_IsDir, file, compress_folder); - will_return(__wrap_IsDir, -1); - } -} - -void expect_fim_diff_create_compress_file(const char *file_origin, const char *compress_tmp_file, int ret) { - syscheck.disk_quota_enabled = 0; - - expect_string(__wrap_w_compress_gzfile, filesrc, file_origin); - expect_string(__wrap_w_compress_gzfile, filedst, compress_tmp_file); - will_return(__wrap_w_compress_gzfile, ret); -} - -void expect_save_compress_file(const char *compress_tmp_file, const char *compress_file, int rename_fail) { - syscheck.disk_quota_enabled = 0; - - expect_rename_ex(compress_tmp_file, compress_file, rename_fail); -} - -void expect_fim_diff_compare(const char *uncompress_file, const char *file_origin, os_md5 md5sum_old, os_md5 md5sum_new, int ret) { - expect_OS_MD5_File_call(uncompress_file, md5sum_old, OS_BINARY, ret); - if (!ret) { - expect_OS_MD5_File_call(file_origin, md5sum_new, OS_BINARY, ret); - } -} - -void expect_fim_diff_generate(gen_diff_struct *gen_diff_data_container, int generate_fail) { - if (generate_fail) { - expect_system(-1); - } else { -#ifndef TEST_WINAGENT - expect_system(256); -#else - expect_system(1); -#endif - expect_gen_diff_generate(gen_diff_data_container); - } -} - -void expect_fim_diff_delete_compress_folder(const char *folder, int isDir_ret, int rmdir_ex_ret, int remove_empty_folder_ret) { - syscheck.diff_folder_size = -1; - - expect_string(__wrap_IsDir, file, folder); - will_return(__wrap_IsDir, isDir_ret); - - if (isDir_ret != -1) { - expect_string(__wrap_DirSize, path, folder); - will_return(__wrap_DirSize, 1024 * 1024); - - expect_string(__wrap_rmdir_ex, name, folder); - will_return(__wrap_rmdir_ex, rmdir_ex_ret); - - if (rmdir_ex_ret >= 0) { - expect_string(__wrap_remove_empty_folders, folder, folder); - expect_any(__wrap__mdebug2, formatted_msg); - will_return(__wrap_remove_empty_folders, remove_empty_folder_ret); - } else { - expect_any(__wrap__mdebug2, formatted_msg); - } - } -} - -/* Setup/teardown */ - -static int setup_group(void **state) { - - // No diff - for (int i = 0; syscheck_nodiff_regex_patterns[i]; i++) { - syscheck_nodiff_regex[i] = calloc(1, sizeof(OSMatch)); - - if (syscheck_nodiff_regex[i] == NULL) { - return -1; - } - - if (!OSMatch_Compile(syscheck_nodiff_regex_patterns[i], syscheck_nodiff_regex[i], 0)) { - return -1; - } - } - syscheck.nodiff = syscheck_nodiff; - syscheck.nodiff_regex = syscheck_nodiff_regex; - -#ifdef TEST_WINAGENT - syscheck.registry = default_reg_config; - - // Ignore registries - for (int i = 0; default_reg_ignore_regex_patterns[i]; i++) { - default_reg_ignore_regex[i].regex = calloc(1, sizeof(OSMatch)); - - if (default_reg_ignore_regex[i].regex == NULL) { - return -1; - } - - if (!OSMatch_Compile(default_reg_ignore_regex_patterns[i], default_reg_ignore_regex[i].regex, 0)) { - return -1; - } - } - syscheck.key_ignore = default_reg_ignore; - syscheck.key_ignore_regex = default_reg_ignore_regex; - - // No diff registries - syscheck.registry_nodiff = default_reg_nodiff; - syscheck.registry_nodiff_regex = default_reg_ignore_regex; -#endif - - test_mode = 1; - - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - - return 0; -} - -static int teardown_free_string(void **state) { - char * string = *state; - free(string); - return 0; -} - -static int setup_diff_data(void **state) { - diff_data *diff = calloc(1, sizeof(diff_data)); - if (!diff) { - return 1; - } - - *state = diff; - - return 0; -} - -static int teardown_free_diff_data(void **state) { - diff_data *diff = *state; - - free_diff_data(diff); - - return 0; -} - -static int teardown_disk_quota_exceeded(void **state) { - syscheck.disk_quota_full_msg = false; - return 0; -} - -static int setup_array_strings(void **state) { - char **strarray = calloc(2, sizeof(char*)); - - if(strarray == NULL) - return -1; - - *state = strarray; - - return 0; -} - -static int teardown_array_strings(void **state) { - char **strarray = *state; - - free(strarray[0]); - free(strarray[1]); - free(strarray); - - return 0; -} - -static int setup_gen_diff_str(void **state) { - gen_diff_struct *gen_diff_data_container = calloc(1, sizeof(gen_diff_struct)); - - if(gen_diff_data_container == NULL) - return -1; - - setup_array_strings((void **)&gen_diff_data_container->strarray); - setup_diff_data((void **)&gen_diff_data_container->diff); - -#ifdef TEST_WINAGENT - gen_diff_data_container->strarray[0] = strdup( - "Comparing files start.txt and end.txt\r\n" - "***** start.txt\r\n" - " 1: First line\r\n" - "***** END.TXT\r\n" - " 1: First Line 123\r\n" - " 2: Last line\r\n" - "*****\r\n\r\n\r\n"); -#else - gen_diff_data_container->strarray[0] = strdup( - "< First line\n" - "---\n" - "> First Line 123\n" - "> Last line\n"); -#endif - if(gen_diff_data_container->strarray[0] == NULL) fail(); - - char *output = strdup( - "< First line\n" - "---\n" - "> First Line 123\n" - "> Last line\n"); - - if(output == NULL) fail(); - gen_diff_data_container->strarray[1] = output; - - *state = gen_diff_data_container; - - return 0; -} - -static int teardown_free_gen_diff_str(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - - teardown_array_strings((void **)&gen_diff_data_container->strarray); - - teardown_free_diff_data((void **)&gen_diff_data_container->diff); - os_free(gen_diff_data_container); - - return 0; -} - -#ifdef TEST_WINAGENT -static int setup_full_diff_functionality(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - - setup_gen_diff_str(state); - - syscheck.registry_nodiff = NULL; - syscheck.registry_nodiff_regex = NULL; - - return 0; -} - -static int teardown_full_diff_functionality(void **state) { - teardown_free_gen_diff_str(state); - - syscheck.registry_nodiff = default_reg_nodiff; - syscheck.registry_nodiff_regex = default_reg_ignore_regex; - - return 0; -} -#endif - -/**********************************************************************************************************************\ - * Tests -\**********************************************************************************************************************/ - -void test_filter(void **state) { - (void) state; - -#ifdef TEST_WINAGENT - const char * file_name = "a/unix/style/path/"; -#else - const char * file_name = "$file/$test"; -#endif - - char * out = filter(file_name); - *state = out; - assert_non_null(out); - -#ifdef TEST_WINAGENT - assert_string_equal(out, "a\\unix\\style\\path\\"); -#else - assert_string_equal(out, "\\$file/\\$test"); -#endif -} - -// Windows test - -#ifdef TEST_WINAGENT -void test_filter_unchanged_string(void **state) { - char *input = "This string wont change"; - char *output; - - output = filter(input); - - *state = output; - - assert_string_equal(output, input); -} - -void test_filter_percentage_char(void **state) { - char *input = "This % is not valid"; - char *output; - - output = filter(input); - - assert_null(output); -} - -void test_adapt_win_fc_output_success(void **state) { - char **strarray = *state; - char *output; - char *input = strdup( - "Comparing files start.txt and end.txt\r\n" - "***** start.txt\r\n" - " 1: First line\r\n" - "***** END.TXT\r\n" - " 1: First Line 123\r\n" - " 2: Last line\r\n" - "*****\r\n\r\n\r\n"); - - if(input == NULL) fail(); - - strarray[0] = input; - - output = adapt_win_fc_output(input); - - assert_non_null(output); - - strarray[1] = output; - - assert_string_equal(output, "< First line\n---\n> First Line 123\n> Last line\n"); -} - -void test_adapt_win_fc_output_invalid_input(void **state) { - char **strarray = *state; - char *output; - char *input = strdup("This is invalid"); - - if(input == NULL) fail(); - - strarray[0] = input; - - expect_string(__wrap__mdebug2, formatted_msg, "(6667): Unable to find second line of alert string.: This is invalid"); - - output = adapt_win_fc_output(input); - - assert_non_null(output); - - strarray[1] = output; - - assert_string_equal(output, input); -} - -void test_adapt_win_fc_output_no_differences(void **state) { - char **strarray = *state; - char *output; - char *input = strdup( - "Comparing files start.txt and end.txt\r\n" - "FC: no differences encountered\r\n\r\n\r\n"); - - if(input == NULL) fail(); - - strarray[0] = input; - - output = adapt_win_fc_output(input); - - assert_non_null(output); - - strarray[1] = output; - - assert_string_equal(output, ""); -} - -void test_initialize_registry_diff_data(void **state) { - diff_data *diff = *state; - registry_t *configuration = &syscheck.registry[0]; - - diff = initialize_registry_diff_data("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile", "valuename", configuration); - - assert_non_null(diff); - assert_string_equal(diff->compress_folder, COMPRESS_FOLDER_REG); - assert_string_equal(diff->compress_file, "queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz"); - assert_string_equal(diff->tmp_folder, "queue/diff/tmp"); - assert_string_equal(diff->file_origin, "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED); - assert_string_equal(diff->uncompress_file, "queue/diff/tmp/tmp-entry"); - assert_string_equal(diff->compress_tmp_file, "queue/diff/tmp/tmp-entry.gz"); - assert_string_equal(diff->diff_file, "queue/diff/tmp/diff-file"); -} - -void test_initialize_file_diff_data(void **state) { - diff_data *diff = *state; - - expect_abspath("C:\\path\\to\\file", 1); - expect_abspath("queue/diff", 1); - - diff = initialize_file_diff_data("C:\\path\\to\\file"); - - assert_non_null(diff); - assert_string_equal(diff->compress_folder, "queue/diff/file/95632dd0fe0cc86cd21b6b7cf6d9db8d0cc1fe6c"); - assert_string_equal(diff->compress_file, "queue/diff/file/95632dd0fe0cc86cd21b6b7cf6d9db8d0cc1fe6c/last-entry.gz"); - assert_string_equal(diff->tmp_folder, "queue/diff/tmp"); - assert_string_equal(diff->file_origin, "C:\\path\\to\\file"); - assert_string_equal(diff->uncompress_file, "queue/diff/tmp/tmp-entry"); - assert_string_equal(diff->compress_tmp_file, "queue/diff/tmp/tmp-entry.gz"); - assert_string_equal(diff->diff_file, "queue/diff/tmp/diff-file"); -} - -#else // END TEST_WINAGENT - -void test_initialize_file_diff_data(void **state) { - diff_data *diff; - - expect_abspath(GENERIC_PATH, 1); - - diff = initialize_file_diff_data(GENERIC_PATH); - *state = diff; - - assert_non_null(diff); - assert_string_equal(diff->compress_folder, COMPRESS_FOLDER); - assert_string_equal(diff->compress_file, COMPRESS_FILE); - assert_string_equal(diff->tmp_folder, TMP_FOLDER); - assert_string_equal(diff->file_origin, GENERIC_PATH); - assert_string_equal(diff->uncompress_file, UNCOMPRESS_FILE); - assert_string_equal(diff->compress_tmp_file, COMPRESS_TMP_FILE); - assert_string_equal(diff->diff_file, "queue/diff/tmp/diff-file"); -} - -#endif // END TEST_AGENT and TEST_SERVER - -void test_initialize_file_diff_data_abspath_fail(void **state) { - diff_data *diff = *state; - - expect_abspath(GENERIC_PATH, 0); - errno = 0; -#ifdef TEST_WINAGENT - expect_string(__wrap__merror, formatted_msg, "(6711): Cannot get absolute path of 'c:\\file\\path': Success (0)"); -#else - expect_string(__wrap__merror, formatted_msg, "(6711): Cannot get absolute path of '/path/to/file': Success (0)"); -#endif - diff = initialize_file_diff_data(GENERIC_PATH); - - assert_null(diff); -} - -void test_fim_diff_check_limits(void **state) { - diff_data *diff = *state; - - diff->size_limit = 2048; - diff->file_origin = strdup(GENERIC_PATH); - syscheck.file_size_enabled = 1; - - expect_FileSize(diff->file_origin, 1024 * 1024); - - int ret = fim_diff_check_limits(diff); - - assert_int_equal(ret, 0); -} - -void test_fim_diff_check_limits_size_limit_reached(void **state) { - diff_data *diff = *state; - - diff->size_limit = 1024; - diff->file_origin = strdup(GENERIC_PATH); - diff->compress_folder = strdup(COMPRESS_FOLDER); - syscheck.file_size_enabled = 1; - - expect_FileSize(diff->file_origin, 2048 * 1024); - - expect_string(__wrap_IsDir, file, diff->compress_folder); - will_return(__wrap_IsDir, -1); - - int ret = fim_diff_check_limits(diff); - - assert_int_equal(ret, 1); -} - -void test_fim_diff_check_limits_estimate_compression(void **state) { - diff_data *diff = *state; - - diff->size_limit = 2048; - diff->file_origin = strdup(GENERIC_PATH); - syscheck.file_size_enabled = 0; - syscheck.disk_quota_enabled = 1; - - expect_FileSize(diff->file_origin, 1024 * 1024); - - int ret = fim_diff_check_limits(diff); - - assert_int_equal(ret, 2); -} - -void test_fim_diff_delete_compress_folder(void **state) { - char *folder = strdup("/path/to/folder"); - - syscheck.diff_folder_size = -1; - - expect_string(__wrap_IsDir, file, folder); - will_return(__wrap_IsDir, 0); - - expect_string(__wrap_DirSize, path, folder); - will_return(__wrap_DirSize, 1024 * 1024); - - expect_string(__wrap_rmdir_ex, name, folder); - will_return(__wrap_rmdir_ex, 0); - - expect_string(__wrap_remove_empty_folders, folder, folder); - will_return(__wrap_remove_empty_folders, 0); - - expect_any(__wrap__mdebug2, formatted_msg); - - int ret = fim_diff_delete_compress_folder(folder); - - os_free(folder); - - assert_int_equal(ret, 0); -} - -void test_fim_diff_delete_compress_folder_no_dir(void **state) { - char *folder = strdup("/path/to/folder"); - - syscheck.diff_folder_size = -1; - - expect_string(__wrap_IsDir, file, folder); - will_return(__wrap_IsDir, -1); - - int ret = fim_diff_delete_compress_folder(folder); - - os_free(folder); - - assert_int_equal(ret, -2); -} - -void test_fim_diff_delete_compress_folder_rmdir_ex_fail(void **state) { - char *folder = strdup("/path/to/folder"); - - syscheck.diff_folder_size = -1; - - expect_string(__wrap_IsDir, file, folder); - will_return(__wrap_IsDir, 0); - - expect_string(__wrap_DirSize, path, folder); - will_return(__wrap_DirSize, 1024 * 1024); - - expect_string(__wrap_rmdir_ex, name, folder); - will_return(__wrap_rmdir_ex, -1); - - expect_any(__wrap__mdebug2, formatted_msg); - - int ret = fim_diff_delete_compress_folder(folder); - - os_free(folder); - - assert_int_equal(ret, -1); -} - -void test_fim_diff_delete_compress_folder_remove_folder_fail(void **state) { - char *folder = strdup("/path/to/folder"); - - syscheck.diff_folder_size = -1; - - expect_string(__wrap_IsDir, file, folder); - will_return(__wrap_IsDir, 0); - - expect_string(__wrap_DirSize, path, folder); - will_return(__wrap_DirSize, 1024 * 1024); - - expect_string(__wrap_rmdir_ex, name, folder); - will_return(__wrap_rmdir_ex, 0); - - expect_string(__wrap_remove_empty_folders, folder, folder); - will_return(__wrap_remove_empty_folders, -1); - - int ret = fim_diff_delete_compress_folder(folder); - - os_free(folder); - - assert_int_equal(ret, -1); -} - -void test_fim_diff_estimate_compression_file_not_fit(void **state) { - syscheck.diff_folder_size = 10240; - syscheck.disk_quota_limit = 10240; - - int ret = fim_diff_estimate_compression(1024); - - assert_int_equal(ret, 0); -} - -void test_fim_diff_estimate_compression_ok(void **state) { - syscheck.diff_folder_size = 5120; - syscheck.disk_quota_limit = 10240; - - int ret = fim_diff_estimate_compression(1024); - - assert_int_equal(ret, 1); -} - -void test_fim_diff_create_compress_file_fail_compress(void **state) { - diff_data *diff = *state; - diff->file_origin = strdup("/path/file/origin"); - diff->compress_tmp_file = strdup("/path/compress/tmp/file"); - - expect_string(__wrap_w_compress_gzfile, filesrc, diff->file_origin); - expect_string(__wrap_w_compress_gzfile, filedst, diff->compress_tmp_file); - will_return(__wrap_w_compress_gzfile, -1); - - expect_string(__wrap__mwarn, formatted_msg, "(6914): Cannot create a snapshot of file '/path/file/origin'"); - - int ret = fim_diff_create_compress_file(diff); - - assert_int_equal(ret, -1); -} - -void test_fim_diff_create_compress_file_ok(void **state) { - diff_data *diff = *state; - diff->file_origin = strdup("/path/file/origin"); - diff->compress_tmp_file = strdup("/path/compress/tmp/file"); - syscheck.disk_quota_enabled = 1; - syscheck.diff_folder_size = 5120; - syscheck.disk_quota_limit = 10240; - - expect_string(__wrap_w_compress_gzfile, filesrc, diff->file_origin); - expect_string(__wrap_w_compress_gzfile, filedst, diff->compress_tmp_file); - will_return(__wrap_w_compress_gzfile, 0); - - expect_FileSize(diff->compress_tmp_file, 1024 * 1024); - - int ret = fim_diff_create_compress_file(diff); - - assert_int_equal(ret, 0); -} - -void test_fim_diff_create_compress_file_quota_reached(void **state) { - diff_data *diff = *state; - diff->file_origin = strdup("/path/file/origin"); - diff->compress_tmp_file = strdup("/path/compress/tmp/file"); - syscheck.disk_quota_enabled = 1; - syscheck.diff_folder_size = 10240; - syscheck.disk_quota_limit = 10240; - syscheck.disk_quota_full_msg = true; - - expect_string(__wrap_w_compress_gzfile, filesrc, diff->file_origin); - expect_string(__wrap_w_compress_gzfile, filedst, diff->compress_tmp_file); - will_return(__wrap_w_compress_gzfile, 0); - - expect_FileSize(diff->compress_tmp_file, 1024 * 1024); - - expect_string(__wrap__mdebug2, formatted_msg, "(6350): The calculate of the file size '/path/file/origin' exceeds the disk_quota. Operation discarded."); - - int ret = fim_diff_create_compress_file(diff); - - assert_int_equal(ret, -2); -} - -void test_fim_diff_modify_compress_estimation_small_compresion_rate(void **state) { - syscheck.comp_estimation_perc = 0.9; - - fim_diff_modify_compress_estimation(10240, 10240); - - // Rate unmodified - assert_float_equal(syscheck.comp_estimation_perc, 0.9, 0.001); -} - -void test_fim_diff_modify_compress_estimation_MIN_COMP_ESTIM(void **state) { - syscheck.comp_estimation_perc = 0.6; - - fim_diff_modify_compress_estimation(9216, 10240); - - // Rate set at minimun - assert_float_equal(syscheck.comp_estimation_perc, 0.4, 0.001); -} - -void test_fim_diff_modify_compress_estimation_ok(void **state) { - syscheck.comp_estimation_perc = 0.9; - - fim_diff_modify_compress_estimation(5120, 10240); - - // Rate modified - assert_float_equal(syscheck.comp_estimation_perc, 0.7, 0.001); -} - -void test_fim_diff_compare_fail_uncompress_MD5(void **state) { - diff_data *diff = *state; - diff->uncompress_file = strdup("/path/to/uncompress/file"); - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - - expect_OS_MD5_File_call(diff->uncompress_file, md5sum_old, OS_BINARY, -1); - - int ret = fim_diff_compare(diff); - - assert_int_equal(ret, -1); -} - -void test_fim_diff_compare_fail_origin_MD5(void **state) { - diff_data *diff = *state; - diff->uncompress_file = strdup("/path/to/uncompress/file"); - diff->file_origin = strdup("/path/to/original/file"); - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "3c183a30cffcda1408daf1c61d47b274"; - - expect_OS_MD5_File_call(diff->uncompress_file, md5sum_old, OS_BINARY, 0); - expect_OS_MD5_File_call(diff->file_origin, md5sum_new, OS_BINARY, 0); - - int ret = fim_diff_compare(diff); - - assert_int_equal(ret, -1); -} - -void test_fim_diff_compare_fail_not_match(void **state) { - diff_data *diff = *state; - diff->uncompress_file = strdup("/path/to/uncompress/file"); - diff->file_origin = strdup("/path/to/original/file"); - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - - expect_OS_MD5_File_call(diff->uncompress_file, md5sum_old, OS_BINARY, 0); - expect_OS_MD5_File_call(diff->file_origin, md5sum_new, OS_BINARY, 0); - - int ret = fim_diff_compare(diff); - - assert_int_equal(ret, 0); -} - -void test_fim_diff_compare_fail_match(void **state) { - diff_data *diff = *state; - diff->uncompress_file = strdup("/path/to/uncompress/file"); - diff->file_origin = strdup("/path/to/original/file"); - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "3c183a30cffcda1408daf1c61d47b274"; - - expect_OS_MD5_File_call(diff->uncompress_file, md5sum_old, OS_BINARY, 0); - expect_OS_MD5_File_call(diff->file_origin, md5sum_new, OS_BINARY, 0); - - int ret = fim_diff_compare(diff); - - assert_int_equal(ret, -1); -} - -void test_save_compress_file_ok(void **state) { - diff_data *diff = *state; - diff->compress_tmp_file = strdup("/path/to/compress/tmp/file"); - diff->compress_file = strdup("/path/to/compress/file"); - syscheck.disk_quota_enabled = 1; - syscheck.diff_folder_size = 0; - - expect_rename_ex(diff->compress_tmp_file, diff->compress_file, 0); - - expect_FileSize(diff->compress_file, 1024 * 1024); - - save_compress_file(diff); - assert_int_equal(syscheck.diff_folder_size, 1024); -} - -void test_save_compress_file_rename_fail(void **state) { - diff_data *diff = *state; - diff->compress_tmp_file = strdup("/path/to/compress/tmp/file"); - diff->compress_file = strdup("/path/to/compress/file"); - syscheck.disk_quota_enabled = 1; - syscheck.diff_folder_size = 0; - - expect_rename_ex(diff->compress_tmp_file, diff->compress_file, -1); - - expect_string(__wrap__merror, formatted_msg, "(1124): Could not rename file '/path/to/compress/tmp/file' to '/path/to/compress/file' due to [(0)-(Success)]."); - - save_compress_file(diff); - assert_int_equal(syscheck.diff_folder_size, 0); -} - -void test_is_file_nodiff_normal_check(void **state) { -#ifdef TEST_WINAGENT - int ret = is_file_nodiff("c:\\file\\nodiff"); -#else - int ret = is_file_nodiff("/path/to/ignore"); -#endif - assert_int_equal(ret, 1); -} - -void test_is_file_nodiff_regex_check(void **state) { - - int ret = is_file_nodiff("/file/nodiff/regex/"); - assert_int_equal(ret, 1); -} - -void test_is_file_nodiff_not_match(void **state) { - - int ret = is_file_nodiff("/file/nodiff/no_config"); - assert_int_equal(ret, 0); -} - -#ifdef TEST_WINAGENT -void test_is_registry_nodiff_normal_check(void **state) { - - int ret = is_registry_nodiff("HKEY_LOCAL_MACHINE\\Software", "Ignore", 1); - assert_int_equal(ret, 1); -} - -void test_is_registry_nodiff_regex_check(void **state) { - - int ret = is_registry_nodiff("HKEY_LOCAL_MACHINE\\Software", "batfile", 1); - assert_int_equal(ret, 1); -} - -void test_is_registry_nodiff_not_match(void **state) { - - int ret = is_registry_nodiff("HKEY_LOCAL_MACHINE\\Software", "RecursionLevel0", 1); - assert_int_equal(ret, 0); -} -#endif - -// gen_diff_str function tests - -void test_gen_diff_str_wfropen_fail(void **state) { - diff_data *diff = *state; - diff->diff_file = strdup("/path/to/diff/file"); - - expect_wfopen(diff->diff_file, "rb", NULL); - - expect_string(__wrap__merror, formatted_msg, "(6665): Unable to generate diff alert (fopen)'/path/to/diff/file'."); - - char *diff_str = gen_diff_str(diff); - assert_ptr_equal(diff_str, NULL); -} - -void test_gen_diff_str_fread_fail(void **state) { - diff_data *diff = *state; - diff->diff_file = strdup("/path/to/diff/file"); - FILE *fp = (FILE*)2345; - char *diff_contain = "diff_contain"; - - expect_wfopen(diff->diff_file, "rb", fp); - - expect_fread(diff_contain, 0); - - expect_fclose(fp, 0); - -#ifndef TEST_WINAGENT - expect_string(__wrap_unlink, file, "/path/to/diff/file"); - will_return(__wrap_unlink, 0); -#endif - - expect_string(__wrap__merror, formatted_msg, "(6666): Unable to generate diff alert (fread)."); - - char *diff_str = gen_diff_str(diff); - assert_ptr_equal(diff_str, NULL); -} - -void test_gen_diff_str_ok(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - gen_diff_data_container->diff->diff_file = strdup("/path/to/diff/file"); - - FILE *fp = (FILE*)2345; - size_t n = 145; - - expect_wfopen(gen_diff_data_container->diff->diff_file, "rb", fp); - - expect_fread(gen_diff_data_container->strarray[0], n); - - expect_fclose(fp, 0); - -#ifndef TEST_WINAGENT - expect_string(__wrap_unlink, file, "/path/to/diff/file"); - will_return(__wrap_unlink, 0); -#endif - - char *diff_str = gen_diff_str(gen_diff_data_container->diff); - assert_string_equal(diff_str, gen_diff_data_container->strarray[1]); - free(diff_str); -} - -#ifdef TEST_WINAGENT -void test_fim_diff_generate_filters_fail(void **state) { - diff_data *diff = *state; - diff->uncompress_file = strdup("\%wrong path"); - diff->file_origin = strdup("\%wrong path"); - diff->diff_file = strdup("\%wrong path"); - - expect_string(__wrap__mdebug1, formatted_msg, "(6200): Diff execution skipped for containing insecure characters."); - - char *diff_str = fim_diff_generate(diff); - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_diff_generate_status_equal(void **state) { - diff_data *diff = *state; - diff->uncompress_file = strdup("/path/to/uncompress/file"); - diff->file_origin = strdup("/path/to/file/origin"); - diff->diff_file = strdup("/path/to/diff/file"); - - expect_system(0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6352): Command diff/fc output 0, files are the same"); - - char *diff_str = fim_diff_generate(diff); - assert_ptr_equal(diff_str, NULL); -} -#endif - -void test_fim_diff_generate_status_error(void **state) { - diff_data *diff = *state; - - diff->uncompress_file = strdup("/path/to/uncompress/file"); - diff->file_origin = strdup("/path/to/file/origin"); - diff->diff_file = strdup("/path/to/diff/file"); - - expect_system(-1); - -#ifdef TEST_WINAGENT - expect_string(__wrap__merror, formatted_msg, "(6714): Command fc output an error"); -#else - expect_string(__wrap__merror, formatted_msg, "(6714): Command diff output an error"); -#endif - - char *diff_str = fim_diff_generate(diff); - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_diff_generate_status_ok(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - - gen_diff_data_container->diff->uncompress_file = strdup("/path/to/uncompress/file"); - gen_diff_data_container->diff->file_origin = strdup("/path/to/file/origin"); - gen_diff_data_container->diff->diff_file = strdup("/path/to/diff/file"); - -#ifndef TEST_WINAGENT - expect_system(256); -#else - expect_system(1); -#endif - - expect_gen_diff_generate(gen_diff_data_container); - - char *diff_str = fim_diff_generate(gen_diff_data_container->diff); - assert_string_equal(diff_str, gen_diff_data_container->strarray[1]); - free(diff_str); -} - -#ifdef TEST_WINAGENT -void test_fim_diff_registry_tmp_fopen_fail(void **state) { - diff_data *diff = *state; - diff->file_origin = strdup("/path/to/file/origin"); - diff->tmp_folder = strdup("/path/to/tmp/folder"); - FILE *fp = NULL; - const char *value_data = "value_data"; - DWORD data_type = 0; - - expect_mkdir_ex(diff->tmp_folder, 0); - - expect_wfopen(diff->file_origin, "w", fp); - - expect_string(__wrap__merror, formatted_msg, "(1103): Could not open file '/path/to/file/origin' due to [(2)-(No such file or directory)]."); - - int ret = fim_diff_registry_tmp(value_data, data_type, diff); - assert_int_equal(ret, -1); -} - -void test_fim_diff_registry_tmp_REG_SZ(void **state) { - diff_data *diff = *state; - diff->file_origin = "/path/to/file/origin"; - diff->tmp_folder = "/path/to/tmp/folder"; - FILE *fp = (FILE*)2345; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - - expect_mkdir_ex(diff->tmp_folder, 0); - - expect_wfopen(diff->file_origin, "w", fp); - - expect_fprintf(fp, value_data, 0); - - expect_fclose(fp, 0); - - int ret = fim_diff_registry_tmp(value_data, data_type, diff); - assert_int_equal(ret, 0); -} - -void test_fim_diff_registry_tmp_REG_MULTI_SZ(void **state) { - diff_data *diff = *state; - diff->file_origin = "/path/to/file/origin"; - diff->tmp_folder = "/path/to/tmp/folder"; - FILE *fp = (FILE*)2345; - const char *value_data = "value_data\0value_data2\0"; - const char *value_data_formatted = "value_data\n"; - const char *value_data_formatted2 = "value_data2\n"; - DWORD data_type = REG_MULTI_SZ; - - expect_mkdir_ex(diff->tmp_folder, 0); - - expect_wfopen(diff->file_origin, "w", fp); - - expect_fprintf(fp, value_data_formatted, 0); - expect_fprintf(fp, value_data_formatted2, 0); - - expect_fclose(fp, 0); - - int ret = fim_diff_registry_tmp((char *)value_data, data_type, diff); - assert_int_equal(ret, 0); -} - -void test_fim_diff_registry_tmp_REG_DWORD(void **state) { - diff_data *diff = *state; - diff->file_origin = "/path/to/file/origin"; - diff->tmp_folder = "/path/to/tmp/folder"; - FILE *fp = (FILE*)2345; - unsigned long value_data = 0x12345; - DWORD data_type = REG_DWORD; - - expect_mkdir_ex(diff->tmp_folder, 0); - - expect_wfopen(diff->file_origin, "w", fp); - - expect_fprintf(fp, "12345", 0); - - expect_fclose(fp, 0); - - int ret = fim_diff_registry_tmp((char *)&value_data, data_type, diff); - assert_int_equal(ret, 0); -} - -void test_fim_diff_registry_tmp_REG_DWORD_BIG_ENDIAN(void **state) { - diff_data *diff = *state; - diff->file_origin = "/path/to/file/origin"; - diff->tmp_folder = "/path/to/tmp/folder"; - FILE *fp = (FILE*)2345; - unsigned int value_data = 0x12345; - DWORD data_type = REG_DWORD_BIG_ENDIAN; - - expect_mkdir_ex(diff->tmp_folder, 0); - - expect_wfopen(diff->file_origin, "w", fp); - - expect_fprintf(fp, "45230100", 0); - - expect_fclose(fp, 0); - - int ret = fim_diff_registry_tmp((char *)&value_data, data_type, diff); - assert_int_equal(ret, 0); -} - -void test_fim_diff_registry_tmp_REG_QWORD(void **state) { - diff_data *diff = *state; - diff->file_origin = "/path/to/file/origin"; - diff->tmp_folder = "/path/to/tmp/folder"; - FILE *fp = (FILE*)2345; - unsigned long long value_data = 0x12345; - DWORD data_type = REG_QWORD; - - expect_mkdir_ex(diff->tmp_folder, 0); - - expect_wfopen(diff->file_origin, "w", fp); - - expect_fprintf(fp, "12345", 0); - - expect_fclose(fp, 0); - - int ret = fim_diff_registry_tmp((char *)&value_data, data_type, diff); - assert_int_equal(ret, 0); -} - -void test_fim_diff_registry_tmp_default_type(void **state) { - diff_data *diff = *state; - diff->file_origin = "/path/to/file/origin"; - diff->tmp_folder = "/path/to/tmp/folder"; - FILE *fp = (FILE*)2345; - const char *value_data = "value_data"; - DWORD data_type = -1; - - expect_mkdir_ex(diff->tmp_folder, 0); - - expect_wfopen(diff->file_origin, "w", fp); - - expect_string(__wrap__mwarn, formatted_msg, FIM_REG_VAL_WRONG_TYPE); - - expect_fclose(fp, 0); - - int ret = fim_diff_registry_tmp((char *)&value_data, data_type, diff); - assert_int_equal(ret, -1); -} - -void test_fim_registry_value_diff_wrong_data_type(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_NONE; - registry_t *configuration = &syscheck.registry[0]; - - char debug2_message[OS_SIZE_1024]; - snprintf(debug2_message, OS_SIZE_1024, FIM_REG_VAL_INVALID_TYPE, key_name, value_name); - expect_string(__wrap__mdebug2, formatted_msg, debug2_message); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_registry_value_diff_wrong_registry_tmp(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, NULL, value_data); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_registry_value_diff_wrong_too_big_file(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - configuration->diff_size_limit = 1024; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6349): File 'HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\valuename' is too big for configured maximum size to perform diff operation."); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_string_equal(diff_str, "Unable to calculate diff due to 'file_size' limit has been reached."); - - free(diff_str); -} - -void test_fim_registry_value_diff_wrong_quota_reached(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - configuration->diff_size_limit = 1024; - syscheck.comp_estimation_perc = 0.4; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 2); - - expect_string(__wrap__mdebug2, formatted_msg, "(6350): The estimation of the file size 'HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile\\valuename' exceeds the disk_quota. Operation discarded."); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_string_equal(diff_str, "Unable to calculate diff due to 'disk_quota' limit has been reached."); - - free(diff_str); -} - -void test_fim_registry_value_diff_uncompress_fail(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 0); - - expect_w_uncompress_gzfile("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", "queue/diff/tmp/tmp-entry", (FILE *)1234); - - expect_fim_diff_create_compress_file("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, "queue/diff/tmp/tmp-entry.gz", 0); - - expect_mkdir_ex(COMPRESS_FOLDER_REG, 0); - - expect_save_compress_file("queue/diff/tmp/tmp-entry.gz", "queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", 0); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_string_equal(diff_str, "Unable to calculate diff due to no previous data stored for this registry value."); - - free(diff_str); -} - -void test_fim_registry_value_diff_create_compress_fail(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 0); - - expect_w_uncompress_gzfile("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", "queue/diff/tmp/tmp-entry", NULL); - - expect_FileSize("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", 1024 * 1024); - - expect_fim_diff_create_compress_file("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, "queue/diff/tmp/tmp-entry.gz", -1); - - expect_string(__wrap__mwarn, formatted_msg, "(6914): Cannot create a snapshot of file 'queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED "'"); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_registry_value_diff_compare_fail(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "3c183a30cffcda1408daf1c61d47b274"; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 0); - - expect_w_uncompress_gzfile("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", "queue/diff/tmp/tmp-entry", NULL); - - expect_FileSize("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", 1024 * 1024); - - expect_fim_diff_create_compress_file("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, "queue/diff/tmp/tmp-entry.gz", 0); - - expect_fim_diff_compare("queue/diff/tmp/tmp-entry", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, md5sum_old, md5sum_new, -1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6351): The files are identical, don't compute differences"); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_string_equal(diff_str, "No content changes were found for this registry value."); - - free(diff_str); -} - -void test_fim_registry_value_diff_nodiff(void **state) { - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 0); - - expect_w_uncompress_gzfile("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", "queue/diff/tmp/tmp-entry", NULL); - - expect_FileSize("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", 1024 * 1024); - - expect_fim_diff_create_compress_file("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, "queue/diff/tmp/tmp-entry.gz", 0); - - expect_fim_diff_compare("queue/diff/tmp/tmp-entry", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, md5sum_old, md5sum_new, 0); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_string_equal(diff_str, "Diff truncated due to 'nodiff' configuration detected for this registry value."); - - free(diff_str); -} - -void test_fim_registry_value_diff_generate_fail(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - - gen_diff_data_container->diff->uncompress_file = "queue/diff/tmp/tmp-entry"; - gen_diff_data_container->diff->file_origin = "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED; - gen_diff_data_container->diff->diff_file = "queue/diff/tmp/diff-file"; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 0); - - expect_w_uncompress_gzfile("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", "queue/diff/tmp/tmp-entry", NULL); - - expect_FileSize("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", 1024 * 1024); - - expect_fim_diff_create_compress_file("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, "queue/diff/tmp/tmp-entry.gz", 0); - - expect_fim_diff_compare("queue/diff/tmp/tmp-entry", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, md5sum_old, md5sum_new, 0); - - expect_fim_diff_generate(gen_diff_data_container, 1); - - expect_string(__wrap__merror, formatted_msg, "(6714): Command fc output an error"); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_registry_value_diff_generate_diff_str(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - - const char *key_name = "HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"; - const char *value_name = "valuename"; - const char *value_data = "value_data"; - DWORD data_type = REG_EXPAND_SZ; - registry_t *configuration = &syscheck.registry[0]; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - - gen_diff_data_container->diff->uncompress_file = "queue/diff/tmp/tmp-entry"; - gen_diff_data_container->diff->file_origin = "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED; - gen_diff_data_container->diff->diff_file = "queue/diff/tmp/diff-file"; - - expect_fim_diff_registry_tmp("queue/diff/tmp", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, (FILE *)1234, value_data); - - expect_fim_diff_check_limits("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, COMPRESS_FOLDER_REG, 0); - - expect_w_uncompress_gzfile("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", "queue/diff/tmp/tmp-entry", NULL); - - expect_FileSize("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", 1024 * 1024); - - expect_fim_diff_create_compress_file("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, "queue/diff/tmp/tmp-entry.gz", 0); - - expect_fim_diff_compare("queue/diff/tmp/tmp-entry", "queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED, md5sum_old, md5sum_new, 0); - - expect_fim_diff_generate(gen_diff_data_container, 0); - - expect_save_compress_file("queue/diff/tmp/tmp-entry.gz", "queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED "/last-entry.gz", 0); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/tmp"); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_registry_value_diff(key_name, value_name, value_data, data_type, configuration); - - assert_string_equal(diff_str, gen_diff_data_container->strarray[1]); -} -#endif - -void test_fim_file_diff_wrong_initialize(void **state) { - const char *filename = GENERIC_PATH; - const directory_t configuration = { .diff_size_limit = 0 }; - - expect_initialize_file_diff_data(filename, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_file_diff_wrong_too_big_file(void **state) { - const char *filename = GENERIC_PATH; - const directory_t configuration = { .diff_size_limit = 0 }; - - expect_initialize_file_diff_data(filename, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 1); -#ifdef TEST_WINAGENT - expect_string(__wrap__mdebug2, formatted_msg, "(6349): File 'c:\\file\\path' is too big for configured maximum size to perform diff operation."); -#else - expect_string(__wrap__mdebug2, formatted_msg, "(6349): File '/path/to/file' is too big for configured maximum size to perform diff operation."); -#endif - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_string_equal(diff_str, "Unable to calculate diff due to 'file_size' limit has been reached."); - - free(diff_str); -} - -void test_fim_file_diff_wrong_quota_reached(void **state) { - const char *filename = GENERIC_PATH; - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - const directory_t configuration = { .diff_size_limit = 0 }; - - expect_initialize_file_diff_data(filename, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 2); -#ifdef TEST_WINAGENT - expect_string(__wrap__mdebug2, formatted_msg, "(6350): The estimation of the file size 'c:\\file\\path' exceeds the disk_quota. Operation discarded."); -#else - expect_string(__wrap__mdebug2, formatted_msg, "(6350): The estimation of the file size '/path/to/file' exceeds the disk_quota. Operation discarded."); -#endif - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_string_equal(diff_str, "Unable to calculate diff due to 'disk_quota' limit has been reached."); - - free(diff_str); -} - -void test_fim_file_diff_uncompress_fail(void **state) { - const char *filename = GENERIC_PATH; - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - const directory_t configuration = { .diff_size_limit = 1024 }; - - expect_initialize_file_diff_data(filename, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 0); - - expect_w_uncompress_gzfile(COMPRESS_FILE, UNCOMPRESS_FILE, (FILE *)1234); - - expect_fim_diff_create_compress_file(GENERIC_PATH, COMPRESS_TMP_FILE, 0); - - expect_mkdir_ex(COMPRESS_FOLDER, 0); - - expect_save_compress_file(COMPRESS_TMP_FILE, COMPRESS_FILE, 0); - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_string_equal(diff_str, "Unable to calculate diff due to no previous data stored for this file."); - - free(diff_str); -} - -void test_fim_file_diff_create_compress_fail(void **state) { - const char *filename = GENERIC_PATH; - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - const directory_t configuration = { .diff_size_limit = 1024 }; - - expect_initialize_file_diff_data(filename, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 0); - - expect_w_uncompress_gzfile(COMPRESS_FILE, UNCOMPRESS_FILE, NULL); - - expect_FileSize(COMPRESS_FILE, 1024 * 1024); - - expect_fim_diff_create_compress_file(GENERIC_PATH, COMPRESS_TMP_FILE, -1); - -#ifdef TEST_WINAGENT - expect_string(__wrap__mwarn, formatted_msg, "(6914): Cannot create a snapshot of file 'c:\\file\\path'"); -#else - expect_string(__wrap__mwarn, formatted_msg, "(6914): Cannot create a snapshot of file '/path/to/file'"); -#endif - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_file_diff_compare_fail(void **state) { - const char *filename = GENERIC_PATH; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - const directory_t configuration = { .diff_size_limit = 1024 }; - - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - - expect_initialize_file_diff_data(filename, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 0); - - expect_w_uncompress_gzfile(COMPRESS_FILE, UNCOMPRESS_FILE, NULL); - - expect_FileSize(COMPRESS_FILE, 1024 * 1024); - - expect_fim_diff_create_compress_file(GENERIC_PATH, COMPRESS_TMP_FILE, 0); - - expect_fim_diff_compare(UNCOMPRESS_FILE, GENERIC_PATH, md5sum_old, md5sum_new, -1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6351): The files are identical, don't compute differences"); - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_string_equal(diff_str, "No content changes were found for this file."); - - free(diff_str); -} - -#ifdef TEST_WINAGENT -void test_fim_file_diff_nodiff(void **state) { - const char *filename = "c:\\file\\nodiff"; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - const directory_t configuration = { .diff_size_limit = 1024 }; - - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - - expect_initialize_file_diff_data(filename, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits("c:\\file\\nodiff", "aaa", 0); - - expect_w_uncompress_gzfile("queue/diff/file/2ddcb012cae2957e19d31b10df12abc8c852cfb7/last-entry.gz", UNCOMPRESS_FILE, NULL); - - expect_FileSize("queue/diff/file/2ddcb012cae2957e19d31b10df12abc8c852cfb7/last-entry.gz", 1024 * 1024); - - expect_fim_diff_create_compress_file("c:\\file\\nodiff", COMPRESS_TMP_FILE, 0); - - expect_fim_diff_compare(UNCOMPRESS_FILE, "c:\\file\\nodiff", md5sum_old, md5sum_new, 0); - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_string_equal(diff_str, "Diff truncated due to 'nodiff' configuration detected for this file."); - - free(diff_str); -} -#else -void test_fim_file_diff_nodiff(void **state) { - const char *filename = "/path/to/ignore"; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - const directory_t configuration = { .diff_size_limit = 1024 }; - - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - - expect_initialize_file_diff_data(filename, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits("/path/to/ignore", "aaa", 0); - - expect_w_uncompress_gzfile("queue/diff/file/2ee531af6f6a5f133cdd38e818e1de895c29114c/last-entry.gz", UNCOMPRESS_FILE, NULL); - - expect_FileSize("queue/diff/file/2ee531af6f6a5f133cdd38e818e1de895c29114c/last-entry.gz", 1024 * 1024); - - expect_fim_diff_create_compress_file("/path/to/ignore", COMPRESS_TMP_FILE, 0); - - expect_fim_diff_compare(UNCOMPRESS_FILE, "/path/to/ignore", md5sum_old, md5sum_new, 0); - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(filename, &configuration); - - assert_string_equal(diff_str, "Diff truncated due to 'nodiff' configuration detected for this file."); - - free(diff_str); -} -#endif - -void test_fim_file_diff_generate_fail(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - const directory_t configuration = { .diff_size_limit = 1024 }; - - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - -#ifndef TEST_WINAGENT - gen_diff_data_container->diff->uncompress_file = strdup(UNCOMPRESS_FILE); - gen_diff_data_container->diff->file_origin = strdup("/path/to/file/origin"); - gen_diff_data_container->diff->diff_file = strdup("queue/diff/tmp/diff-file"); -#else - gen_diff_data_container->diff->uncompress_file = strdup("queue/diff/tmp/tmp-entry"); - gen_diff_data_container->diff->file_origin = strdup("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED); - gen_diff_data_container->diff->diff_file = strdup("queue/diff/tmp/diff-file"); -#endif - - expect_initialize_file_diff_data(GENERIC_PATH, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 0); - - expect_w_uncompress_gzfile(COMPRESS_FILE, UNCOMPRESS_FILE, NULL); - - expect_FileSize(COMPRESS_FILE, 1024 * 1024); - - expect_fim_diff_create_compress_file(GENERIC_PATH, COMPRESS_TMP_FILE, 0); - - expect_fim_diff_compare(UNCOMPRESS_FILE, GENERIC_PATH, md5sum_old, md5sum_new, 0); - - expect_fim_diff_generate(gen_diff_data_container, 1); - -#ifndef TEST_WINAGENT - expect_string(__wrap__merror, formatted_msg, "(6714): Command diff output an error"); -#else - expect_string(__wrap__merror, formatted_msg, "(6714): Command fc output an error"); -#endif - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(GENERIC_PATH, &configuration); - - assert_ptr_equal(diff_str, NULL); -} - -void test_fim_file_diff_generate_diff_str(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - const directory_t configuration = { .diff_size_limit = 1024 }; - - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - -#ifndef TEST_WINAGENT - gen_diff_data_container->diff->uncompress_file = strdup(UNCOMPRESS_FILE); - gen_diff_data_container->diff->file_origin = strdup("/path/to/file/origin"); - gen_diff_data_container->diff->diff_file = strdup("queue/diff/tmp/diff-file"); -#else - gen_diff_data_container->diff->uncompress_file = strdup("queue/diff/tmp/tmp-entry"); - gen_diff_data_container->diff->file_origin = strdup("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED); - gen_diff_data_container->diff->diff_file = strdup("queue/diff/tmp/diff-file"); -#endif - - expect_initialize_file_diff_data(GENERIC_PATH, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 0); - - expect_w_uncompress_gzfile(COMPRESS_FILE, UNCOMPRESS_FILE, NULL); - - expect_FileSize(COMPRESS_FILE, 1024 * 1024); - - expect_fim_diff_create_compress_file(GENERIC_PATH, COMPRESS_TMP_FILE, 0); - - expect_fim_diff_compare(UNCOMPRESS_FILE, GENERIC_PATH, md5sum_old, md5sum_new, 0); - - expect_fim_diff_generate(gen_diff_data_container, 0); - - expect_save_compress_file(COMPRESS_TMP_FILE, COMPRESS_FILE, 0); - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - - char *diff_str = fim_file_diff(GENERIC_PATH, &configuration); - - assert_string_equal(diff_str, gen_diff_data_container->strarray[1]); - - free(diff_str); -} - -void test_fim_file_diff_generate_diff_str_too_long(void **state) { - gen_diff_struct *gen_diff_data_container = *state; - os_md5 md5sum_old = "3c183a30cffcda1408daf1c61d47b274"; - os_md5 md5sum_new = "abc44bfb4ab4cf4af49a4fa9b04fa44a"; - const directory_t configuration = { .diff_size_limit = 1024 }; - - syscheck.comp_estimation_perc = 0.4; - syscheck.diff_folder_size = 512; - -#ifndef TEST_WINAGENT - int input_size = strlen(gen_diff_data_container->strarray[0]); - os_realloc(gen_diff_data_container->strarray[0], OS_MAXSTR, gen_diff_data_container->strarray[0]); - memset(gen_diff_data_container->strarray[0] + input_size - 1, 'a', OS_MAXSTR - input_size); - gen_diff_data_container->strarray[0][OS_MAXSTR - 1] = '\0'; - - os_realloc(gen_diff_data_container->strarray[1], strlen(gen_diff_data_container->strarray[1]) - 12 + strlen(STR_MORE_CHANGES) + 1, gen_diff_data_container->strarray[1]); - strcpy(gen_diff_data_container->strarray[1] + strlen(gen_diff_data_container->strarray[1]) - 12, STR_MORE_CHANGES); - - gen_diff_data_container->diff->uncompress_file = strdup(UNCOMPRESS_FILE); - gen_diff_data_container->diff->file_origin = strdup("/path/to/file/origin"); - gen_diff_data_container->diff->diff_file = strdup("queue/diff/tmp/diff-file"); -#else - strcpy(gen_diff_data_container->strarray[0], "Comparing files start.txt and end.txt\r\n" - "Error diffs\r\n" - "***** start.txt\r\n" - " 1: First line\r\n" - "***** END.TXT\r\n" - " 1: First Line 123\r\n" - " 2: Last line"); - int input_size = strlen(gen_diff_data_container->strarray[0]); - os_realloc(gen_diff_data_container->strarray[0], OS_MAXSTR, gen_diff_data_container->strarray[0]); - memset(gen_diff_data_container->strarray[0] + input_size, 'a', OS_MAXSTR - input_size); - gen_diff_data_container->strarray[0][OS_MAXSTR - 1] = '\0'; - - int output_size = strlen(gen_diff_data_container->strarray[1]); - os_realloc(gen_diff_data_container->strarray[1], OS_MAXSTR, gen_diff_data_container->strarray[1]); - memset(gen_diff_data_container->strarray[1] + output_size - 1, 'a', OS_MAXSTR - output_size - OS_SK_HEADER - 85 - strlen(STR_MORE_CHANGES)); - strcat(gen_diff_data_container->strarray[1], STR_MORE_CHANGES); - - gen_diff_data_container->diff->uncompress_file = strdup("queue/diff/tmp/tmp-entry"); - gen_diff_data_container->diff->file_origin = strdup("queue/diff/tmp/[x64] " KEY_NAME_HASHED VALUE_NAME_HASHED); - gen_diff_data_container->diff->diff_file = strdup("queue/diff/tmp/diff-file"); -#endif - - expect_initialize_file_diff_data(GENERIC_PATH, 1); - - expect_mkdir_ex(TMP_FOLDER, 0); - - expect_fim_diff_check_limits(GENERIC_PATH, COMPRESS_FOLDER, 0); - - expect_w_uncompress_gzfile(COMPRESS_FILE, UNCOMPRESS_FILE, NULL); - - expect_FileSize(COMPRESS_FILE, 1024 * 1024); - - expect_fim_diff_create_compress_file(GENERIC_PATH, COMPRESS_TMP_FILE, 0); - - expect_fim_diff_compare(UNCOMPRESS_FILE, GENERIC_PATH, md5sum_old, md5sum_new, 0); - - expect_fim_diff_generate(gen_diff_data_container, 0); - - expect_save_compress_file(COMPRESS_TMP_FILE, COMPRESS_FILE, 0); - - expect_string(__wrap_rmdir_ex, name, TMP_FOLDER); - will_return(__wrap_rmdir_ex, 0); - char *diff_str = fim_file_diff(GENERIC_PATH, &configuration); - - assert_string_equal(diff_str, gen_diff_data_container->strarray[1]); - free(diff_str); -} - -void test_fim_diff_process_delete_file_ok(void **state) { -#ifdef TEST_WINAGENT - expect_abspath("c:\\file\\path", 1); -#else - expect_abspath("/path/to/file", 1); -#endif - expect_fim_diff_delete_compress_folder(COMPRESS_FOLDER, 0, 0, 0); - - fim_diff_process_delete_file(GENERIC_PATH); -} - -void test_fim_diff_process_delete_file_delete_error(void **state) { -#ifdef TEST_WINAGENT - expect_abspath("c:\\file\\path", 1); -#else - expect_abspath("/path/to/file", 1); -#endif - expect_fim_diff_delete_compress_folder(COMPRESS_FOLDER, 0, -1, 0); - -#ifdef TEST_WINAGENT - expect_string(__wrap__merror, formatted_msg, "(6713): Cannot remove diff folder for file: 'queue/diff/file/750621a746c8d786022a931ab9a99b918f7208f4'"); -#else - expect_string(__wrap__merror, formatted_msg, "(6713): Cannot remove diff folder for file: 'queue/diff/file/7cdbc5364a7aeb60f61d8fd2e6243056227bd6d3'"); -#endif - - fim_diff_process_delete_file(GENERIC_PATH); -} - -void test_fim_diff_process_delete_file_folder_not_exist(void **state) { -#ifdef TEST_WINAGENT - expect_abspath("c:\\file\\path", 1); -#else - expect_abspath("/path/to/file", 1); -#endif - expect_fim_diff_delete_compress_folder(COMPRESS_FOLDER, -1, 0, 0); - -#ifdef TEST_WINAGENT - expect_string(__wrap__mdebug2, formatted_msg, "(6355): Can't remove folder 'queue/diff/file/750621a746c8d786022a931ab9a99b918f7208f4', it does not exist."); -#else - expect_string(__wrap__mdebug2, formatted_msg, "(6355): Can't remove folder 'queue/diff/file/7cdbc5364a7aeb60f61d8fd2e6243056227bd6d3', it does not exist."); -#endif - - fim_diff_process_delete_file(GENERIC_PATH); -} - -#ifdef TEST_WINAGENT -void test_fim_diff_process_delete_registry_ok(void **state) { - const char *key_name = strdup("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"); - - expect_fim_diff_delete_compress_folder("queue/diff/registry/[x32] " KEY_NAME_HASHED, 0, 0, 0); - - fim_diff_process_delete_registry(key_name, 0); -} - -void test_fim_diff_process_delete_registry_delete_error(void **state) { - const char *key_name = strdup("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"); - - expect_string(__wrap__merror, formatted_msg, "(6713): Cannot remove diff folder for file: 'queue/diff/registry/[x64] b9b175e8810d3475f15976dd3b5f9210f3af6604'"); - - expect_fim_diff_delete_compress_folder("queue/diff/registry/[x64] " KEY_NAME_HASHED, 0, -1, 0); - - fim_diff_process_delete_registry(key_name, 1); -} - -void test_fim_diff_process_delete_value_ok(void **state) { - const char *key_name = strdup("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"); - - expect_fim_diff_delete_compress_folder("queue/diff/registry/[x32] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED, 0, 0, 0); - - fim_diff_process_delete_value(key_name, "valuename", 0); -} - -void test_fim_diff_process_delete_value_delete_error(void **state) { - const char *key_name = strdup("HKEY_LOCAL_MACHINE\\Software\\Classes\\batfile"); - - expect_string(__wrap__merror, formatted_msg, "(6713): Cannot remove diff folder for file: 'queue/diff/registry/[x64] b9b175e8810d3475f15976dd3b5f9210f3af6604/3f17670fd80d6563a3d4283adfe14140907b75b0'"); - - expect_fim_diff_delete_compress_folder("queue/diff/registry/[x64] " KEY_NAME_HASHED "/" VALUE_NAME_HASHED, 0, -1, 0); - - fim_diff_process_delete_value(key_name, "valuename", 1); -} -#endif - -int main(void) { - const struct CMUnitTest tests[] = { - -#ifdef TEST_WINAGENT - // filter - cmocka_unit_test_teardown(test_filter_unchanged_string, teardown_free_string), - cmocka_unit_test(test_filter_percentage_char), - - // adapt_win_fc_output - cmocka_unit_test_setup_teardown(test_adapt_win_fc_output_success, setup_array_strings, teardown_array_strings), - cmocka_unit_test_setup_teardown(test_adapt_win_fc_output_invalid_input, setup_array_strings, teardown_array_strings), - cmocka_unit_test_setup_teardown(test_adapt_win_fc_output_no_differences, setup_array_strings, teardown_array_strings), - - // initialize_registry_diff_data - cmocka_unit_test_teardown(test_initialize_registry_diff_data, teardown_free_diff_data), -#endif - // initialize_file_diff_data - cmocka_unit_test_teardown(test_initialize_file_diff_data, teardown_free_diff_data), - cmocka_unit_test_teardown(test_initialize_file_diff_data_abspath_fail, teardown_free_diff_data), - - // filter - cmocka_unit_test_teardown(test_filter, teardown_free_string), - - // fim_diff_check_limits - cmocka_unit_test_setup_teardown(test_fim_diff_check_limits, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_check_limits_size_limit_reached, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_check_limits_estimate_compression, setup_diff_data, teardown_free_diff_data), - - // fim_diff_delete_compress_folder - cmocka_unit_test_teardown(test_fim_diff_delete_compress_folder, teardown_disk_quota_exceeded), - cmocka_unit_test(test_fim_diff_delete_compress_folder_no_dir), - cmocka_unit_test(test_fim_diff_delete_compress_folder_rmdir_ex_fail), - cmocka_unit_test_setup_teardown(test_fim_diff_delete_compress_folder_remove_folder_fail, setup_diff_data, teardown_free_diff_data), - - // fim_diff_estimate_compression - cmocka_unit_test(test_fim_diff_estimate_compression_file_not_fit), - cmocka_unit_test(test_fim_diff_estimate_compression_ok), - - // fim_diff_create_compress_file - cmocka_unit_test_setup_teardown(test_fim_diff_create_compress_file_fail_compress, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_create_compress_file_ok, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_create_compress_file_quota_reached, setup_diff_data, teardown_free_diff_data), - - // fim_diff_modify_compress_estimation - cmocka_unit_test(test_fim_diff_modify_compress_estimation_small_compresion_rate), - cmocka_unit_test(test_fim_diff_modify_compress_estimation_MIN_COMP_ESTIM), - cmocka_unit_test(test_fim_diff_modify_compress_estimation_ok), - - // fim_diff_compare - cmocka_unit_test_setup_teardown(test_fim_diff_compare_fail_uncompress_MD5, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_compare_fail_origin_MD5, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_compare_fail_not_match, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_compare_fail_match, setup_diff_data, teardown_free_diff_data), - - // save_compress_file - cmocka_unit_test_setup_teardown(test_save_compress_file_ok, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_save_compress_file_rename_fail, setup_diff_data, teardown_free_diff_data), - - // is_file_nodiff - cmocka_unit_test(test_is_file_nodiff_normal_check), - cmocka_unit_test(test_is_file_nodiff_regex_check), - cmocka_unit_test(test_is_file_nodiff_not_match), - -#ifdef TEST_WINAGENT - // is_registry_nodiff - cmocka_unit_test(test_is_registry_nodiff_normal_check), - cmocka_unit_test(test_is_registry_nodiff_regex_check), - cmocka_unit_test(test_is_registry_nodiff_not_match), -#endif - - // gen_diff_str - cmocka_unit_test_setup_teardown(test_gen_diff_str_wfropen_fail, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_gen_diff_str_fread_fail, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_gen_diff_str_ok, setup_gen_diff_str, teardown_free_gen_diff_str), - - // fim_diff_generate - cmocka_unit_test_setup_teardown(test_fim_diff_generate_status_error, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_generate_status_ok, setup_gen_diff_str, teardown_free_gen_diff_str), -#ifdef TEST_WINAGENT - cmocka_unit_test_setup_teardown(test_fim_diff_generate_filters_fail, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_generate_status_equal, setup_diff_data, teardown_free_diff_data), - - // fim_diff_registry_tmp - cmocka_unit_test_setup_teardown(test_fim_diff_registry_tmp_fopen_fail, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_registry_tmp_REG_SZ, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_registry_tmp_REG_MULTI_SZ, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_registry_tmp_REG_DWORD, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_registry_tmp_REG_DWORD_BIG_ENDIAN, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_registry_tmp_REG_QWORD, setup_diff_data, teardown_free_diff_data), - cmocka_unit_test_setup_teardown(test_fim_diff_registry_tmp_default_type, setup_diff_data, teardown_free_diff_data), - - // fim_registry_value_diff - cmocka_unit_test(test_fim_registry_value_diff_wrong_data_type), - cmocka_unit_test(test_fim_registry_value_diff_wrong_registry_tmp), - cmocka_unit_test(test_fim_registry_value_diff_wrong_too_big_file), - cmocka_unit_test(test_fim_registry_value_diff_wrong_quota_reached), - cmocka_unit_test(test_fim_registry_value_diff_uncompress_fail), - cmocka_unit_test(test_fim_registry_value_diff_create_compress_fail), - cmocka_unit_test(test_fim_registry_value_diff_compare_fail), - cmocka_unit_test(test_fim_registry_value_diff_nodiff), - cmocka_unit_test_setup_teardown(test_fim_registry_value_diff_generate_fail, setup_full_diff_functionality, teardown_full_diff_functionality), - cmocka_unit_test_setup_teardown(test_fim_registry_value_diff_generate_diff_str, setup_full_diff_functionality, teardown_full_diff_functionality), -#endif - - // fim_file_diff - cmocka_unit_test(test_fim_file_diff_wrong_initialize), - cmocka_unit_test(test_fim_file_diff_wrong_too_big_file), - cmocka_unit_test(test_fim_file_diff_wrong_quota_reached), - cmocka_unit_test(test_fim_file_diff_uncompress_fail), - cmocka_unit_test(test_fim_file_diff_create_compress_fail), - cmocka_unit_test(test_fim_file_diff_compare_fail), - cmocka_unit_test(test_fim_file_diff_nodiff), -#ifdef TEST_WINAGENT - cmocka_unit_test_setup_teardown(test_fim_file_diff_generate_fail, setup_full_diff_functionality, teardown_full_diff_functionality), - cmocka_unit_test_setup_teardown(test_fim_file_diff_generate_diff_str, setup_full_diff_functionality, teardown_full_diff_functionality), -#else - cmocka_unit_test_setup_teardown(test_fim_file_diff_generate_fail, setup_gen_diff_str, teardown_free_gen_diff_str), - cmocka_unit_test_setup_teardown(test_fim_file_diff_generate_diff_str, setup_gen_diff_str, teardown_free_gen_diff_str), -#endif - cmocka_unit_test_setup_teardown(test_fim_file_diff_generate_diff_str_too_long, setup_gen_diff_str, teardown_free_gen_diff_str), - - // fim_diff_process_delete_file - cmocka_unit_test(test_fim_diff_process_delete_file_ok), - cmocka_unit_test(test_fim_diff_process_delete_file_delete_error), - cmocka_unit_test(test_fim_diff_process_delete_file_folder_not_exist), - -#ifdef TEST_WINAGENT - // fim_diff_process_delete_registry - cmocka_unit_test(test_fim_diff_process_delete_registry_ok), - cmocka_unit_test(test_fim_diff_process_delete_registry_delete_error), - - // fim_diff_process_delete_value - cmocka_unit_test(test_fim_diff_process_delete_value_ok), - cmocka_unit_test(test_fim_diff_process_delete_value_delete_error), -#endif - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/syscheckd/test_run_check.c b/src/unit_tests/syscheckd/test_run_check.c deleted file mode 100644 index 40bdd60ebba..00000000000 --- a/src/unit_tests/syscheckd/test_run_check.c +++ /dev/null @@ -1,1146 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wrappers/common.h" -#include "../wrappers/posix/stat_wrappers.h" -#include "../wrappers/linux/inotify_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../wrappers/wazuh/shared/randombytes_wrappers.h" -#include "../wrappers/wazuh/syscheckd/create_db_wrappers.h" -#include "../wrappers/wazuh/syscheckd/fim_db_wrappers.h" -#include "../wrappers/wazuh/syscheckd/run_realtime_wrappers.h" -#include "../wrappers/wazuh/syscheckd/win_whodata_wrappers.h" - -#include "../syscheckd/include/syscheck.h" -#include "../syscheckd/src/db/include/db.h" -#include "../config/syscheck-config.h" - -#ifdef TEST_WINAGENT -#include "../wrappers/windows/processthreadsapi_wrappers.h" - -void set_priority_windows_thread(); -void set_whodata_mode_changes(); -#endif - -/* External 'static' functions prototypes */ -void fim_send_msg(char mq, const char * location, const char * msg); -#ifdef WIN32 -DWORD WINAPI fim_run_realtime(__attribute__((unused)) void * args); - -extern void free_win32rtfim_data(win32rtfim *data); - -#else -void * fim_run_realtime(__attribute__((unused)) void * args); -#endif - -#ifndef TEST_WINAGENT -void fim_link_update(const char *new_path, directory_t *configuration); -void fim_link_check_delete(directory_t *configuration); -void fim_link_delete_range(const directory_t *configuration); -void fim_link_silent_scan(char *path, directory_t *configuration); -void fim_link_reload_broken_link(char *path, directory_t *configuration); -void fim_realtime_delete_watches(const directory_t *configuration); -#endif - -void fim_db_remove_validated_path(void * data, void * ctx); - -extern time_t last_time; -extern unsigned int files_read; - -/* redefinitons/wrapping */ - -#ifdef TEST_WINAGENT -int __wrap_audit_restore(void) { - return mock(); -} -#else -time_t __wrap_time(time_t *timer) { - return mock_type(time_t); -} - -#endif - - -extern bool fim_shutdown_process_on(); -/* Setup/Teardown */ - -static int setup_group(void ** state) { -#ifdef TEST_WINAGENT - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - expect_string(__wrap__mdebug1, formatted_msg, "(6287): Reading configuration file: 'test_syscheck.conf'"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex node .log$|.htm$|.jpg$|.png$|.chm$|.pnf$|.evtx$|.swp$"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex node .log$|.htm$|.jpg$|.png$|.chm$|.pnf$|.evtx$|.swp$ OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex size 0"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node ^file"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node ^file OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex size 0"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node test_$"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node test_$ OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex size 1"); -#else // !TEST_WINAGENT - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_string(__wrap__mdebug1, formatted_msg, "(6287): Reading configuration file: 'test_syscheck.conf'"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex node .log$|.swp$"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex node .log$|.swp$ OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex size 0"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node ^file"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node ^file OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex size 0"); - -#endif // TEST_WINAGENT -#if defined(TEST_AGENT) || defined(TEST_WINAGENT) - expect_string(__wrap__mdebug1, formatted_msg, "(6208): Reading Client Configuration [test_syscheck.conf]"); -#endif - - will_return_always(__wrap_os_random, 12345); - - if(Read_Syscheck_Config("test_syscheck.conf")) - fail(); - - syscheck.realtime = (rtfim *) calloc(1, sizeof(rtfim)); - if(syscheck.realtime == NULL) { - return -1; - } -#ifndef TEST_WINAGENT - will_return(__wrap_time, 1); -#endif - syscheck.realtime->dirtb = OSHash_Create(); - if (syscheck.realtime->dirtb == NULL) { - return -1; - } - - -#ifdef TEST_WINAGENT - time_mock_value = 1; -#else - OSHash_Add_ex(syscheck.realtime->dirtb, "key", strdup("data")); -#endif - return 0; -} - -#ifndef TEST_WINAGENT - -static int setup_symbolic_links(void **state) { - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - directory_t *config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - if (config->path != NULL) { - free(config->path); - config->path = NULL; - } - - config->path = strdup("/link"); - config->symbolic_links = strdup("/folder"); - config->options |= REALTIME_ACTIVE; - - if (config->path == NULL || config->symbolic_links == NULL) { - return -1; - } - - return 0; -} - -static int teardown_symbolic_links(void **state) { - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - directory_t *config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - if (config->path != NULL) { - free(config->path); - config->path = NULL; - } - - if (config->symbolic_links != NULL) { - free(config->symbolic_links); - config->symbolic_links = NULL; - } - - config->path = strdup("/etc"); - config->options &= ~REALTIME_ACTIVE; - - if (config->path == NULL) { - return -1; - } - - return 0; -} - -static int setup_tmp_file(void **state) { - fim_tmp_file *tmp_file = calloc(1, sizeof(fim_tmp_file)); - tmp_file->elements = 1; - - if (setup_symbolic_links(NULL) < 0) { - return -1; - } - - *state = tmp_file; - - return 0; -} - -static int teardown_tmp_file(void **state) { - fim_tmp_file *tmp_file = *state; - free(tmp_file); - - if (teardown_symbolic_links(NULL) < 0) { - return -1; - } - - return 0; -} - -#endif - -static int teardown_group(void **state) { -#ifdef TEST_WINAGENT - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - if (syscheck.realtime) { - if (syscheck.realtime->dirtb) { - OSHash_Free(syscheck.realtime->dirtb); - } - free(syscheck.realtime); - syscheck.realtime = NULL; - } -#else - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); -#endif - - Free_Syscheck(&syscheck); - - return 0; -} - -/** - * @brief This function loads expect and will_return calls for the function send_sync_msg -*/ -static void expect_w_send_sync_msg(const char *msg, const char *locmsg, char location, bool (*fn_ptr)(), int ret) { - expect_SendMSGPredicated_call(msg, locmsg, location, fn_ptr, ret); -} - -static int setup_max_fps(void **state) { - syscheck.max_files_per_second = 1; - return 0; -} - -static int teardown_max_fps(void **state) { - syscheck.max_files_per_second = 0; - return 0; -} - -#ifdef TEST_WINAGENT - -static int setup_hash(void **state) { - directory_t *dir_it; - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - win32rtfim *rtlocald; - rtlocald = calloc(1, sizeof(win32rtfim)); - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - OSHash_Add_ex(syscheck.realtime->dirtb, dir_it->path, rtlocald); - } - } - syscheck.realtime->evt = (HANDLE)234; - return 0; -} - -static int teardown_hash(void **state) { - directory_t *dir_it; - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - free_win32rtfim_data(OSHash_Delete_ex(syscheck.realtime->dirtb, dir_it->path)); - } - } - return 0; -} -#endif - -static int teardown_dbsync_msg(void **state) { - char *ret_msg = *state; - free(ret_msg); - return 0; -} -/* tests */ - -void test_fim_whodata_initialize(void **state) -{ - int ret; -#ifdef TEST_WINAGENT - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - int i; - char *dirs[] = { - "%WINDIR%\\System32\\WindowsPowerShell\\v1.0", - NULL - }; - char expanded_dirs[1][OS_SIZE_1024]; - - // Expand directories - for(i = 0; dirs[i]; i++) { - if(!ExpandEnvironmentStrings(dirs[i], expanded_dirs[i], OS_SIZE_1024)) - fail(); - - str_lowercase(expanded_dirs[i]); - expect_realtime_adddir_call(expanded_dirs[i], 0); - } - will_return(__wrap_run_whodata_scan, 0); - will_return(wrap_CreateThread, (HANDLE)123456); -#endif - - ret = fim_whodata_initialize(); - - assert_int_equal(ret, 0); -} - -void test_log_realtime_status(void **state) -{ - (void) state; - - log_realtime_status(2); - - expect_string(__wrap__minfo, formatted_msg, FIM_REALTIME_STARTED); - log_realtime_status(1); - log_realtime_status(1); - - expect_string(__wrap__minfo, formatted_msg, FIM_REALTIME_PAUSED); - log_realtime_status(2); - log_realtime_status(2); - - expect_string(__wrap__minfo, formatted_msg, FIM_REALTIME_RESUMED); - log_realtime_status(1); -} - -#ifndef TEST_WINAGENT - -void test_fim_run_realtime_first_error(void **state) { - char debug_msg[OS_SIZE_128] = {0}; - syscheck.realtime->fd = 4; - - expect_function_call(__wrap_pthread_mutex_lock); - snprintf(debug_msg, OS_SIZE_128, FIM_NUM_WATCHES, 1); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_FOREVER, 1); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_select, -1); - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_SELECT); - - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} - -void test_fim_run_realtime_first_timeout(void **state) { - syscheck.realtime->fd = 4; - char debug_msg[OS_SIZE_128] = {0}; - - expect_function_call(__wrap_pthread_mutex_lock); - snprintf(debug_msg, OS_SIZE_128, FIM_NUM_WATCHES, 1); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_FOREVER, 1); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - - will_return(__wrap_select, 0); - - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} - -void test_fim_run_realtime_first_sleep(void **state) { - - syscheck.realtime->fd = -1; - char debug_msg[OS_SIZE_128] = {0}; - expect_function_call(__wrap_pthread_mutex_lock); - snprintf(debug_msg, OS_SIZE_128, FIM_NUM_WATCHES, 1); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_FOREVER, 1); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_sleep, seconds, SYSCHECK_WAIT); - - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} - -void test_fim_run_realtime_first_process(void **state) { - syscheck.realtime->fd = 4; - char debug_msg[OS_SIZE_128] = {0}; - - expect_function_call(__wrap_pthread_mutex_lock); - snprintf(debug_msg, OS_SIZE_128, FIM_NUM_WATCHES, 1); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_FOREVER, 1); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_select, 4); - expect_function_call(__wrap_realtime_process); - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} - -void test_fim_run_realtime_process_after_timeout(void **state) { - syscheck.realtime->fd = 4; - char debug_msg[OS_SIZE_128] = {0}; - - expect_function_call(__wrap_pthread_mutex_lock); - snprintf(debug_msg, OS_SIZE_128, FIM_NUM_WATCHES, 1); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_FOREVER, 1); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_select, 0); - - will_return(__wrap_FOREVER, 1); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - will_return(__wrap_select, 4); - expect_function_call(__wrap_realtime_process); - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} -#else - -void test_fim_run_realtime_w_first_timeout(void **state) { - char debug_msg[OS_SIZE_128] = {0}; - directory_t *dir_it; - OSListNode *node_it; - int added_dirs = 0; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - // set_priority_windows_thread - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '10'"); - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_LOWEST, true); - - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - expect_string(__wrap_realtime_adddir, dir, dir_it->path); - will_return(__wrap_realtime_adddir, 0); - added_dirs++; - } - } - will_return(__wrap_FOREVER, 1); - - snprintf(debug_msg, OS_SIZE_128, FIM_NUM_WATCHES, added_dirs); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - expect_value(wrap_WaitForSingleObjectEx, hHandle, (DWORD)234); - expect_value(wrap_WaitForSingleObjectEx, dwMilliseconds, SYSCHECK_WAIT * 1000); - expect_value(wrap_WaitForSingleObjectEx, bAlertable, TRUE); - will_return(wrap_WaitForSingleObjectEx, WAIT_FAILED); - - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_REALTIME_WAITSINGLE_OBJECT); - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - expect_string(__wrap_realtime_adddir, dir, dir_it->path); - will_return(__wrap_realtime_adddir, 0); - added_dirs++; - } - } - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} - -void test_fim_run_realtime_w_wait_success(void **state) { - char debug_msg[OS_SIZE_128] = {0}; - directory_t *dir_it; - OSListNode *node_it; - int added_dirs = 0; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - // set_priority_windows_thread - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '10'"); - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_LOWEST, true); - - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - expect_string(__wrap_realtime_adddir, dir, dir_it->path); - will_return(__wrap_realtime_adddir, 0); - added_dirs++; - } - } - - will_return(__wrap_FOREVER, 1); - - snprintf(debug_msg, OS_SIZE_128, FIM_NUM_WATCHES, added_dirs); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - expect_value(wrap_WaitForSingleObjectEx, hHandle, (DWORD)234); - expect_value(wrap_WaitForSingleObjectEx, dwMilliseconds, SYSCHECK_WAIT * 1000); - expect_value(wrap_WaitForSingleObjectEx, bAlertable, TRUE); - will_return(wrap_WaitForSingleObjectEx, WAIT_IO_COMPLETION); - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - expect_string(__wrap_realtime_adddir, dir, dir_it->path); - will_return(__wrap_realtime_adddir, 0); - added_dirs++; - } - } - - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} - -void test_fim_run_realtime_w_sleep(void **state) { - char debug_msg[OS_SIZE_128] = {0}; - directory_t *dir_it; - OSListNode *node_it; - int added_dirs = 0; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - // set_priority_windows_thread - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '10'"); - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_LOWEST, true); - - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - expect_string(__wrap_realtime_adddir, dir, dir_it->path); - will_return(__wrap_realtime_adddir, 0); - } - } - will_return(__wrap_FOREVER, 1); - - expect_value(wrap_Sleep, dwMilliseconds, SYSCHECK_WAIT * 1000); - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (dir_it->options & REALTIME_ACTIVE) { - expect_string(__wrap_realtime_adddir, dir, dir_it->path); - will_return(__wrap_realtime_adddir, 0); - added_dirs++; - } - } - - will_return(__wrap_FOREVER, 0); - - fim_run_realtime(NULL); -} - -void test_fim_whodata_initialize_fail_set_policies(void **state) -{ - int ret; - int i; - char *dirs[] = { - "%WINDIR%\\System32\\WindowsPowerShell\\v1.0", - NULL - }; - char expanded_dirs[1][OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - // Expand directories - for(i = 0; dirs[i]; i++) { - if(!ExpandEnvironmentStrings(dirs[i], expanded_dirs[i], OS_SIZE_1024)) - fail(); - - str_lowercase(expanded_dirs[i]); - expect_realtime_adddir_call(expanded_dirs[i], 0); - } - - will_return(__wrap_run_whodata_scan, 1); - expect_string(__wrap__merror, formatted_msg, - "(6710): Failed to start the Whodata engine. Directories/files will be monitored in Realtime mode"); - - will_return(__wrap_audit_restore, NULL); - - ret = fim_whodata_initialize(); - - assert_int_equal(ret, -1); -} - -void test_set_priority_windows_thread_highest(void **state) { - syscheck.process_priority = -10; - - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '-10'"); - - will_return(wrap_GetCurrentThread, (HANDLE)123456); - - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_HIGHEST, true); - - set_priority_windows_thread(); -} - -void test_set_priority_windows_thread_above_normal(void **state) { - syscheck.process_priority = -8; - - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '-8'"); - - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_ABOVE_NORMAL, true); - - set_priority_windows_thread(); -} - -void test_set_priority_windows_thread_normal(void **state) { - syscheck.process_priority = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '0'"); - - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_NORMAL, true); - - set_priority_windows_thread(); -} - -void test_set_priority_windows_thread_below_normal(void **state) { - syscheck.process_priority = 2; - - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '2'"); - - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_BELOW_NORMAL, true); - - set_priority_windows_thread(); -} - -void test_set_priority_windows_thread_lowest(void **state) { - syscheck.process_priority = 7; - - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '7'"); - - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_LOWEST, true); - - set_priority_windows_thread(); -} - -void test_set_priority_windows_thread_idle(void **state) { - syscheck.process_priority = 20; - - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '20'"); - - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_IDLE, true); - - set_priority_windows_thread(); -} - -void test_set_priority_windows_thread_error(void **state) { - syscheck.process_priority = 10; - - expect_string(__wrap__mdebug1, formatted_msg, "(6320): Setting process priority to: '10'"); - - will_return(wrap_GetCurrentThread, (HANDLE)123456); - expect_SetThreadPriority_call((HANDLE)123456, THREAD_PRIORITY_LOWEST, false); - - will_return(wrap_GetLastError, 2345); - - expect_string(__wrap__merror, formatted_msg, "Can't set thread priority: 2345"); - - set_priority_windows_thread(); -} - -#ifdef WIN_WHODATA -void test_set_whodata_mode_changes(void **state) { - int i; - char *dirs[] = { - "%PROGRAMDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup", - "%WINDIR%\\System32\\wbem", - "%WINDIR%\\System32\\Windowspowershell\\v1.0", - NULL - }; - char expanded_dirs[3][OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // Mark directories to be added in realtime - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status |= WD_CHECK_REALTIME; - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status &= ~WD_CHECK_WHODATA; - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 4))->dirs_status.status |= WD_CHECK_REALTIME; - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 4))->dirs_status.status &= ~WD_CHECK_WHODATA; - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 5))->dirs_status.status |= WD_CHECK_REALTIME; - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 5))->dirs_status.status &= ~WD_CHECK_WHODATA; - - // Expand directories - for(i = 0; dirs[i]; i++) { - if(!ExpandEnvironmentStrings(dirs[i], expanded_dirs[i], OS_SIZE_1024)) - fail(); - - str_lowercase(expanded_dirs[i]); - expect_realtime_adddir_call(expanded_dirs[i], i % 2 == 0); - } - - expect_string(__wrap__mdebug1, formatted_msg, "(6225): The 'c:\\programdata\\microsoft\\windows\\start menu\\programs\\startup' directory starts to be monitored in real-time mode."); - expect_string(__wrap__merror, formatted_msg, "(6611): 'realtime_adddir' failed, the directory 'c:\\windows\\system32\\wbem' couldn't be added to real time mode."); - expect_string(__wrap__mdebug1, formatted_msg, "(6225): The 'c:\\windows\\system32\\windowspowershell\\v1.0' directory starts to be monitored in real-time mode."); - - set_whodata_mode_changes(); -} - -void test_fim_whodata_initialize_eventchannel(void **state) { - int ret; - int i; - char *dirs[] = { - "%WINDIR%\\System32\\WindowsPowerShell\\v1.0", - NULL - }; - char expanded_dirs[1][OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - // Expand directories - for(i = 0; dirs[i]; i++) { - if(!ExpandEnvironmentStrings(dirs[i], expanded_dirs[i], OS_SIZE_1024)) - fail(); - - str_lowercase(expanded_dirs[i]); - expect_realtime_adddir_call(expanded_dirs[i], 0); - } - - will_return(__wrap_run_whodata_scan, 0); - - will_return(wrap_CreateThread, (HANDLE)123456); - - ret = fim_whodata_initialize(); - - assert_int_equal(ret, 0); -} -#endif // WIN_WHODATA -#endif - -void test_fim_send_scan_info(void **state) { - (void) state; - const char *msg = "{\"type\":\"scan_start\",\"data\":{\"timestamp\":1}}"; -#ifndef TEST_WINAGENT - will_return(__wrap_time, 1); -#endif - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_string(__wrap__mdebug2, formatted_msg, "(6321): Sending FIM event: {\"type\":\"scan_start\",\"data\":{\"timestamp\":1}}"); - expect_w_send_sync_msg(msg, SYSCHECK, SYSCHECK_MQ, fim_shutdown_process_on, 0); - fim_send_scan_info(FIM_SCAN_START); -} - -#ifndef TEST_WINAGENT -void test_fim_link_update(void **state) { - char *new_path = "/new_path"; - char pattern[PATH_MAX] = {0}; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - expect_string(__wrap_remove_audit_rule_syscheck, path, affected_config->symbolic_links); - - snprintf(pattern, PATH_MAX, "%s%c%%", affected_config->symbolic_links, PATH_SEP); - expect_fim_db_file_pattern_search(pattern, 0); - - expect_fim_checker_call(new_path, affected_config); - expect_realtime_adddir_call(new_path, 0); - expect_string(__wrap_remove_audit_rule_syscheck, path, affected_config->path); - - fim_link_update(new_path, affected_config); - - assert_string_equal(affected_config->path, "/link"); - assert_string_equal(affected_config->symbolic_links, new_path); -} - -void test_fim_link_update_already_added(void **state) { - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - char *link_path = "/home"; - char error_msg[OS_SIZE_128]; - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - free(affected_config->symbolic_links); - affected_config->symbolic_links = strdup("/home"); - - snprintf(error_msg, OS_SIZE_128, FIM_LINK_ALREADY_ADDED, link_path); - - expect_string(__wrap__mdebug2, formatted_msg, error_msg); - - fim_link_update(link_path, affected_config); - - assert_string_equal(affected_config->path, "/link"); - assert_null(affected_config->symbolic_links); -} - -void test_fim_link_check_delete(void **state) { - char *link_path = "/link"; - char *pointed_folder = "/folder"; - char pattern[PATH_MAX] = {0}; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - expect_string(__wrap_lstat, filename, affected_config->symbolic_links); - will_return(__wrap_lstat, 0); - will_return(__wrap_lstat, 0); - - expect_string(__wrap_remove_audit_rule_syscheck, path, affected_config->symbolic_links); - - snprintf(pattern, PATH_MAX, "%s%c%%", affected_config->symbolic_links, PATH_SEP); - expect_fim_db_file_pattern_search(pattern, 0); - - expect_fim_configuration_directory_call("data", NULL); - fim_link_check_delete(affected_config); - - assert_string_equal(affected_config->path, link_path); - assert_null(affected_config->symbolic_links); -} - -void test_fim_link_check_delete_lstat_error(void **state) { - char *link_path = "/link"; - char *pointed_folder = "/folder"; - char error_msg[OS_SIZE_128]; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - expect_string(__wrap_lstat, filename, pointed_folder); - will_return(__wrap_lstat, 0); - will_return(__wrap_lstat, -1); - errno = 0; - - snprintf(error_msg, OS_SIZE_128, FIM_STAT_FAILED, pointed_folder, 0, "Success"); - - expect_string(__wrap__mdebug1, formatted_msg, error_msg); - - fim_link_check_delete(affected_config); - - assert_string_equal(affected_config->path, link_path); - assert_string_equal(affected_config->symbolic_links, pointed_folder); -} - -void test_fim_link_check_delete_noentry_error(void **state) { - char *link_path = "/link"; - char *pointed_folder = "/folder"; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - expect_string(__wrap_lstat, filename, pointed_folder); - will_return(__wrap_lstat, 0); - will_return(__wrap_lstat, -1); - expect_string(__wrap_remove_audit_rule_syscheck, path, affected_config->symbolic_links); - - errno = ENOENT; - - fim_link_check_delete(affected_config); - - errno = 0; - - assert_string_equal(affected_config->path, link_path); - assert_null(affected_config->symbolic_links); -} - -void test_fim_delete_realtime_watches(void **state) { - unsigned int pos; - char *link_path = "/link"; - char *pointed_folder = "/folder"; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_fim_configuration_directory_call("data", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))); - - will_return(__wrap_inotify_rm_watch, 1); - - fim_realtime_delete_watches(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))); - - assert_null(OSHash_Begin(syscheck.realtime->dirtb, &pos)); -} - -void test_fim_link_delete_range(void **state) { - fim_tmp_file *tmp_file = *state; - char pattern[PATH_MAX] = {0}; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - snprintf(pattern, PATH_MAX, "%s%c%%", "/folder", PATH_SEP); - expect_fim_db_file_pattern_search(pattern, 0); - - fim_link_delete_range(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))); -} - -void test_fim_link_silent_scan(void **state) { - char *link_path = "/link"; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 3); - - expect_realtime_adddir_call(link_path, 0); - expect_fim_checker_call(link_path, affected_config); - - fim_link_silent_scan(link_path, affected_config); -} - -void test_fim_link_reload_broken_link_already_monitored(void **state) { - char *link_path = "/link"; - char *pointed_folder = "/folder"; - char error_msg[OS_SIZE_128]; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - snprintf(error_msg, OS_SIZE_128, FIM_LINK_ALREADY_ADDED, link_path); - - expect_string(__wrap__mdebug2, formatted_msg, error_msg); - - fim_link_reload_broken_link(link_path, affected_config); - - assert_string_equal(affected_config->path, link_path); - assert_string_equal(affected_config->symbolic_links, pointed_folder); -} - -void test_fim_link_reload_broken_link_reload_broken(void **state) { - char *link_path = "/link"; - char *pointed_folder = "/new_path"; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - directory_t *affected_config = (directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1); - - expect_fim_checker_call(pointed_folder, affected_config); - - expect_string(__wrap_realtime_adddir, dir, pointed_folder); - will_return(__wrap_realtime_adddir, 0); - - expect_string(__wrap_remove_audit_rule_syscheck, path, link_path); - - fim_link_reload_broken_link(pointed_folder, affected_config); - - assert_string_equal(affected_config->path, link_path); - assert_string_equal(affected_config->symbolic_links, pointed_folder); -} -#endif - -void test_check_max_fps_no_sleep(void **state) { - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - will_return(__wrap_gettime, last_time + 1); - - check_max_fps(); -} - -void test_check_max_fps_sleep(void **state) { - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - last_time = 10; - files_read = syscheck.max_files_per_second; - - will_return(__wrap_gettime, last_time); - expect_string(__wrap__mdebug2, formatted_msg, FIM_REACHED_MAX_FPS); - check_max_fps(); -} - -void test_send_sync_state(void **state) { - char debug_msg[OS_SIZE_256] = {0}; - char *event = "{\"data\":\"random_string\"}"; - - snprintf(debug_msg, OS_SIZE_256, FIM_DBSYNC_SEND, event); - syscheck.sync_max_eps = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_w_send_sync_msg(event, "fim_file", DBSYNC_MQ, fim_shutdown_process_on, 0); -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, 1 * 1000); -#else - expect_value(__wrap_sleep, seconds, 1); -#endif - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - expect_function_call(__wrap_pthread_mutex_unlock); - - fim_send_sync_state("fim_file", event); -} - -void test_send_sync_state_without_max_eps(void **state) { - char debug_msg[OS_SIZE_256] = {0}; - char *event = "{\"data\":\"random_string\"}"; - - snprintf(debug_msg, OS_SIZE_256, FIM_DBSYNC_SEND, event); - syscheck.sync_max_eps = 0; - - expect_w_send_sync_msg(event, "fim_file", DBSYNC_MQ, fim_shutdown_process_on, 0); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - fim_send_sync_state("fim_file", event); -} - -void test_fim_db_remove_validated_path(void **state){ - - char* path = "path"; - directory_t mock_config; - get_data_ctx mock_data; - mock_data.config = &mock_config; - - expect_fim_configuration_directory_call(path, &mock_config); - expect_function_call(__wrap_fim_generate_delete_event); - - fim_db_remove_validated_path(path, &mock_data); -} - -int main(void) { -#ifndef WIN_WHODATA - const struct CMUnitTest tests[] = { -#ifdef TEST_WINAGENT - cmocka_unit_test(test_set_priority_windows_thread_highest), - cmocka_unit_test(test_set_priority_windows_thread_above_normal), - cmocka_unit_test(test_set_priority_windows_thread_normal), - cmocka_unit_test(test_set_priority_windows_thread_below_normal), - cmocka_unit_test(test_set_priority_windows_thread_lowest), - cmocka_unit_test(test_set_priority_windows_thread_idle), - cmocka_unit_test(test_set_priority_windows_thread_error), -#endif - - cmocka_unit_test(test_log_realtime_status), - cmocka_unit_test(test_fim_db_remove_validated_path), - cmocka_unit_test(test_fim_send_scan_info), - cmocka_unit_test_setup_teardown(test_check_max_fps_no_sleep, setup_max_fps, teardown_max_fps), - cmocka_unit_test_setup_teardown(test_check_max_fps_sleep, setup_max_fps, teardown_max_fps), -#ifndef TEST_WINAGENT - cmocka_unit_test(test_fim_run_realtime_first_error), - cmocka_unit_test(test_fim_run_realtime_first_timeout), - cmocka_unit_test(test_fim_run_realtime_first_sleep), - cmocka_unit_test(test_fim_run_realtime_first_process), - cmocka_unit_test(test_fim_run_realtime_process_after_timeout), - cmocka_unit_test_setup_teardown(test_fim_link_update, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_link_update_already_added, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_link_check_delete, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_link_check_delete_lstat_error, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_link_check_delete_noentry_error, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_delete_realtime_watches, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_link_delete_range, setup_tmp_file, teardown_tmp_file), - cmocka_unit_test_setup_teardown(test_fim_link_silent_scan, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_link_reload_broken_link_already_monitored, setup_symbolic_links, teardown_symbolic_links), - cmocka_unit_test_setup_teardown(test_fim_link_reload_broken_link_reload_broken, setup_symbolic_links, teardown_symbolic_links), -#else - cmocka_unit_test_setup_teardown(test_fim_run_realtime_w_first_timeout, setup_hash, teardown_hash), - cmocka_unit_test_setup_teardown(test_fim_run_realtime_w_wait_success, setup_hash, teardown_hash), - cmocka_unit_test(test_fim_run_realtime_w_sleep), -#endif - cmocka_unit_test(test_send_sync_state), - cmocka_unit_test(test_send_sync_state_without_max_eps), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -#else // WIN_WHODATA - const struct CMUnitTest eventchannel_tests[] = { - cmocka_unit_test(test_fim_whodata_initialize), - cmocka_unit_test(test_set_whodata_mode_changes), - cmocka_unit_test(test_fim_whodata_initialize_eventchannel), - cmocka_unit_test(test_fim_whodata_initialize_fail_set_policies), - }; - return cmocka_run_group_tests(eventchannel_tests, setup_group, teardown_group); -#endif -} diff --git a/src/unit_tests/syscheckd/test_run_realtime.c b/src/unit_tests/syscheckd/test_run_realtime.c deleted file mode 100644 index 44e636bbaa7..00000000000 --- a/src/unit_tests/syscheckd/test_run_realtime.c +++ /dev/null @@ -1,2036 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#ifndef TEST_WINAGENT -#include -#endif - -#include "../wrappers/common.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/linux/inotify_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/fs_op_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/shared/randombytes_wrappers.h" -#include "../wrappers/wazuh/shared/syscheck_op_wrappers.h" -#include "../wrappers/wazuh/shared/vector_op_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/wazuh/syscheckd/create_db_wrappers.h" -#include "../wrappers/wazuh/syscheckd/run_check_wrappers.h" -#include "../wrappers/wazuh/syscheckd/win_whodata_wrappers.h" - -#include "../syscheckd/include/syscheck.h" -#include "../config/syscheck-config.h" - -#ifdef TEST_WINAGENT -// This struct should always reflect the one defined in run_realtime.c - -int realtime_win32read(win32rtfim *rtlocald); -void free_win32rtfim_data(win32rtfim *data); -void CALLBACK RTCallBack(DWORD dwerror, DWORD dwBytes, LPOVERLAPPED overlap); -#endif - - -typedef struct realtime_process_data{ - struct inotify_event *event; - OSHashNode *node; -} realtime_process_data; - -static int setup_OSHash(void **state); -static int teardown_OSHash(void **state); - -/* setup/teardown */ -static int setup_group(void **state) { - expect_any_always(__wrap__mdebug1, formatted_msg); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - test_mode = 0; - Read_Syscheck_Config("test_syscheck.conf"); - - syscheck.realtime = (rtfim *) calloc(1, sizeof(rtfim)); - - if(syscheck.realtime == NULL) - return -1; - - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - Free_Syscheck(&syscheck); - - return 0; -} - -#ifdef TEST_WINAGENT -#ifndef WIN_WHODATA -static int setup_RTCallBack(void **state) { - win32rtfim *rt = calloc(1, sizeof(win32rtfim)); - - if(rt == NULL) - return -1; - - *state = rt; - return 0; -} - -static int teardown_RTCallBack(void **state) { - win32rtfim *rt = *state; - - if(rt->dir) - free(rt->dir); - - free(rt); - - return 0; -} -#endif // WIN_WHODATA - -static int setup_realtime_adddir_realtime_start_error(void **state) { - *state = syscheck.realtime; - return 0; -} - -static int teardown_realtime_adddir_realtime_start_error(void **state) { - return 0; -} - -# else // TEST_WINAGENT - -static int setup_realtime_adddir_realtime_start_error(void **state) { - *state = syscheck.realtime; - syscheck.realtime->fd = -1; - return 0; -} - -static int teardown_realtime_adddir_realtime_start_error(void **state) { - syscheck.realtime->fd = ((rtfim *)state)->fd; - - return 0; -} -#endif - -static int setup_realtime_start(void **state) { - OSHash *hash = calloc(1, sizeof(OSHash)); - - if(hash == NULL) - return -1; - - *state = hash; - - state[1] = syscheck.realtime; - syscheck.realtime = NULL; - - return 0; -} - -static int teardown_realtime_start(void **state) { - OSHash *hash = *state; - - free(hash); - - if (syscheck.realtime) { - free(syscheck.realtime); - } - - syscheck.realtime = state[1]; - state[1] = NULL; - - return 0; -} - -static int setup_inotify_event(void **state) { - struct inotify_event *event; - - if (setup_OSHash(state) != 0) { - return -1; - } - - event = calloc(1, OS_SIZE_512); - - if (!event) { - return -1; - } - *state = event; - - return 0; -} - -static int teardown_inotify_event(void **state) { - struct inotify_event *event = *state; - - if (teardown_OSHash(state) != 0) { - return -1; - } - - if (event) { - free(event); - } - - return 0; -} - -static int setup_hash_node(void **state) { - OSHashNode *node = (OSHashNode *)calloc(1, sizeof(OSHashNode)); - - if (!node) { - return -1; - } - - node->next = NULL; - node->prev = NULL; - node->key = "dummy_key"; - - if (node->key == NULL) { - return -1; - } - - *state = node; - - return 0; -} - -static int teardown_hash_node(void **state) { - OSHashNode *node = *state; - - if (node) { - free(node); - } - - return 0; -} - -static int setup_realtime_process(void **state) { - realtime_process_data *data = (realtime_process_data *)calloc(1, sizeof(realtime_process_data)); - - if (!data) { - return -1; - } - - if (setup_hash_node((void **) &data->node)) { - return -1; - } - - if (setup_inotify_event((void **) &data->event)) { - return -1; - } - *state = data; - - return 0; -} - -static int teardown_realtime_process(void **state) { - realtime_process_data *data = *state; - - if (teardown_hash_node((void **) &data->node)) { - return -1; - } - - if (teardown_inotify_event((void **) &data->event)) { - return -1; - } - if (data) { - free(data); - } - - return 0; -} - -static int setup_OSHash(void **state) { - test_mode = 0; - will_return_always(__wrap_os_random, 12345); - if (setup_hashmap(state) != 0) { - return -1; - } - - __real_OSHash_SetFreeDataPointer(mock_hashmap, free); - - syscheck.realtime->dirtb = mock_hashmap; - - test_mode = 1; - return 0; -} - -static int teardown_OSHash(void **state) { - test_mode = 0; - - if (teardown_hashmap(state) != 0) { - return -1; - } - - syscheck.realtime->dirtb = NULL; - errno = 0; - - return 0; -} - -static int setup_sanitize_watch_map(void **state) { - test_mode = 0; - - will_return_always(__wrap_os_random, 12345); - if (setup_hashmap(state) != 0) { - return -1; - } - - syscheck.realtime->dirtb = mock_hashmap; - - test_mode = 1; - return 0; -} - -static int teardown_sanitize_watch_map(void **state) { - test_mode = 0; - OSHash *hash = *state; - if (teardown_hashmap(state) != 0) { - return -1; - } - - syscheck.realtime->dirtb = NULL; - errno = 0; - test_mode = 1; - return 0; -} - -/* tests */ - -void test_realtime_start_success(void **state) { - OSHash *hash = *state; - int ret; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, hash); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 0); - -#if defined(TEST_SERVER) || defined(TEST_AGENT) - will_return(__wrap_inotify_init, 0); -#else - expect_value(wrap_CreateEvent, lpEventAttributes, NULL); - expect_value(wrap_CreateEvent, bManualReset, TRUE); - expect_value(wrap_CreateEvent, bInitialState, FALSE); - expect_value(wrap_CreateEvent, lpName, NULL); - will_return(wrap_CreateEvent, (HANDLE)123456); -#endif - - ret = realtime_start(); - - assert_int_equal(ret, 0); -#ifdef TEST_WINAGENT - assert_ptr_equal(syscheck.realtime->evt, 123456); -#endif -} - - -void test_realtime_start_failure_hash(void **state) { - int ret; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, NULL); - - errno = ENOMEM; - expect_string(__wrap__merror, formatted_msg, - "(1102): Could not acquire memory due to [(12)-(Cannot allocate memory)]."); - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - ret = realtime_start(); - - errno = 0; - assert_int_equal(ret, -1); -} - -#if defined(TEST_SERVER) || defined(TEST_AGENT) - -void test_realtime_start_failure_inotify(void **state) { - OSHash *hash = *state; - int ret; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, hash); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 0); - - will_return(__wrap_inotify_init, -1); - - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_INOTIFY_INITIALIZE); - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - ret = realtime_start(); - - assert_int_equal(ret, -1); -} - -void test_realtime_adddir_realtime_start_failure(void **state) { - int ret; - directory_t config = { .options = REALTIME_ACTIVE }; - - const char * path = "/etc/folder"; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - ret = realtime_adddir(path, &config); - - assert_int_equal(ret, -1); -} - -void test_realtime_adddir_realtime_failure(void **state) { - int ret; - directory_t config = { .options = REALTIME_ACTIVE }; - - const char * path = "/etc/folder"; - - syscheck.realtime->fd = -1; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - ret = realtime_adddir(path, &config); - - assert_int_equal(ret, -1); -} - - -void test_realtime_adddir_realtime_watch_max_reached_failure(void **state) { - int ret; - directory_t config = { .options = REALTIME_ACTIVE }; - const char * path = "/etc/folder"; - - expect_function_call(__wrap_pthread_mutex_lock); - - syscheck.realtime->fd = 1; - will_return(__wrap_inotify_add_watch, -1); - expect_string(__wrap__merror, formatted_msg, "(6700): Unable to add inotify watch to real time monitoring: '/etc/folder'. '-1' '28': " - "The maximum limit of inotify watches has been reached."); - - expect_function_call(__wrap_pthread_mutex_unlock); - - errno = 28; - - ret = realtime_adddir(path, &config); - - errno = 0; - - assert_int_equal(ret, 1); -} - - -void test_realtime_adddir_realtime_watch_generic_failure(void **state) { - int ret; - directory_t config = { .options = REALTIME_ACTIVE }; - const char * path = "/etc/folder"; - - expect_function_call(__wrap_pthread_mutex_lock); - syscheck.realtime->fd = 1; - will_return(__wrap_inotify_add_watch, -1); - expect_string(__wrap__mdebug1, formatted_msg, "(6272): Unable to add inotify watch to real time monitoring: '/etc/folder'. '-1' '0':'Success'"); - expect_function_call(__wrap_pthread_mutex_unlock); - - ret = realtime_adddir(path, &config); - - assert_int_equal(ret, 1); -} - - -void test_realtime_adddir_realtime_add(void **state) { - int ret; - char * path = strdup("/etc/folder"); - directory_t config = { .options = REALTIME_ACTIVE }; - - syscheck.realtime->fd = 1; - will_return(__wrap_inotify_add_watch, 1); - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6224): Entry '/etc/folder' already exists in the RT hash table."); - expect_string(__wrap__mdebug2, formatted_msg, "(6227): Directory added for real time monitoring: '/etc/folder'"); - - test_mode = 0; - OSHash_Add_ex(syscheck.realtime->dirtb, "1", path); // Duplicate simulation - - expect_function_call(__wrap_pthread_mutex_unlock); - - ret = realtime_adddir(path, &config); - test_mode = 1; - - assert_int_equal(ret, 1); -} - - -void test_realtime_adddir_realtime_add_hash_failure(void **state) { - int ret; - const char * path = "/etc/folder"; - directory_t config = { .options = REALTIME_ACTIVE }; - - expect_function_call(__wrap_pthread_mutex_lock); - syscheck.realtime->fd = 1; - will_return(__wrap_inotify_add_watch, 1); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Add_ex, key, "1"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror_exit, formatted_msg, "(6697): Out of memory. Exiting."); - - test_mode = 1; - expect_assert_failure(realtime_adddir(path, &config)); - test_mode = 0; -} - - -void test_realtime_adddir_realtime_update(void **state) { - int ret; - char *path = strdup("/etc/folder"); - const char *dummy_key = "1"; - - directory_t config = { .options = REALTIME_ACTIVE }; - - expect_function_call(__wrap_pthread_rwlock_wrlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - __real_OSHash_Add_ex(syscheck.realtime->dirtb, dummy_key, (void *) path); - - expect_function_call(__wrap_pthread_mutex_lock); - - syscheck.realtime->fd = 1; - will_return(__wrap_inotify_add_watch, 1); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, dummy_key); - will_return(__wrap_OSHash_Get_ex, 1); - - will_return(__wrap_OSHash_Update_ex, 1); - - expect_function_call(__wrap_pthread_mutex_unlock); - - ret = realtime_adddir(path, &config); - - assert_int_equal(ret, 1); -} - - -void test_realtime_adddir_realtime_update_failure(void **state) { - int ret; - const char * path = "/etc/folder"; - directory_t config = { .options = REALTIME_ACTIVE }; - - expect_function_call(__wrap_pthread_mutex_lock); - - syscheck.realtime->fd = 1; - will_return(__wrap_inotify_add_watch, 1); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, 1); - - will_return(__wrap_OSHash_Update_ex, 0); - - expect_string(__wrap__merror, formatted_msg, "Unable to update 'dirtb'. Directory not found: '/etc/folder'"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - ret = realtime_adddir(path, &config); - - assert_int_equal(ret, -1); -} - -void test_realtime_process(void **state) { - - syscheck.realtime->fd = 1; - expect_function_call(__wrap_pthread_mutex_lock); - - will_return(__wrap_read, ""); - will_return(__wrap_read, 0); - expect_function_call(__wrap_pthread_mutex_unlock); - - realtime_process(); -} - -void test_realtime_process_len(void **state) { - struct inotify_event *event = *state; - event->wd = 1; - event->mask = 2; - event->cookie = 0; - event->len = 5; - strcpy(event->name, "test"); - - syscheck.realtime->fd = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_read, event); - will_return(__wrap_read, 21); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "Duplicate event in real-time buffer: test/test"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - char **paths = NULL; - paths = os_AddStrArray("/test", paths); - - will_return(__wrap_rbtree_keys, paths); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_string(__wrap_fim_realtime_event, file, "/test"); - expect_function_call(__wrap_pthread_rwlock_unlock); - - test_mode = 1; - realtime_process(); - test_mode = 0; -} - -void test_realtime_process_len_zero(void **state) { - struct inotify_event *event = *state; - event->wd = 1; - event->mask = 2; - event->cookie = 0; - event->len = 0; - strcpy(event->name, "test"); - - syscheck.realtime->fd = 1; - - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_read, event); - will_return(__wrap_read, 16); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "Duplicate event in real-time buffer: test"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - char **paths = NULL; - paths = os_AddStrArray("/test", paths); - - will_return(__wrap_rbtree_keys, paths); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_string(__wrap_fim_realtime_event, file, "/test"); - expect_function_call(__wrap_pthread_rwlock_unlock); - - test_mode = 1; - realtime_process(); - test_mode = 0; -} - -void test_realtime_process_len_path_separator(void **state) { - struct inotify_event *event = *state; - event->wd = 1; - event->mask = 2; - event->cookie = 0; - event->len = 5; - strcpy(event->name, "test"); - - syscheck.realtime->fd = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_read, event); - will_return(__wrap_read, 21); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, "test/"); - - expect_string(__wrap__mdebug2, formatted_msg, "Duplicate event in real-time buffer: test/test"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - char **paths = NULL; - paths = os_AddStrArray("/test", paths); - - will_return(__wrap_rbtree_keys, paths); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_string(__wrap_fim_realtime_event, file, "/test"); - expect_function_call(__wrap_pthread_rwlock_unlock); - - test_mode = 1; - realtime_process(); - test_mode = 0; -} - -void test_realtime_process_overflow(void **state) { - struct inotify_event *event = *state; - event->wd = -1; - event->mask = 16384; - event->cookie = 0; - event->len = 5; - strcpy(event->name, "test"); - - syscheck.realtime->fd = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_read, event); - will_return(__wrap_read, 21); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mwarn, formatted_msg, "Real-time inotify kernel queue is full. Some events may be lost. Next scheduled scan will recover lost data."); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - expect_string(__wrap_send_log_msg, msg, "ossec: Real-time inotify kernel queue is full. Some events may be lost. Next scheduled scan will recover lost data."); - will_return(__wrap_send_log_msg, 1); - - char **paths = NULL; - paths = os_AddStrArray("/test", paths); - - will_return(__wrap_rbtree_keys, paths); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_string(__wrap_fim_realtime_event, file, "/test"); - expect_function_call(__wrap_pthread_rwlock_unlock); - - realtime_process(); - - assert_int_equal(syscheck.realtime->queue_overflow, true); -} - -void test_realtime_process_delete(void **state) { - struct inotify_event *event = *state; - event->wd = 1; - event->mask = 1024; - event->cookie = 0; - event->len = 5; - strcpy(event->name, "test"); - - syscheck.realtime->fd = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_read, event); - will_return(__wrap_read, 21); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "Duplicate event in real-time buffer: test/test"); - - char *data = strdup("delete this"); - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "1"); - will_return(__wrap_OSHash_Delete_ex, data); - - expect_string(__wrap__mdebug2, formatted_msg, "(6344): Inotify watch deleted for 'test'"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - char **paths = NULL; - paths = os_AddStrArray("/test", paths); - - will_return(__wrap_rbtree_keys, paths); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_string(__wrap_fim_realtime_event, file, "/test"); - expect_function_call(__wrap_pthread_rwlock_unlock); - - test_mode = 1; - realtime_process(); - test_mode = 0; -} - -void test_realtime_process_move_self(void **state) { - realtime_process_data *data = *state; - struct inotify_event *event = data->event; - - event->wd = 1; - event->mask = 2048; - event->cookie = 0; - event->len = 5; - strcpy(event->name, "test"); - - syscheck.realtime->fd = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_read, event); - will_return(__wrap_read, 21); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "1"); - will_return(__wrap_OSHash_Get_ex, "test"); - - expect_string(__wrap__mdebug2, formatted_msg, "Duplicate event in real-time buffer: test/test"); - - // In delete_subdirectories_watches - OSHashNode *node = data->node; - - node->data = "test/sub"; - - syscheck.realtime->fd = 1; - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, node); - - expect_string(__wrap__mdebug2, formatted_msg, "(6344): Inotify watch deleted for 'test/sub'"); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - // Back to realtime_process - char *str_data = strdup("delete this"); - expect_value_count(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb, 2); - expect_string(__wrap_OSHash_Delete_ex, key, "dummy_key"); - expect_string(__wrap_OSHash_Delete_ex, key, "1"); - will_return(__wrap_OSHash_Delete_ex, str_data); - will_return(__wrap_OSHash_Delete_ex, NULL); - - expect_string(__wrap__mdebug2, formatted_msg, "(6344): Inotify watch deleted for 'test'"); - - expect_function_call(__wrap_pthread_mutex_unlock); - - char **paths = NULL; - paths = os_AddStrArray("/test", paths); - - will_return(__wrap_rbtree_keys, paths); - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_string(__wrap_fim_realtime_event, file, "/test"); - expect_function_call(__wrap_pthread_rwlock_unlock); - - test_mode = 1; - realtime_process(); - test_mode = 0; -} - -void test_realtime_process_failure(void **state) -{ - (void) state; - - syscheck.realtime->fd = 1; - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_read, NULL); - will_return(__wrap_read, 0); - expect_function_call(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_REALTIME_READ_BUFFER); - - realtime_process(); -} - -void test_delete_subdirectories_watches_realtime_fd_null(void **state) { - (void) state; - char *dir = "/test"; - - syscheck.realtime->fd = 0; - - delete_subdirectories_watches(dir); -} - -void test_delete_subdirectories_watches_hash_node_null(void **state) { - (void) state; - char *dir = "/test"; - int inode_it = 0; - - syscheck.realtime->fd = 1; - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - delete_subdirectories_watches(dir); -} - -void test_delete_subdirectories_watches_not_same_name(void **state) { - (void) state; - char *dir = "/test/"; - OSHashNode *node = *state; - - node->data = "/other/sub"; - - syscheck.realtime->fd = 1; - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, node); - - expect_value(__wrap_OSHash_Next, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Next, NULL); - - delete_subdirectories_watches(dir); -} - -void test_delete_subdirectories_watches_deletes(void **state) { - char *dir = "/test"; - OSHashNode *node = *state; - - node->data = "/test/sub"; - - syscheck.realtime->fd = 1; - syscheck.realtime->dirtb = (OSHash *)8; - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, node); - - char *data = strdup("delete this"); - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "dummy_key"); - will_return(__wrap_OSHash_Delete_ex, data); - - expect_string(__wrap__mdebug2, formatted_msg, "(6344): Inotify watch deleted for '/test/sub'"); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - test_mode = 1; - delete_subdirectories_watches(dir); - test_mode = 0; -} - - -void test_realtime_sanitize_watch_map_empty_hash(void **state) { - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_any(__wrap__mdebug2, formatted_msg); - - realtime_sanitize_watch_map(); -} - -void test_realtime_sanitize_watch_map_inotify_not_connected(void **state) { - OSHashNode node; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, &node); - - syscheck.realtime->fd = -1; - - expect_value(__wrap_OSHash_Next, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Next, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_any(__wrap__mdebug2, formatted_msg); - - realtime_sanitize_watch_map(); -} - -void test_realtime_sanitize_watch_map_entry_with_no_configuration(void **state) { - char *path = strdup("/some/path"); - int i = 0; - - if (path == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - expect_any(__wrap__mdebug2, formatted_msg); - - will_return(__wrap_inotify_rm_watch, 0); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "1234"); - will_return(__wrap_OSHash_Delete_ex, path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - realtime_sanitize_watch_map(); - - assert_int_equal(syscheck.realtime->dirtb->elements, 0); -} - -void test_realtime_sanitize_watch_map_unable_to_add_more_watches(void **state) { - char *path = "/media/some/path"; - int i = 0; - - if (path == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, -1); - - errno = ENOSPC; - - expect_string(__wrap__merror, formatted_msg, - "(6700): Unable to add inotify watch to real time monitoring: '/media/some/path'. '-1' '28': The " - "maximum limit of inotify watches has been reached."); - - expect_value(__wrap_OSHash_Next, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Next, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - realtime_sanitize_watch_map(); - - assert_int_equal(syscheck.realtime->dirtb->elements, 1); -} - -void test_realtime_sanitize_watch_map_entry_deleted(void **state) { - char *path = strdup("/media/some/path"); - int i = 0; - - if (path == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, -1); - - errno = ENOENT; - - expect_string(__wrap__mdebug2, formatted_msg, "Removing watch on non existent directory '/media/some/path'"); - - will_return(__wrap_inotify_rm_watch, 0); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "1234"); - will_return(__wrap_OSHash_Delete_ex, path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - realtime_sanitize_watch_map(); - - assert_int_equal(syscheck.realtime->dirtb->elements, 0); -} - -void test_realtime_sanitize_watch_map_inotify_error(void **state) { - char *path = "/media/some/path"; - int i = 0; - - if (path == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, -1); - - expect_string(__wrap__mdebug1, formatted_msg, - "(6272): Unable to add inotify watch to real time monitoring: '/media/some/path'. '-1' " - "'0':'Success'"); - - expect_value(__wrap_OSHash_Next, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Next, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - realtime_sanitize_watch_map(); - - assert_int_equal(syscheck.realtime->dirtb->elements, 1); -} - -void test_realtime_sanitize_watch_map_entry_already_up_to_date(void **state) { - char *path = "/media/some/path"; - int i = 0; - - if (path == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, 1234); - - expect_value(__wrap_OSHash_Next, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Next, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - test_mode = 0; - realtime_sanitize_watch_map(); - - assert_int_equal(syscheck.realtime->dirtb->elements, 1); -} - -void test_realtime_sanitize_watch_map_entry_with_new_watch_number(void **state) { - char *path = strdup("/media/some/path"); - int i = 0; - - if (path == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, 4321); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "4321"); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6227): Directory added for real time monitoring: '/media/some/path'"); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - test_mode = 0; - realtime_sanitize_watch_map(); - - assert_int_equal(syscheck.realtime->dirtb->elements, 1); - assert_string_equal(__real_OSHash_Get_ex(syscheck.realtime->dirtb, "4321"), "/media/some/path"); - free(__real_OSHash_Delete(syscheck.realtime->dirtb, "4321")); -} - -void test_realtime_sanitize_watch_map_entry_with_new_watch_number_fail(void **state) { - char *path = "/media/some/path"; - char *freeable = strdup("path to be free'd"); - int i = 0; - - if (path == NULL || freeable == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, 4321); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "1234"); - will_return(__wrap_OSHash_Delete_ex, freeable); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "4321"); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_value(__wrap_OSHash_Add_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Add_ex, key, "4321"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, FIM_CRITICAL_ERROR_OUT_MEM); - - expect_value(__wrap_OSHash_Next, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Next, NULL); - expect_any(__wrap__mdebug2, formatted_msg); - test_mode = 1; - realtime_sanitize_watch_map(); -} - -void test_realtime_sanitize_watch_map_update_existing_watch_with_new_directory(void **state) { - char *path = strdup("/media/some/path"); - char *other_path = strdup("/media/some/other/path"); - int i = 0; - - if (path == NULL || other_path == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "4321", other_path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, 4321); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "1234"); - will_return(__wrap_OSHash_Delete_ex, path); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "4321"); - will_return(__wrap_OSHash_Get_ex, other_path); - - will_return(__wrap_OSHash_Update_ex, 1); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - realtime_sanitize_watch_map(); - - assert_int_equal(syscheck.realtime->dirtb->elements, 1); - free(other_path); - free(__real_OSHash_Delete(syscheck.realtime->dirtb, "4321")); -} - -void test_realtime_sanitize_watch_map_update_existing_watch_with_new_directory_fail(void **state) { - char *path = strdup("/media/some/path"); - char *other_path = strdup("/media/some/other/path"); - char *freeable = strdup("path to be free'd"); - int i = 0; - - if (path == NULL || other_path == NULL || freeable == NULL) { - fail(); - } - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "1234", path); - __real_OSHash_Add_ex(syscheck.realtime->dirtb, "4321", other_path); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, __real_OSHash_Begin(syscheck.realtime->dirtb, &i)); - - syscheck.realtime->fd = 1; - - will_return(__wrap_inotify_add_watch, 34321); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "1234"); - will_return(__wrap_OSHash_Delete_ex, freeable); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "34321"); - will_return(__wrap_OSHash_Get_ex, other_path); - - will_return(__wrap_OSHash_Update_ex, 0); - - expect_string(__wrap__merror, formatted_msg, "Unable to update 'dirtb'. Directory not found: '/media/some/path'"); - - expect_value(__wrap_OSHash_Begin, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Begin, NULL); - - expect_any(__wrap__mdebug2, formatted_msg); - - test_mode = 1; - realtime_sanitize_watch_map(); - free(other_path); - free(path); -} - -#else // TEST_WINAGENT -void test_realtime_win32read_success(void **state) { - win32rtfim rtlocal; - int ret; - - will_return(wrap_ReadDirectoryChangesW, 1); - - ret = realtime_win32read(&rtlocal); - - assert_int_equal(ret, 1); -} - -void test_realtime_win32read_unable_to_read_directory(void **state) { - win32rtfim rtlocal; - int ret; - - rtlocal.dir = "C:\\a\\path"; - - will_return(wrap_ReadDirectoryChangesW, 0); - - ret = realtime_win32read(&rtlocal); - - assert_int_equal(ret, 0); -} - -void test_free_win32rtfim_data_null_input(void **state) { - // Nothing to check on this condition - free_win32rtfim_data(NULL); -} - -void test_free_win32rtfim_data_full_data(void **state) { - win32rtfim *data = calloc(1, sizeof(win32rtfim)); - - if(data == NULL) - fail(); - - data->h = (HANDLE)123456; - - data->overlap.hEvent = calloc(1, sizeof(PVOID)); - - if(data->overlap.hEvent == NULL) { - free(data); - fail(); - } - - data->dir = strdup("c:\\a\\path"); - - if(data->dir == NULL) { - free(data->overlap.hEvent); - free(data); - fail(); - } - - free_win32rtfim_data(data); -} - -void test_realtime_adddir_whodata_non_existent_file(void **state) { - int ret; - directory_t *configuration; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - configuration = ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 5)); - configuration->dirs_status.status &= ~WD_CHECK_WHODATA; - configuration->dirs_status.status |= WD_CHECK_REALTIME; - - expect_string(__wrap_check_path_type, dir, "C:\\a\\path"); - will_return(__wrap_check_path_type, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6907): 'C:\\a\\path' does not exist. Monitoring discarded."); - - ret = realtime_adddir("C:\\a\\path", configuration); - - assert_int_equal(ret, 0); - assert_non_null(configuration->dirs_status.status & WD_CHECK_WHODATA); - assert_null(configuration->dirs_status.status & WD_CHECK_REALTIME); - assert_int_equal(configuration->dirs_status.object_type, WD_STATUS_UNK_TYPE); - assert_null(configuration->dirs_status.status & WD_STATUS_EXISTS); -} - -void test_realtime_adddir_whodata_error_adding_whodata_dir(void **state) { - int ret; - directory_t *configuration; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - configuration = ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 5)); - configuration->dirs_status.status &= ~WD_CHECK_WHODATA; - configuration->dirs_status.status |= WD_CHECK_REALTIME; - - expect_string(__wrap_check_path_type, dir, "C:\\a\\path"); - will_return(__wrap_check_path_type, 2); - - expect_string(__wrap_set_winsacl, dir, "C:\\a\\path"); - expect_value(__wrap_set_winsacl, configuration, configuration); - will_return(__wrap_set_winsacl, 1); - - expect_string(__wrap__merror, formatted_msg, - "(6619): Unable to add directory to whodata real time monitoring: 'C:\\a\\path'. It will be monitored in Realtime"); - - ret = realtime_adddir("C:\\a\\path", configuration); - - assert_int_equal(ret, -2); - assert_non_null(configuration->dirs_status.status & WD_CHECK_WHODATA); - assert_null(configuration->dirs_status.status & WD_CHECK_REALTIME); - assert_int_equal(configuration->dirs_status.object_type, WD_STATUS_DIR_TYPE); - assert_non_null(configuration->dirs_status.status & WD_STATUS_EXISTS); -} - -void test_realtime_adddir_whodata_file_success(void **state) { - int ret; - directory_t *configuration; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - configuration = ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 5)); - configuration->dirs_status.status &= ~WD_CHECK_WHODATA; - configuration->dirs_status.status |= WD_CHECK_REALTIME; - - expect_string(__wrap_check_path_type, dir, "C:\\a\\path"); - will_return(__wrap_check_path_type, 1); - - expect_string(__wrap_set_winsacl, dir, "C:\\a\\path"); - expect_value(__wrap_set_winsacl, configuration, configuration); - will_return(__wrap_set_winsacl, 0); - - ret = realtime_adddir("C:\\a\\path", configuration); - - assert_int_equal(ret, 1); - assert_non_null(configuration->dirs_status.status & WD_CHECK_WHODATA); - assert_null(configuration->dirs_status.status & WD_CHECK_REALTIME); - assert_int_equal(configuration->dirs_status.object_type, WD_STATUS_FILE_TYPE); - assert_non_null(configuration->dirs_status.status & WD_STATUS_EXISTS); -} - -void test_realtime_adddir_whodata_dir_success(void **state) { - int ret; - directory_t *configuration; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - configuration = ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 5)); - configuration->dirs_status.status &= ~WD_CHECK_WHODATA; - configuration->dirs_status.status |= WD_CHECK_REALTIME; - - expect_string(__wrap_check_path_type, dir, "C:\\a\\path"); - will_return(__wrap_check_path_type, 2); - - expect_string(__wrap_set_winsacl, dir, "C:\\a\\path"); - expect_value(__wrap_set_winsacl, configuration, configuration); - will_return(__wrap_set_winsacl, 0); - - ret = realtime_adddir("C:\\a\\path", configuration); - - assert_int_equal(ret, 1); - assert_non_null(configuration->dirs_status.status & WD_CHECK_WHODATA); - assert_null(configuration->dirs_status.status & WD_CHECK_REALTIME); - assert_int_equal(configuration->dirs_status.object_type, WD_STATUS_DIR_TYPE); - assert_non_null(configuration->dirs_status.status & WD_STATUS_EXISTS); -} - -void test_realtime_adddir_max_limit_reached(void **state) { - int ret; - char msg[OS_SIZE_256] = { '\0' }; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Get_Elem_ex, 257); - - snprintf(msg, OS_SIZE_256, FIM_REALTIME_MAXNUM_WATCHES, "C:\\a\\path"); - expect_string(__wrap__mdebug1, formatted_msg, msg); - - ret = realtime_adddir("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 0); -} - -void test_realtime_adddir_duplicate_entry(void **state) { - win32rtfim rtlocald = { .dir = "C:\\a\\path" }; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, &rtlocald); - - expect_string(__wrap_w_directory_exists, path, "C:\\a\\path"); - will_return(__wrap_w_directory_exists, 1); - - ret = realtime_adddir("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_realtime_adddir_duplicate_entry_non_existent_directory_valid_handle(void **state) { - win32rtfim rtlocald = { .dir = "C:\\a\\path", .watch_status = FIM_RT_HANDLE_OPEN, .h = (HANDLE)1234 }; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, &rtlocald); - - expect_string(__wrap_w_directory_exists, path, "C:\\a\\path"); - will_return(__wrap_w_directory_exists, 0); - - expect_value(wrap_CloseHandle, hObject, 1234); - will_return(wrap_CloseHandle, 0); - - ret = realtime_adddir("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); - -} - -void test_realtime_adddir_duplicate_entry_non_existent_directory_closed_handle(void **state) { - win32rtfim *rtlocald = calloc(1, sizeof(win32rtfim)); - char debug_msg[OS_SIZE_128]; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - if (rtlocald == NULL) { - fail_msg("Failed to allocate 'rtlocald'"); - } - - - rtlocald->dir = strdup("C:\\a\\path"); - - if (rtlocald->dir == NULL) { - free(rtlocald); - fail_msg("Failed to allocate 'rtlocald->dir'"); - } - - rtlocald->watch_status = FIM_RT_HANDLE_CLOSED; - rtlocald->h = (HANDLE)1234; - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, rtlocald); - - expect_string(__wrap_w_directory_exists, path, "C:\\a\\path"); - will_return(__wrap_w_directory_exists, 0); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Delete_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Delete_ex, rtlocald); - - snprintf(debug_msg, OS_SIZE_128, FIM_REALTIME_CALLBACK, "C:\\a\\path"); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - ret = realtime_adddir("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_realtime_adddir_duplicate_entry_non_existent_directory_invalid_handle(void **state) { - win32rtfim rtlocald = { .dir = "C:\\a\\path", .watch_status = FIM_RT_HANDLE_OPEN, .h = INVALID_HANDLE_VALUE }; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, &rtlocald); - - expect_string(__wrap_w_directory_exists, path, "C:\\a\\path"); - will_return(__wrap_w_directory_exists, 0); - - ret = realtime_adddir("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_realtime_adddir_handle_error(void **state) { - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_value(__wrap_OSHash_Get_Elem_ex, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Get_Elem_ex, 128); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, 0); - - expect_string(wrap_CreateFile, lpFileName, "C:\\a\\path"); - will_return(wrap_CreateFile, INVALID_HANDLE_VALUE); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6290): Unable to add directory to real time monitoring: 'C:\\a\\path'"); - - ret = realtime_adddir("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 0); -} - -void test_realtime_adddir_success(void **state) { - int ret; - - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, 0); - - OSHash_Add_ex_check_data = 0; - expect_value(__wrap_OSHash_Add_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Add_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_string(wrap_CreateFile, lpFileName, "C:\\a\\path"); - will_return(wrap_CreateFile, (HANDLE)123456); - - will_return(wrap_ReadDirectoryChangesW, 1); - expect_value(__wrap_OSHash_Get_Elem_ex, self, syscheck.realtime->dirtb); - will_return(__wrap_OSHash_Get_Elem_ex, 127); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6227): Directory added for real time monitoring: 'C:\\a\\path'"); - - ret = realtime_adddir("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_RTCallBack_error_on_callback(void **state) { - OVERLAPPED ov = {.hEvent = "C:\\a\\path"}; - - will_return(wrap_FormatMessage, "Path not found."); - expect_string(__wrap__merror, formatted_msg, "(6613): Real time Windows callback process: 'Path not found.' (3)."); - - RTCallBack(ERROR_PATH_NOT_FOUND, 0, &ov); -} - -void test_RTCallBack_empty_hash_table(void **state) { - OVERLAPPED ov = {.hEvent = "C:\\a\\path"}; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_any(__wrap_OSHash_Get_ex, key); - will_return(__wrap_OSHash_Get_ex, NULL); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_REALTIME_WINDOWS_CALLBACK_EMPTY); - - RTCallBack(ERROR_SUCCESS, 1, &ov); -} - -void test_RTCallBack_no_bytes_returned(void **state) { - win32rtfim *rt = *state; - OVERLAPPED ov = {.hEvent = "C:\\a\\path"}; - - rt->watch_status = 1; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_any(__wrap_OSHash_Get_ex, key); - will_return(__wrap_OSHash_Get_ex, rt); - - expect_string(__wrap__mwarn, formatted_msg, FIM_WARN_REALTIME_OVERFLOW); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - // Inside realtime_win32read - will_return(wrap_ReadDirectoryChangesW, 1); - - RTCallBack(ERROR_SUCCESS, 0, &ov); -} - -void test_RTCallBack_acquired_changes_null_dir(void **state) { - win32rtfim *rt = *state; - OVERLAPPED ov; - PFILE_NOTIFY_INFORMATION pinfo; - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_mutex_lock); - - // Fill the win32rtfim struct with testing data - pinfo = (PFILE_NOTIFY_INFORMATION) rt->buffer; - wcscpy(pinfo->FileName, L"C:\\a\\path"); - pinfo->FileNameLength = wcslen(pinfo->FileName) * sizeof(WCHAR); - pinfo->NextEntryOffset = 0; - - // This condition is not taken into account - rt->dir = NULL; - rt->watch_status = 1; - - ov.hEvent = "C:\\a\\path"; - - // Begin calls to mock functions - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path"); - will_return(__wrap_OSHash_Get_ex, rt); - - expect_string(__wrap_fim_configuration_directory, path, "C:\\a\\path"); - will_return(__wrap_fim_configuration_directory, 0); - - expect_string(__wrap_fim_configuration_directory, path, ""); - will_return(__wrap_fim_configuration_directory, -1); - - // Inside realtime_win32read - will_return(wrap_ReadDirectoryChangesW, 1); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - RTCallBack(ERROR_SUCCESS, 1, &ov); -} - -void test_RTCallBack_acquired_changes(void **state) { - win32rtfim *rt = *state; - OVERLAPPED ov; - PFILE_NOTIFY_INFORMATION pinfo; - - - expect_function_call(__wrap_pthread_rwlock_rdlock); - expect_function_call(__wrap_pthread_mutex_lock); - - // Fill the win32rtfim struct with testing data - pinfo = (PFILE_NOTIFY_INFORMATION) rt->buffer; - wcscpy(pinfo->FileName, L"file.test"); - pinfo->FileNameLength = wcslen(pinfo->FileName) * sizeof(WCHAR); - pinfo->NextEntryOffset = 0; - - // This condition is not taken into account - rt->dir = strdup("C:\\a\\path"); - rt->watch_status = 1; - - ov.hEvent = "C:\\a\\path\\file.test"; - - // Begin calls to mock functions - - expect_value(__wrap_OSHash_Get_ex, self, syscheck.realtime->dirtb); - expect_string(__wrap_OSHash_Get_ex, key, "C:\\a\\path\\file.test"); - will_return(__wrap_OSHash_Get_ex, rt); - - expect_string(__wrap_fim_configuration_directory, path, "C:\\a\\path\\file.test"); - will_return(__wrap_fim_configuration_directory, 0); - - expect_string(__wrap_fim_configuration_directory, path, "c:\\a\\path\\file.test"); - will_return(__wrap_fim_configuration_directory, 0); - - expect_string(__wrap_fim_realtime_event, file, "c:\\a\\path\\file.test"); - - // Inside realtime_win32read - will_return(wrap_ReadDirectoryChangesW, 1); - - expect_function_call(__wrap_pthread_mutex_unlock); - expect_function_call(__wrap_pthread_rwlock_unlock); - - RTCallBack(ERROR_SUCCESS, 1, &ov); -} -#endif - -static void test_fim_realtime_get_queue_overflow(void **state) { - rtfim realtime = { .queue_overflow = false }; - int retval; - - syscheck.realtime = &realtime; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - retval = fim_realtime_get_queue_overflow(); - - assert_int_equal(retval, false); - - realtime.queue_overflow = true; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - retval = fim_realtime_get_queue_overflow(); - - assert_int_equal(retval, true); - - syscheck.realtime = NULL; -} - -static void test_fim_realtime_set_queue_overflow(void **state) { - rtfim realtime = { .queue_overflow = false }; - - syscheck.realtime = &realtime; - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - - fim_realtime_set_queue_overflow(true); - - assert_int_equal(realtime.queue_overflow, true); - - syscheck.realtime = NULL; -} - -static void test_fim_realtime_print_watches(void **state) { - rtfim realtime = { .queue_overflow = false }; - char msg[OS_SIZE_256]; - - syscheck.realtime = &realtime; - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_any(__wrap_OSHash_Get_Elem_ex, self); - will_return(__wrap_OSHash_Get_Elem_ex, 257); - - snprintf(msg, OS_SIZE_256, FIM_NUM_WATCHES, 257); - expect_string(__wrap__mdebug2, formatted_msg, msg); - - expect_function_call(__wrap_pthread_mutex_unlock); - - fim_realtime_print_watches(); - - syscheck.realtime = NULL; - -} - - -int main(void) { -#ifndef WIN_WHODATA - const struct CMUnitTest tests[] = { - /* realtime_start */ - cmocka_unit_test_setup_teardown(test_realtime_start_success, setup_realtime_start, teardown_realtime_start), - cmocka_unit_test_setup_teardown(test_realtime_start_failure_hash, setup_realtime_start, teardown_realtime_start), - -#if defined(TEST_SERVER) || defined(TEST_AGENT) - cmocka_unit_test_setup_teardown(test_realtime_start_failure_inotify, setup_realtime_start, teardown_realtime_start), - - /* realtime_adddir */ - cmocka_unit_test_setup_teardown(test_realtime_adddir_realtime_start_failure, setup_realtime_adddir_realtime_start_error, teardown_realtime_adddir_realtime_start_error), - cmocka_unit_test(test_realtime_adddir_realtime_failure), - cmocka_unit_test(test_realtime_adddir_realtime_watch_max_reached_failure), - cmocka_unit_test(test_realtime_adddir_realtime_watch_generic_failure), - cmocka_unit_test_setup_teardown(test_realtime_adddir_realtime_add, setup_OSHash, teardown_OSHash), - cmocka_unit_test_setup_teardown(test_realtime_adddir_realtime_add_hash_failure, setup_OSHash, teardown_OSHash), - cmocka_unit_test_setup_teardown(test_realtime_adddir_realtime_update, setup_OSHash, teardown_OSHash), - cmocka_unit_test_setup_teardown(test_realtime_adddir_realtime_update_failure, setup_OSHash, teardown_OSHash), - - /* realtime_process */ - cmocka_unit_test(test_realtime_process), - cmocka_unit_test_setup_teardown(test_realtime_process_len, setup_inotify_event, teardown_inotify_event), - cmocka_unit_test_setup_teardown(test_realtime_process_len_zero, setup_inotify_event, teardown_inotify_event), - cmocka_unit_test_setup_teardown(test_realtime_process_len_path_separator, setup_inotify_event, teardown_inotify_event), - cmocka_unit_test_setup_teardown(test_realtime_process_overflow, setup_inotify_event, teardown_inotify_event), - cmocka_unit_test_setup_teardown(test_realtime_process_delete, setup_inotify_event, teardown_inotify_event), - cmocka_unit_test_setup_teardown(test_realtime_process_move_self, setup_realtime_process, teardown_realtime_process), - cmocka_unit_test(test_realtime_process_failure), - - /* delete_subdirectories_watches */ - cmocka_unit_test_setup_teardown(test_delete_subdirectories_watches_realtime_fd_null, setup_hash_node, teardown_hash_node), - cmocka_unit_test_setup_teardown(test_delete_subdirectories_watches_hash_node_null, setup_hash_node, teardown_hash_node), - cmocka_unit_test_setup_teardown(test_delete_subdirectories_watches_not_same_name, setup_hash_node, teardown_hash_node), - cmocka_unit_test_setup_teardown(test_delete_subdirectories_watches_deletes, setup_hash_node, teardown_hash_node), - -#else - // realtime_win32read - cmocka_unit_test(test_realtime_win32read_success), - cmocka_unit_test(test_realtime_win32read_unable_to_read_directory), - - // free_win32rtfim_data - cmocka_unit_test(test_free_win32rtfim_data_null_input), - cmocka_unit_test(test_free_win32rtfim_data_full_data), - - // RTCallBack - cmocka_unit_test(test_RTCallBack_error_on_callback), - cmocka_unit_test(test_RTCallBack_empty_hash_table), - cmocka_unit_test_setup_teardown(test_RTCallBack_no_bytes_returned, setup_RTCallBack, teardown_RTCallBack), - cmocka_unit_test_setup_teardown(test_RTCallBack_acquired_changes_null_dir, setup_RTCallBack, teardown_RTCallBack), - cmocka_unit_test_setup_teardown(test_RTCallBack_acquired_changes, setup_RTCallBack, teardown_RTCallBack), -#endif - - /* realtime_sanitize_watch_map */ -#ifndef TEST_WINAGENT - cmocka_unit_test(test_realtime_sanitize_watch_map_empty_hash), - cmocka_unit_test(test_realtime_sanitize_watch_map_inotify_not_connected), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_entry_with_no_configuration, - setup_sanitize_watch_map, teardown_sanitize_watch_map), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_unable_to_add_more_watches, - setup_sanitize_watch_map, teardown_sanitize_watch_map), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_entry_deleted, setup_sanitize_watch_map, - teardown_sanitize_watch_map), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_inotify_error, setup_sanitize_watch_map, - teardown_sanitize_watch_map), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_entry_already_up_to_date, - setup_sanitize_watch_map, teardown_sanitize_watch_map), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_entry_with_new_watch_number, - setup_sanitize_watch_map, teardown_sanitize_watch_map), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_entry_with_new_watch_number_fail, - setup_sanitize_watch_map, teardown_sanitize_watch_map), - cmocka_unit_test_setup_teardown(test_realtime_sanitize_watch_map_update_existing_watch_with_new_directory, - setup_sanitize_watch_map, teardown_sanitize_watch_map), - cmocka_unit_test_setup(test_realtime_sanitize_watch_map_update_existing_watch_with_new_directory_fail, - setup_sanitize_watch_map), -#endif - }; -#else - const struct CMUnitTest tests[] = { - // realtime_adddir - cmocka_unit_test(test_realtime_adddir_whodata_non_existent_file), - cmocka_unit_test(test_realtime_adddir_whodata_error_adding_whodata_dir), - cmocka_unit_test(test_realtime_adddir_whodata_file_success), - cmocka_unit_test(test_realtime_adddir_whodata_dir_success), - cmocka_unit_test(test_realtime_adddir_max_limit_reached), - cmocka_unit_test(test_realtime_adddir_duplicate_entry), - cmocka_unit_test(test_realtime_adddir_handle_error), - cmocka_unit_test(test_realtime_adddir_duplicate_entry_non_existent_directory_valid_handle), - cmocka_unit_test(test_realtime_adddir_duplicate_entry_non_existent_directory_closed_handle), - cmocka_unit_test(test_realtime_adddir_duplicate_entry_non_existent_directory_invalid_handle), - cmocka_unit_test_setup_teardown(test_realtime_adddir_success, setup_OSHash, teardown_OSHash), - }; -#endif - - const struct CMUnitTest realtime_helper_tests[] = { - cmocka_unit_test(test_fim_realtime_get_queue_overflow), - cmocka_unit_test(test_fim_realtime_set_queue_overflow), - cmocka_unit_test(test_fim_realtime_print_watches), - }; - - int results = 0; - - results += cmocka_run_group_tests(tests, setup_group, teardown_group); - results += cmocka_run_group_tests(realtime_helper_tests, NULL, NULL); - - return results; -} diff --git a/src/unit_tests/syscheckd/test_syscheck.c b/src/unit_tests/syscheckd/test_syscheck.c deleted file mode 100644 index 89ec0565379..00000000000 --- a/src/unit_tests/syscheckd/test_syscheck.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/fs_op_wrappers.h" -#include "../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../wrappers/wazuh/syscheckd/create_db_wrappers.h" -#include "../wrappers/wazuh/syscheckd/fim_db_wrappers.h" - -#include "syscheck.h" - -/* setup/teardowns */ -static int setup_group(void **state) { - - if (initialize_syscheck_configuration(&syscheck) == OS_INVALID) { - return OS_INVALID; - } - - fdb_t *fdb = calloc(1, sizeof(fdb_t)); - if (fdb == NULL) - return -1; - - *state = fdb; - - return 0; -} - -static int teardown_group(void **state) { - fdb_t *fdb = *state; - - free(fdb); - - return 0; -} - -static int setup_syscheck_config(void **state) { - syscheck_config *syscheck_conf = calloc(1, sizeof(syscheck_config)); - - syscheck_conf->database_store = FIM_DB_DISK; - syscheck_conf->sync_interval = 300; - syscheck_conf->sync_response_timeout = 30; - syscheck_conf->sync_max_interval = 3600; - syscheck_conf->sync_thread_pool = 1; - syscheck_conf->sync_queue_size = 16384; - syscheck_conf->file_entry_limit = 100000; -#ifdef WIN32 - syscheck_conf->db_entry_registry_limit = 100000; -#endif - *state = syscheck_conf; - return 0; -} - -static int teardown_syscheck_config(void **state) { - syscheck_config *syscheck_conf = *state; - - free(syscheck_conf); - - return 0; -} - -#ifdef TEST_WINAGENT -static int setup_group_win(void **state) { - syscheck.directories = OSList_Create(); - if (syscheck.directories == NULL) { - return -1; - } - - return 0; -} - -static int teardown_group_win(void **state) { - OSListNode *node_it; - if (syscheck.directories) { - OSList_foreach(node_it, syscheck.directories) { - free_directory(node_it->data); - node_it->data = NULL; - } - OSList_Destroy(syscheck.directories); - syscheck.directories = NULL; - } - - return 0; -} -#endif - -/* tests */ - -void test_fim_initialize(void **state) -{ - syscheck_config *syscheck_conf = *state; - -#ifdef TEST_WINAGENT - expect_wrapper_fim_db_init(syscheck_conf->database_store, - syscheck_conf->sync_interval, - syscheck_conf->sync_max_interval, - syscheck_conf->sync_response_timeout, - syscheck_conf->file_entry_limit, - syscheck_conf->db_entry_registry_limit, - 1, - syscheck_conf->sync_thread_pool, - syscheck_conf->sync_queue_size); -#else - expect_wrapper_fim_db_init(syscheck_conf->database_store, - syscheck_conf->sync_interval, - syscheck_conf->sync_max_interval, - syscheck_conf->sync_response_timeout, - syscheck_conf->file_entry_limit, - 0, - 0, - syscheck_conf->sync_thread_pool, - syscheck_conf->sync_queue_size); -#endif - fim_initialize(); -} - -void test_read_internal(void **state) -{ - (void) state; - - will_return_always(__wrap_getDefine_Int, 1); - - read_internal(0); -} - -void test_read_internal_debug(void **state) -{ - (void) state; - - will_return_always(__wrap_getDefine_Int, 1); - - read_internal(1); -} -#ifdef TEST_WINAGENT -int Start_win32_Syscheck(); - -int __wrap_Read_Syscheck_Config(const char * file) -{ - check_expected_ptr(file); - return mock(); -} - -int __wrap_rootcheck_init(int value, char * home_path) -{ - return mock(); -} - -void __wrap_start_daemon() -{ - function_called(); -} - -void __wrap_read_internal(int debug_level) -{ - function_called(); -} - -void test_Start_win32_Syscheck_no_config_file(void **state) { - directory_t EMPTY = { 0 }; - registry_t REGISTRY_EMPTY[] = { { NULL, 0, 0, 0, 0, NULL, NULL } }; - - syscheck.registry = REGISTRY_EMPTY; - syscheck.disabled = 1; - - - /* Conf file not found */ - will_return_always(__wrap_getDefine_Int, 1); - expect_string(__wrap_File_DateofChange, file, "ossec.conf"); - will_return(__wrap_File_DateofChange, -1); - expect_string(__wrap__merror_exit, formatted_msg, "(1239): Configuration file not found: 'ossec.conf'."); - - expect_assert_failure(Start_win32_Syscheck()); -} - -void test_Start_win32_Syscheck_corrupted_config_file(void **state) { - directory_t EMPTY = { 0 }; - registry_t REGISTRY_EMPTY[] = { { NULL, 0, 0, 0, 0, NULL, NULL } }; - - syscheck.registry = REGISTRY_EMPTY; - syscheck.disabled = 1; - - will_return_always(__wrap_getDefine_Int, 1); - expect_string(__wrap_File_DateofChange, file, "ossec.conf"); - will_return(__wrap_File_DateofChange, 0); - - expect_string(__wrap_Read_Syscheck_Config, file, "ossec.conf"); - will_return(__wrap_Read_Syscheck_Config, -1); - expect_string(__wrap__mwarn, formatted_msg, "(1207): syscheck remote configuration in 'ossec.conf' is corrupted."); - - will_return(__wrap_rootcheck_init, 1); - - expect_wrapper_fim_db_init(0, 300, 3600, 30, 100000, 100000, 1, 1, 16384); - expect_function_call(__wrap_start_daemon); - assert_int_equal(Start_win32_Syscheck(), 0); -} - -void test_Start_win32_Syscheck_syscheck_disabled_1(void **state) { - syscheck.directories = NULL; - syscheck.registry = NULL; - syscheck.disabled = 0; - char info_msg[OS_MAXSTR]; - - will_return_always(__wrap_getDefine_Int, 1); - - expect_string(__wrap_File_DateofChange, file, "ossec.conf"); - will_return(__wrap_File_DateofChange, 0); - - expect_string(__wrap_Read_Syscheck_Config, file, "ossec.conf"); - will_return(__wrap_Read_Syscheck_Config, 1); - - expect_string(__wrap__minfo, formatted_msg, "(6678): No directory provided for syscheck to monitor."); - - expect_string(__wrap__minfo, formatted_msg, "(6001): File integrity monitoring disabled."); - - will_return(__wrap_rootcheck_init, 0); - - expect_wrapper_fim_db_init(0, 300, 3600, 30, 100000, 100000, 1, 1, 16384); - expect_string(__wrap__minfo, formatted_msg, FIM_FILE_SIZE_LIMIT_DISABLED); - - expect_string(__wrap__minfo, formatted_msg, FIM_DISK_QUOTA_LIMIT_DISABLED); - - snprintf(info_msg, OS_MAXSTR, "Started (pid: %d).", getpid()); - expect_string(__wrap__minfo, formatted_msg, info_msg); - expect_function_call(__wrap_start_daemon); - assert_int_equal(Start_win32_Syscheck(), 0); -} - -void test_Start_win32_Syscheck_syscheck_disabled_2(void **state) { - directory_t EMPTY = { 0 }; - char info_msg[OS_MAXSTR]; - - will_return_always(__wrap_getDefine_Int, 1); - - expect_string(__wrap_File_DateofChange, file, "ossec.conf"); - will_return(__wrap_File_DateofChange, 0); - - expect_string(__wrap_Read_Syscheck_Config, file, "ossec.conf"); - will_return(__wrap_Read_Syscheck_Config, 1); - - expect_string(__wrap__minfo, formatted_msg, "(6678): No directory provided for syscheck to monitor."); - - expect_string(__wrap__minfo, formatted_msg, "(6001): File integrity monitoring disabled."); - - will_return(__wrap_rootcheck_init, 0); - - expect_wrapper_fim_db_init(0, 300, 3600, 30, 100000, 100000, 1, 1, 16384); - expect_string(__wrap__minfo, formatted_msg, FIM_FILE_SIZE_LIMIT_DISABLED); - - expect_string(__wrap__minfo, formatted_msg, FIM_DISK_QUOTA_LIMIT_DISABLED); - - snprintf(info_msg, OS_MAXSTR, "Started (pid: %d).", getpid()); - expect_string(__wrap__minfo, formatted_msg, info_msg); - expect_function_call(__wrap_start_daemon); - assert_int_equal(Start_win32_Syscheck(), 0); -} - -void test_Start_win32_Syscheck_dirs_and_registry(void **state) { - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - directory_t *directory0 = fim_create_directory("c:\\dir1", 0, NULL, 512, NULL, 1024, 0); - OSList_InsertData(syscheck.directories, NULL, directory0); - - syscheck.disabled = 0; - - registry_t syscheck_registry[] = { { "Entry1", 1, 0, 0, 0, NULL, NULL, "Tag1" }, - { NULL, 0, 0, 0, 0, NULL, NULL, NULL } }; - syscheck.registry = syscheck_registry; - - char *syscheck_ignore[] = {"dir1", NULL}; - syscheck.ignore = syscheck_ignore; - syscheck.file_size_enabled = 0; - syscheck.disk_quota_enabled = 0; - OSMatch regex; - regex.raw = "^regex$"; - OSMatch *syscheck_ignore_regex[] = {®ex, NULL}; - syscheck.ignore_regex = syscheck_ignore_regex; - - registry_ignore syscheck_registry_ignore[] = { { "Entry1", 1 }, { NULL, 0 } }; - syscheck.key_ignore = syscheck_registry_ignore; - - char *syscheck_nodiff[] = {"Diff", NULL}; - syscheck.nodiff = syscheck_nodiff; - - char info_msg[OS_MAXSTR]; - - will_return_always(__wrap_getDefine_Int, 1); - - expect_string(__wrap_File_DateofChange, file, "ossec.conf"); - will_return(__wrap_File_DateofChange, 0); - - expect_string(__wrap_Read_Syscheck_Config, file, "ossec.conf"); - will_return(__wrap_Read_Syscheck_Config, 0); - - will_return(__wrap_rootcheck_init, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6002): Monitoring registry entry: 'Entry1 [x64]', with options ''"); - expect_string(__wrap__minfo, formatted_msg, "(6003): Monitoring path: 'c:\\dir1', with options ''."); - - expect_string(__wrap__minfo, formatted_msg, FIM_FILE_SIZE_LIMIT_DISABLED); - - expect_string(__wrap__minfo, formatted_msg, FIM_DISK_QUOTA_LIMIT_DISABLED); - - expect_string(__wrap__minfo, formatted_msg, "(6206): Ignore 'file' entry 'dir1'"); - - expect_string(__wrap__minfo, formatted_msg, "(6207): Ignore 'file' sregex '^regex$'"); - - expect_string(__wrap__minfo, formatted_msg, "(6206): Ignore 'registry' entry 'Entry1'"); - - expect_string(__wrap__minfo, formatted_msg, "(6004): No diff for file: 'Diff'"); - - expect_wrapper_fim_db_init(0, 300, 3600, 30, 100000, 100000, 1, 1, 16384); - snprintf(info_msg, OS_MAXSTR, "Started (pid: %d).", getpid()); - expect_string(__wrap__minfo, formatted_msg, info_msg); - - expect_function_call(__wrap_start_daemon); - assert_int_equal(Start_win32_Syscheck(), 0); - - free_directory(directory0); - OSList_DeleteThisNode(syscheck.directories, syscheck.directories->first_node); -} - -void test_Start_win32_Syscheck_whodata_active(void **state) { - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - directory_t *directory0 = fim_create_directory("c:\\dir1", WHODATA_ACTIVE, NULL, 512, NULL, -1, 0); - - registry_t syscheck_registry[] = { { NULL, 0, 0, 0, 0, NULL, NULL } }; - - syscheck.disabled = 0; - - OSList_InsertData(syscheck.directories, NULL, directory0); - - syscheck.registry = syscheck_registry; - - syscheck.ignore = NULL; - syscheck.ignore_regex = NULL; - syscheck.key_ignore = NULL; - syscheck.nodiff = NULL; - - char info_msg[OS_MAXSTR]; - - will_return_always(__wrap_getDefine_Int, 1); - - expect_string(__wrap_File_DateofChange, file, "ossec.conf"); - will_return(__wrap_File_DateofChange, 0); - - expect_string(__wrap_Read_Syscheck_Config, file, "ossec.conf"); - will_return(__wrap_Read_Syscheck_Config, 0); - - will_return(__wrap_rootcheck_init, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6003): Monitoring path: 'c:\\dir1', with options 'whodata'."); - - expect_wrapper_fim_db_init(0, 300, 3600, 30, 100000, 100000, 1, 1, 16384); - expect_string(__wrap__minfo, formatted_msg, FIM_FILE_SIZE_LIMIT_DISABLED); - - expect_string(__wrap__minfo, formatted_msg, FIM_DISK_QUOTA_LIMIT_DISABLED); - - snprintf(info_msg, OS_MAXSTR, "Started (pid: %d).", getpid()); - expect_string(__wrap__minfo, formatted_msg, info_msg); - expect_function_call(__wrap_start_daemon); - assert_int_equal(Start_win32_Syscheck(), 0); - - free_directory(directory0); - OSList_DeleteThisNode(syscheck.directories, syscheck.directories->first_node); -} - -#endif - -int main(void) { - int ret; - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_fim_initialize, setup_syscheck_config, teardown_syscheck_config), - cmocka_unit_test(test_read_internal), - cmocka_unit_test(test_read_internal_debug), - }; - /* Windows specific tests */ -#ifdef TEST_WINAGENT - const struct CMUnitTest tests_win[] = { - cmocka_unit_test(test_Start_win32_Syscheck_no_config_file), - cmocka_unit_test_setup_teardown(test_Start_win32_Syscheck_corrupted_config_file, setup_syscheck_config, teardown_syscheck_config), - cmocka_unit_test(test_Start_win32_Syscheck_dirs_and_registry), - cmocka_unit_test(test_Start_win32_Syscheck_whodata_active), - cmocka_unit_test(test_Start_win32_Syscheck_syscheck_disabled_1), - cmocka_unit_test(test_Start_win32_Syscheck_syscheck_disabled_2), - }; -#endif - - ret = cmocka_run_group_tests(tests, setup_group, teardown_group); -#ifdef TEST_WINAGENT - ret += cmocka_run_group_tests(tests_win, setup_group_win, teardown_group_win); -#endif - - return ret; -} diff --git a/src/unit_tests/syscheckd/test_syscom.c b/src/unit_tests/syscheckd/test_syscom.c deleted file mode 100644 index 06fa8d94a34..00000000000 --- a/src/unit_tests/syscheckd/test_syscom.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/syscheckd/config_wrappers.h" -#include "../wrappers/wazuh/syscheckd/fim_sync_wrappers.h" -#include "../../syscheckd/include/syscheck.h" -#include "../../config/syscheck-config.h" - - -/* redefinitons/wrapping */ - -static int delete_string(void **state) -{ - char *data = *state; - free(data); - return 0; -} - - -/* tests */ - - -void test_syscom_dispatch_getconfig_agent(void **state) -{ - (void) state; - size_t ret; - - char command[] = "syscheck getconfig args"; - char * output; - - expect_string(__wrap__mdebug1, formatted_msg, "(6283): At SYSCOM getconfig: Could not get 'args' section."); - - ret = syscom_dispatch(command, &output); - *state = output; - - assert_string_equal(output, "err Could not get requested section"); - assert_int_equal(ret, 35); -} - -void test_syscom_dispatch_getconfig_manager(void **state) -{ - (void) state; - size_t ret; - - char command[] = "getconfig args"; - char * output; - - expect_string(__wrap__mdebug1, formatted_msg, "(6283): At SYSCOM getconfig: Could not get 'args' section."); - - ret = syscom_dispatch(command, &output); - *state = output; - - assert_string_equal(output, "err Could not get requested section"); - assert_int_equal(ret, 35); -} - - -void test_syscom_dispatch_getconfig_noargs(void **state) -{ - (void) state; - size_t ret; - - char command[] = "syscheck getconfig"; - char * output; - - expect_string(__wrap__mdebug1, formatted_msg, "(6281): SYSCOM getconfig needs arguments."); - - ret = syscom_dispatch(command, &output); - *state = output; - - assert_string_equal(output, "err SYSCOM getconfig needs arguments"); - assert_int_equal(ret, 36); -} - - -void test_syscom_dispatch_dbsync(void **state) -{ - (void) state; - size_t ret; - - char command[] = "fim_file dbsync args"; - char *output; - - expect_string(__wrap_fim_sync_push_msg, msg, "fim_file dbsync args"); - - ret = syscom_dispatch(command, &output); - - assert_int_equal(ret, 0); -} - - -void test_syscom_dispatch_dbsync_noargs(void **state) -{ - (void) state; - size_t ret; - - char command[] = "fim_file dbsync"; - char *output; - - expect_string(__wrap_fim_sync_push_msg, msg, "fim_file dbsync"); - - ret = syscom_dispatch(command, &output); - - assert_int_equal(ret, 0); -} - - -void test_syscom_dispatch_restart_agent(void **state) -{ - (void) state; - size_t ret; - - char command[] = "syscheck restart"; - char *output; - - ret = syscom_dispatch(command, &output); - - assert_int_equal(ret, 0); -} - -void test_syscom_dispatch_restart_manager(void **state) -{ - (void) state; - size_t ret; - - char command[] = "restart"; - char *output; - - ret = syscom_dispatch(command, &output); - - assert_int_equal(ret, 0); -} - - -void test_syscom_dispatch_getconfig_unrecognized(void **state) -{ - (void) state; - size_t ret; - - char command[] = "invalid"; - char * output; - - expect_string(__wrap__mdebug1, formatted_msg, "(6282): SYSCOM Unrecognized command 'invalid'"); - - ret = syscom_dispatch(command, &output); - *state = output; - - assert_string_equal(output, "err Unrecognized command"); - assert_int_equal(ret, 24); -} - -void test_syscom_dispatch_null_command(void **state) -{ - char * output; - - expect_assert_failure(syscom_dispatch(NULL, &output)); -} - -void test_syscom_dispatch_null_output(void **state) -{ - char command[] = "invalid"; - - expect_assert_failure(syscom_dispatch(command, NULL)); -} - -void test_syscom_getconfig_syscheck(void **state) -{ - (void) state; - size_t ret; - - char * section = "syscheck"; - char * output; - - cJSON * root = cJSON_CreateObject(); - cJSON_AddStringToObject(root, "test", "syscheck"); - - will_return(__wrap_getSyscheckConfig, root); - ret = syscom_getconfig(section, &output); - *state = output; - - assert_string_equal(output, "ok {\"test\":\"syscheck\"}"); - assert_int_equal(ret, 22); -} - - -void test_syscom_getconfig_syscheck_failure(void **state) -{ - (void) state; - size_t ret; - - char * section = "syscheck"; - char * output; - - will_return(__wrap_getSyscheckConfig, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(6283): At SYSCOM getconfig: Could not get 'syscheck' section."); - - ret = syscom_getconfig(section, &output); - *state = output; - - assert_string_equal(output, "err Could not get requested section"); - assert_int_equal(ret, 35); -} - - -void test_syscom_getconfig_rootcheck(void **state) -{ - (void) state; - size_t ret; - - char * section = "rootcheck"; - char * output; - - cJSON * root = cJSON_CreateObject(); - cJSON_AddStringToObject(root, "test", "rootcheck"); - - will_return(__wrap_getRootcheckConfig, root); - ret = syscom_getconfig(section, &output); - *state = output; - - assert_string_equal(output, "ok {\"test\":\"rootcheck\"}"); - assert_int_equal(ret, 23); -} - - -void test_syscom_getconfig_rootcheck_failure(void **state) -{ - (void) state; - size_t ret; - - char * section = "rootcheck"; - char * output; - - will_return(__wrap_getRootcheckConfig, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(6283): At SYSCOM getconfig: Could not get 'rootcheck' section."); - - ret = syscom_getconfig(section, &output); - *state = output; - - assert_string_equal(output, "err Could not get requested section"); - assert_int_equal(ret, 35); -} - - -void test_syscom_getconfig_internal(void **state) -{ - (void) state; - size_t ret; - - char * section = "internal"; - char * output; - - cJSON * root = cJSON_CreateObject(); - cJSON_AddStringToObject(root, "test", "internal"); - - will_return(__wrap_getSyscheckInternalOptions, root); - ret = syscom_getconfig(section, &output); - *state = output; - - assert_string_equal(output, "ok {\"test\":\"internal\"}"); - assert_int_equal(ret, 22); -} - - -void test_syscom_getconfig_internal_failure(void **state) -{ - (void) state; - size_t ret; - - char * section = "internal"; - char * output; - - will_return(__wrap_getSyscheckInternalOptions, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "(6283): At SYSCOM getconfig: Could not get 'internal' section."); - - ret = syscom_getconfig(section, &output); - *state = output; - - assert_string_equal(output, "err Could not get requested section"); - assert_int_equal(ret, 35); -} - -void test_syscom_getconfig_null_section(void **state) -{ - char * output; - - expect_assert_failure(syscom_getconfig(NULL, &output)); -} - -void test_syscom_getconfig_null_output(void **state) -{ - char * section = "internal"; - - expect_assert_failure(syscom_getconfig(section, NULL)); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_teardown(test_syscom_dispatch_getconfig_agent, delete_string), - cmocka_unit_test_teardown(test_syscom_dispatch_getconfig_manager, delete_string), - cmocka_unit_test_teardown(test_syscom_dispatch_getconfig_noargs, delete_string), - cmocka_unit_test(test_syscom_dispatch_dbsync), - cmocka_unit_test(test_syscom_dispatch_dbsync_noargs), - cmocka_unit_test(test_syscom_dispatch_restart_agent), - cmocka_unit_test(test_syscom_dispatch_restart_manager), - cmocka_unit_test_teardown(test_syscom_dispatch_getconfig_unrecognized, delete_string), - cmocka_unit_test_teardown(test_syscom_dispatch_null_command, delete_string), - cmocka_unit_test(test_syscom_dispatch_null_output), - cmocka_unit_test_teardown(test_syscom_getconfig_syscheck, delete_string), - cmocka_unit_test_teardown(test_syscom_getconfig_syscheck_failure, delete_string), - cmocka_unit_test_teardown(test_syscom_getconfig_rootcheck, delete_string), - cmocka_unit_test_teardown(test_syscom_getconfig_rootcheck_failure, delete_string), - cmocka_unit_test_teardown(test_syscom_getconfig_internal, delete_string), - cmocka_unit_test_teardown(test_syscom_getconfig_internal_failure, delete_string), - cmocka_unit_test(test_syscom_getconfig_null_section), - cmocka_unit_test(test_syscom_getconfig_null_output), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/syscheckd/utils.c b/src/unit_tests/syscheckd/utils.c deleted file mode 100644 index 9358d837318..00000000000 --- a/src/unit_tests/syscheckd/utils.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include "test_fim.h" - -int setup_os_list(void **state) { - OSList *list = OSList_Create(); - - if (list == NULL) { - return -1; - } - - *state = list; - - return 0; -} - -int teardown_os_list(void **state) { - OSList *list = *state; - - OSList_Destroy(list); - - return 0; -} - -int setup_rb_tree(void **state) { - rb_tree *tree = rbtree_init(); - - if (tree == NULL) { - return -1; - } - - *state = tree; - - return 0; -} - -int teardown_rb_tree(void **state) { - rb_tree *tree = *state; - - rbtree_destroy(tree); - - return 0; -} - -#define BASE_WIN_ALLOWED_ACE "[" \ - "\"delete\"," \ - "\"read_control\"," \ - "\"write_dac\"," \ - "\"write_owner\"," \ - "\"synchronize\"," \ - "\"read_data\"," \ - "\"write_data\"," \ - "\"append_data\"," \ - "\"read_ea\"," \ - "\"write_ea\"," \ - "\"execute\"," \ - "\"read_attributes\"," \ - "\"write_attributes\"" \ -"]" - -#define BASE_WIN_DENIED_ACE "[" \ - "\"read_control\"," \ - "\"synchronize\"," \ - "\"read_data\"," \ - "\"read_ea\"," \ - "\"execute\"," \ - "\"read_attributes\"" \ -"]" - -#define BASE_WIN_ACE "{" \ - "\"name\": \"Users\"," \ - "\"allowed\": " BASE_WIN_ALLOWED_ACE "," \ - "\"denied\": " BASE_WIN_DENIED_ACE \ -"}" - -cJSON *create_win_permissions_object() { - static const char * const BASE_WIN_PERMS = "{\"S-1-5-32-636\": " BASE_WIN_ACE "}"; - return cJSON_Parse(BASE_WIN_PERMS); -} diff --git a/src/unit_tests/syscheckd/whodata/CMakeLists.txt b/src/unit_tests/syscheckd/whodata/CMakeLists.txt deleted file mode 100644 index 20cfcfd957b..00000000000 --- a/src/unit_tests/syscheckd/whodata/CMakeLists.txt +++ /dev/null @@ -1,140 +0,0 @@ -include_directories(${SRC_FOLDER}/syscheckd/include) -include_directories(${SRC_FOLDER}/syscheckd/src) -include_directories(${SRC_FOLDER}/unit_tests) -include_directories(${SRC_FOLDER}/config) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -if(NOT ${TARGET} STREQUAL "winagent") - # test_audit_healthcheck tests - add_executable(test_audit_healthcheck test_audit_healthcheck.c) - target_compile_options(test_audit_healthcheck PRIVATE "-Wall") - - set(AUDIT_HC_FLAGS "-Wl,--wrap=_mdebug1,--wrap=_mdebug2 -Wl,--wrap,audit_add_rule \ - -Wl,--wrap,pthread_cond_wait -Wl,--wrap,pthread_mutex_lock \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,CreateThread -Wl,--wrap,wfopen \ - -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fgetpos \ - -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fgetc \ - -Wl,--wrap,getpid -Wl,--wrap,sleep -Wl,--wrap,unlink -Wl,--wrap,audit_delete_rule \ - -Wl,--wrap,select -Wl,--wrap,audit_parse -Wl,--wrap=abspath -Wl,--wrap,atomic_int_get \ - -Wl,--wrap,atomic_int_set -Wl,--wrap,atomic_int_dec -Wl,--wrap,atomic_int_inc \ - -Wl,--wrap,pthread_cond_timedwait -Wl,--wrap,gettime -Wl,--wrap,fim_db_init \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows -Wl,--wrap,popen") - - target_link_libraries(test_audit_healthcheck SYSCHECK_O ${TEST_DEPS}) - - target_link_libraries(test_audit_healthcheck "${AUDIT_HC_FLAGS}") - add_test(NAME test_audit_healthcheck COMMAND test_audit_healthcheck) - - # test_syscheck_rule_handling tests - add_executable(test_audit_rule_handling test_audit_rule_handling.c) - target_compile_options(test_audit_rule_handling PRIVATE "-Wall") - - set(SYSCHECK_AUDIT_FLAGS "-Wl,--wrap=_mdebug1,--wrap=_mdebug2,--wrap=_merror,--wrap=_mwarn,--wrap=audit_add_rule\ - -Wl,--wrap=pthread_mutex_lock,--wrap=pthread_mutex_unlock,--wrap=fim_db_init \ - -Wl,--wrap=pthread_rwlock_rdlock,--wrap=pthread_rwlock_wrlock,--wrap=pthread_rwlock_unlock \ - -Wl,--wrap=fopen,--wrap=fclose,--wrap=fflush,--wrap=fgets,--wrap=fgetpos,--wrap=wfopen \ - -Wl,--wrap=fread,--wrap=fseek,--wrap=fwrite,--wrap=remove,--wrap=fgetc \ - -Wl,--wrap=getpid,--wrap=sleep,--wrap=unlink,--wrap=audit_delete_rule \ - -Wl,--wrap=select,--wrap=audit_parse,--wrap=audit_get_rule_list,--wrap=audit_close \ - -Wl,--wrap=search_audit_rule,--wrap=audit_open -Wl,--wrap,atomic_int_get \ - -Wl,--wrap,atomic_int_set -Wl,--wrap,atomic_int_dec -Wl,--wrap,atomic_int_inc \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows -Wl,--wrap,popen") - - target_link_libraries(test_audit_rule_handling SYSCHECK_O ${TEST_DEPS}) - - target_link_libraries(test_audit_rule_handling "${SYSCHECK_AUDIT_FLAGS}") - add_test(NAME test_audit_rule_handling COMMAND test_audit_rule_handling) - - # test_syscheck_audit tests - add_executable(test_syscheck_audit test_syscheck_audit.c) - target_compile_options(test_syscheck_audit PRIVATE "-Wall") - - set(SYSCHECK_AUDIT_FLAGS "-Wl,--wrap,pthread_cond_wait -Wl,--wrap,pthread_mutex_lock \ - -Wl,--wrap,openproc -Wl,--wrap,readproc -Wl,--wrap,freeproc -Wl,--wrap,popen \ - -Wl,--wrap,OS_ConnectUnixDomain -Wl,--wrap,audit_add_rule -Wl,--wrap,audit_restart \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,closeproc -Wl,--wrap,recv -Wl,--wrap,IsDir \ - -Wl,--wrap,IsLink -Wl,--wrap,IsFile -Wl,--wrap,IsSocket -Wl,--wrap,fprintf -Wl,--wrap,wfopen \ - -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fgetpos \ - -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,fgetc \ - -Wl,--wrap,getpid -Wl,--wrap,sleep -Wl,--wrap,unlink -Wl,--wrap,audit_delete_rule \ - -Wl,--wrap,select -Wl,--wrap,audit_parse -Wl,--wrap,symlink -Wl,--wrap,SendMSG \ - -Wl,--wrap,audit_get_rule_list -Wl,--wrap,fim_audit_reload_rules \ - -Wl,--wrap,search_audit_rule -Wl,--wrap,abspath -Wl,--wrap,atomic_int_get \ - -Wl,--wrap,atomic_int_set -Wl,--wrap,atomic_int_dec -Wl,--wrap,atomic_int_inc \ - -Wl,--wrap,pthread_rwlock_wrlock -Wl,--wrap,pthread_rwlock_unlock \ - -Wl,--wrap,pthread_rwlock_rdlock -Wl,--wrap,OS_SHA1_Str -Wl,--wrap,fim_db_init \ - -Wl,--wrap,OS_SHA1_File -Wl,--wrap,audit_open -Wl,--wrap,audit_close \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - ${DEBUG_OP_WRAPPERS}") - - target_link_libraries(test_syscheck_audit SYSCHECK_O ${TEST_DEPS}) - - target_link_libraries(test_syscheck_audit "${SYSCHECK_AUDIT_FLAGS}") - add_test(NAME test_syscheck_audit COMMAND test_syscheck_audit) - - # test_audit_parse tests - add_executable(test_audit_parse test_audit_parse.c) - target_compile_options(test_audit_parse PRIVATE "-Wall") - - set(AUDIT_PARSE_FLAGS "-Wl,--wrap=_mdebug1,--wrap=_mdebug2 -Wl,--wrap=_mwarn -Wl,--wrap=_minfo \ - -Wl,--wrap,audit_add_rule -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,popen \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush \ - -Wl,--wrap,fgets -Wl,--wrap,fgetpos -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite\ - -Wl,--wrap,remove -Wl,--wrap,fgetc -Wl,--wrap,getpid -Wl,--wrap,sleep -Wl,--wrap,unlink \ - -Wl,--wrap,audit_delete_rule -Wl,--wrap,realpath -Wl,--wrap,atexit -Wl,--wrap,audit_open\ - -Wl,--wrap,get_user -Wl,--wrap,get_group -Wl,--wrap,readlink -Wl,--wrap,audit_get_rule_list \ - -Wl,--wrap,SendMSG -Wl,--wrap,fim_whodata_event -Wl,--wrap,search_audit_rule \ - -Wl,--wrap,audit_close -Wl,--wrap,fim_manipulated_audit_rules -Wl,--wrap,wfopen \ - -Wl,--wrap,fim_audit_reload_rules -Wl,--wrap,remove_audit_rule_syscheck \ - -Wl,--wrap,atomic_int_get -Wl,--wrap,atomic_int_set -Wl,--wrap,atomic_int_dec \ - -Wl,--wrap,atomic_int_inc -Wl,--wrap,pthread_rwlock_wrlock -Wl,--wrap,pthread_rwlock_unlock \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_db_init \ - -Wl,--wrap,pthread_rwlock_rdlock -Wl,--wrap=fim_run_integrity -Wl,--wrap=fim_db_transaction_start \ - -Wl,--wrap=fim_db_transaction_sync_row -Wl,--wrap=fim_db_transaction_deleted_rows \ - ${DEBUG_OP_WRAPPERS}") - - target_link_libraries(test_audit_parse SYSCHECK_O ${TEST_DEPS}) - - target_link_libraries(test_audit_parse "${AUDIT_PARSE_FLAGS}") - add_test(NAME test_audit_parse COMMAND test_audit_parse) -else() - link_directories(${SRC_FOLDER}/syscheckd/build/bin) - add_executable(test_win_whodata test_win_whodata.c) - target_compile_options(test_win_whodata PRIVATE "-Wall") - set(WIN_WHODATA_FLAGS "-Wl,--wrap,wstr_replace -Wl,--wrap,SendMSG -Wl,--wrap,popen \ - -Wl,--wrap,free_whodata_event -Wl,--wrap,IsFile -Wl,--wrap=remove \ - -Wl,--wrap=fim_db_get_count_registry_data -Wl,--wrap=fim_db_get_count_registry_key -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap,wm_exec -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,atexit -Wl,--wrap,wfopen \ - -Wl,--wrap,check_path_type -Wl,--wrap,pthread_rwlock_unlock -Wl,--wrap,fim_whodata_event \ - -Wl,--wrap,fim_checker -Wl,--wrap,os_random -Wl,--wrap,wpopenv -Wl,--wrap,atomic_int_get\ - -Wl,--wrap,convert_windows_string -Wl,--wrap,FOREVER -Wl,--wrap,wpclose \ - -Wl,--wrap,fflush -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,fprintf \ - -Wl,--wrap,fgets -Wl,--wrap,wstr_split -Wl,--wrap,pthread_rwlock_wrlock \ - -Wl,--wrap,fgetpos -Wl,--wrap,fgetc -Wl,--wrap,getDefine_Int -Wl,--wrap,pthread_rwlock_rdlock \ - -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap=fim_db_file_pattern_search,--wrap=fim_db_remove_path -Wl,--wrap,fim_db_get_path \ - -Wl,--wrap=fim_db_file_update,--wrap=fim_db_file_inode_search -Wl,--wrap,fim_db_get_count_file_inode \ - -Wl,--wrap=fim_db_get_count_file_entry -Wl,--wrap=fim_db_init -Wl,--wrap=fim_run_integrity \ - -Wl,--wrap=fim_db_transaction_start -Wl,--wrap=fim_db_transaction_sync_row \ - -Wl,--wrap=fim_db_transaction_deleted_rows,--wrap=fim_sync_push_msg \ - -Wl,--wrap=is_fim_shutdown -Wl,--wrap=_imp__dbsync_initialize \ - -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown ${HASH_OP_WRAPPERS} \ - ${DEBUG_OP_WRAPPERS}") - target_link_libraries(test_win_whodata SYSCHECK_EVENT_O ${TEST_EVENT_DEPS} fimdb) - - target_link_libraries(test_win_whodata "${WIN_WHODATA_FLAGS}") - add_test(NAME test_win_whodata COMMAND test_win_whodata) -endif() diff --git a/src/unit_tests/syscheckd/whodata/test_audit_healthcheck.c b/src/unit_tests/syscheckd/whodata/test_audit_healthcheck.c deleted file mode 100644 index 763a1b05d5a..00000000000 --- a/src/unit_tests/syscheckd/whodata/test_audit_healthcheck.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../../syscheckd/include/syscheck.h" - -#include "wrappers/externals/audit/libaudit_wrappers.h" -#include "wrappers/externals/procpc/readproc_wrappers.h" -#include "wrappers/libc/stdio_wrappers.h" -#include "wrappers/libc/stdlib_wrappers.h" -#include "wrappers/posix/unistd_wrappers.h" -#include "wrappers/wazuh/shared/audit_op_wrappers.h" -#include "wrappers/wazuh/shared/debug_op_wrappers.h" -#include "wrappers/wazuh/shared/file_op_wrappers.h" -#include "wrappers/wazuh/shared/atomic_wrappers.h" -#include "wrappers/wazuh/shared/time_op_wrappers.h" -#include "wrappers/wazuh/shared/pthreads_op_wrappers.h" - - -#include "wrappers/wazuh/syscheckd/audit_parse_wrappers.h" - - -#define PERMS (AUDIT_PERM_WRITE | AUDIT_PERM_ATTR) - - -extern atomic_int_t audit_health_check_creation; -extern atomic_int_t hc_thread_active; -extern atomic_int_t audit_thread_active; -extern pthread_mutex_t audit_hc_mutex; -extern pthread_cond_t audit_hc_cond; - -extern void __real_atomic_int_set(atomic_int_t *atomic, int value); -extern int __real_atomic_int_get(atomic_int_t *atomic); - -/* setup/teardown */ -static int setup_group(void **state) { - (void) state; - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - (void) state; - memset(&syscheck, 0, sizeof(syscheck_config)); - Free_Syscheck(&syscheck); - test_mode = 0; - return 0; -} - -int __wrap_pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, - const struct timespec *restrict abstime) { - function_called(); - return 0; -} - -/** - * @brief Functions that prepares the wraps calls for starting the audit healthcheck thread - */ -void prepare_audit_healthcheck_thread() { - will_return(__wrap_audit_add_rule, -EEXIST); - - expect_string(__wrap__mdebug1, formatted_msg, FIM_AUDIT_HEALTHCHECK_START); - - expect_function_call(__wrap_pthread_mutex_lock); - - expect_value(__wrap_atomic_int_get, atomic, &hc_thread_active); - will_return(__wrap_atomic_int_get, 0); - expect_value(__wrap_pthread_cond_wait, cond, &audit_hc_cond); - expect_value(__wrap_pthread_cond_wait, mutex, &audit_hc_mutex); - - expect_value(__wrap_atomic_int_get, atomic, &hc_thread_active); - will_return(__wrap_atomic_int_get, 1); - expect_function_call(__wrap_pthread_mutex_unlock); -} - - -/** - * @brief Functions that prepares the wraps calls for stopping the audit healthcheck thread - */ -void prepare_post_audit_healthcheck_thread() { - expect_string(__wrap_unlink, file, AUDIT_HEALTHCHECK_FILE); - will_return(__wrap_unlink, 0); - - expect_string(__wrap_audit_delete_rule, path, AUDIT_HEALTHCHECK_DIR); - expect_value(__wrap_audit_delete_rule, perms, PERMS); - expect_string(__wrap_audit_delete_rule, key, "wazuh_hc"); - will_return(__wrap_audit_delete_rule, 1); - - expect_value(__wrap_atomic_int_set, atomic, &hc_thread_active); - will_return(__wrap_atomic_int_set, 0); - - expect_function_call(__wrap_pthread_mutex_lock); - will_return(__wrap_gettime, 1232); - expect_function_call(__wrap_pthread_cond_timedwait); - expect_function_call(__wrap_pthread_mutex_unlock); -} - -/* audit_health_check() tests */ -void test_audit_health_check_fail_to_add_rule(void **state) { - int ret; - - expect_abspath(AUDIT_HEALTHCHECK_DIR, 1); - expect_abspath(AUDIT_HEALTHCHECK_FILE, 1); - - will_return(__wrap_audit_add_rule, -1); - - expect_string(__wrap__mdebug1, formatted_msg, FIM_AUDIT_HEALTHCHECK_RULE); - - ret = audit_health_check(123456); - - assert_int_equal(ret, -1); - assert_int_equal(hc_thread_active.data, 0); -} - -void test_audit_health_check_fail_to_create_hc_file(void **state) { - int ret; - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - __real_atomic_int_set(&hc_thread_active, 1); - - expect_abspath(AUDIT_HEALTHCHECK_DIR, 1); - expect_abspath(AUDIT_HEALTHCHECK_FILE, 1); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - __real_atomic_int_set(&audit_health_check_creation, 0); - - prepare_audit_healthcheck_thread(); - - expect_string_count(__wrap_wfopen, path, AUDIT_HEALTHCHECK_FILE, 10); - expect_string_count(__wrap_wfopen, mode, "w", 10); - will_return_count(__wrap_wfopen, 0, 10); - - expect_string_count(__wrap__mdebug1, formatted_msg, FIM_AUDIT_HEALTHCHECK_FILE, 10); - - expect_value_count(__wrap_sleep, seconds, 1, 10); - expect_value_count(__wrap_atomic_int_get, atomic, &audit_health_check_creation, 10); - will_return_count(__wrap_atomic_int_get, 0, 10); - // outside do while - expect_value(__wrap_atomic_int_get, atomic, &audit_health_check_creation); - will_return(__wrap_atomic_int_get, 0); - expect_string(__wrap__mdebug1, formatted_msg, FIM_HEALTHCHECK_CREATE_ERROR); - - prepare_post_audit_healthcheck_thread(); - - ret = audit_health_check(123456); - - assert_int_equal(ret, -1); - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - assert_int_equal(__real_atomic_int_get(&hc_thread_active), 0); -} - -void test_audit_health_check_no_creation_event_detected(void **state) { - int ret; - - expect_abspath(AUDIT_HEALTHCHECK_DIR, 1); - expect_abspath(AUDIT_HEALTHCHECK_FILE, 1); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - __real_atomic_int_set(&hc_thread_active, 0); - - prepare_audit_healthcheck_thread(); - - expect_string_count(__wrap_wfopen, path, AUDIT_HEALTHCHECK_FILE, 10); - expect_string_count(__wrap_wfopen, mode, "w", 10); - will_return_count(__wrap_wfopen, 1, 10); - - expect_value_count(__wrap_fclose, _File, 1, 10); - will_return_count(__wrap_fclose, 0, 10); - - expect_value_count(__wrap_sleep, seconds, 1, 10); - expect_value_count(__wrap_atomic_int_get, atomic, &audit_health_check_creation, 10); - will_return_count(__wrap_atomic_int_get, 0, 10); - - // outside the loop - expect_value(__wrap_atomic_int_get, atomic, &audit_health_check_creation); - will_return(__wrap_atomic_int_get, 0); - expect_string(__wrap__mdebug1, formatted_msg, FIM_HEALTHCHECK_CREATE_ERROR); - - prepare_post_audit_healthcheck_thread(); - - ret = audit_health_check(123456); - - assert_int_equal(ret, -1); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - assert_int_equal(__real_atomic_int_get(&hc_thread_active), 0); -} - -void test_audit_health_check_success(void **state) { - int ret; - - expect_abspath(AUDIT_HEALTHCHECK_DIR, 1); - expect_abspath(AUDIT_HEALTHCHECK_FILE, 1); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - __real_atomic_int_set(&hc_thread_active, 0); - - prepare_audit_healthcheck_thread(); - - expect_string(__wrap_wfopen, path, AUDIT_HEALTHCHECK_FILE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - expect_value(__wrap_sleep, seconds, 1); - expect_value(__wrap_atomic_int_get, atomic, &audit_health_check_creation); - will_return(__wrap_atomic_int_get, 1); - - // outside the loop - expect_value(__wrap_atomic_int_get, atomic, &audit_health_check_creation); - will_return(__wrap_atomic_int_get, 1); - expect_string(__wrap__mdebug1, formatted_msg, FIM_HEALTHCHECK_SUCCESS); - - prepare_post_audit_healthcheck_thread(); - - ret = audit_health_check(123456); - assert_int_equal(ret, 0); - - expect_function_call(__wrap_pthread_mutex_lock); - expect_function_call(__wrap_pthread_mutex_unlock); - assert_int_equal(__real_atomic_int_get(&hc_thread_active), 0); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_audit_health_check_fail_to_add_rule), - cmocka_unit_test(test_audit_health_check_fail_to_create_hc_file), - cmocka_unit_test(test_audit_health_check_no_creation_event_detected), - cmocka_unit_test(test_audit_health_check_success), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/syscheckd/whodata/test_audit_parse.c b/src/unit_tests/syscheckd/whodata/test_audit_parse.c deleted file mode 100644 index 3417233ec51..00000000000 --- a/src/unit_tests/syscheckd/whodata/test_audit_parse.c +++ /dev/null @@ -1,1366 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../../syscheckd/include/syscheck.h" -#include "../../../syscheckd/src/whodata/syscheck_audit.h" - -#include "wrappers/externals/audit/libaudit_wrappers.h" -#include "wrappers/externals/procpc/readproc_wrappers.h" -#include "wrappers/libc/stdio_wrappers.h" -#include "wrappers/libc/stdlib_wrappers.h" -#include "wrappers/posix/unistd_wrappers.h" -#include "wrappers/wazuh/shared/audit_op_wrappers.h" -#include "wrappers/wazuh/shared/debug_op_wrappers.h" -#include "wrappers/wazuh/shared/file_op_wrappers.h" -#include "wrappers/wazuh/syscheckd/audit_rule_handling_wrappers.h" - - -#define PERMS (AUDIT_PERM_WRITE | AUDIT_PERM_ATTR) - -extern unsigned int count_reload_retries; -audit_key_type filterkey_audit_events(char *buffer); - -/* setup/teardown */ -static int setup_group(void **state) { - (void) state; - test_mode = 1; - init_regex(); - - return 0; -} - -static int teardown_group(void **state) { - (void) state; - memset(&syscheck, 0, sizeof(syscheck_config)); - Free_Syscheck(&syscheck); - clean_regex(); - test_mode = 0; - return 0; -} - -static int setup_config(void **state) { - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - directory_t *directory0 = fim_create_directory("/var/test", WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - - syscheck.directories = OSList_Create(); - if (syscheck.directories == NULL) { - return -1; - } - - OSList_InsertData(syscheck.directories, NULL, directory0); - - return 0; -} - -static int teardown_config(void **state) { - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - if (syscheck.directories) { - OSList_foreach(node_it, syscheck.directories) { - free_directory(node_it->data); - node_it->data = NULL; - } - OSList_Destroy(syscheck.directories); - syscheck.directories = NULL; - } - - return 0; -} - -static int free_string(void **state) { - char * string = *state; - free(string); - return 0; -} - -static int setup_custom_key(void **state) { - syscheck.audit_key = calloc(2, sizeof(char *)); - if (syscheck.audit_key == NULL) { - return 1; - } - - syscheck.audit_key[0] = calloc(OS_SIZE_64, sizeof(char)); - if (syscheck.audit_key[0] == NULL) { - return 1; - } - return 0; -} - -static int teardown_custom_key(void **state) { - free(syscheck.audit_key[0]); - free(syscheck.audit_key); - syscheck.audit_key = NULL; - return 0; -} - - -void test_filterkey_audit_events_custom(void **state) { - (void) state; - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=\"test_key\""; - char *key = "test_key"; - char buff[OS_SIZE_128] = {0}; - - snprintf(syscheck.audit_key[0], strlen(key) + 1, "%s", key); - - snprintf(buff, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, key); - expect_string(__wrap__mdebug2, formatted_msg, buff); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_CUSTOM_KEY); -} - - -void test_filterkey_audit_events_discard(void **state) { - (void) state; - - char *key = "test_key"; - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=\"test_invalid_key\""; - - syscheck.audit_key = calloc(2, sizeof(char *)); - syscheck.audit_key[0] = calloc(strlen(key) + 2, sizeof(char)); - snprintf(syscheck.audit_key[0], strlen(key) + 1, "%s", key); - - ret = filterkey_audit_events(event); - - free(syscheck.audit_key[0]); - free(syscheck.audit_key); - - assert_int_equal(ret, FIM_AUDIT_UNKNOWN_KEY); -} - - -void test_filterkey_audit_events_hc(void **state) { - (void) state; - - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=\"wazuh_hc\""; - char buff[OS_SIZE_128] = {0}; - - snprintf(buff, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_hc"); - expect_string(__wrap__mdebug2, formatted_msg, buff); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_HC_KEY); -} - - -void test_filterkey_audit_events_fim(void **state) { - (void) state; - - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=\"wazuh_fim\""; - char audit_key_msg[OS_SIZE_128] = {0}; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_KEY); -} - -void test_filterkey_audit_events_missing_whitespace(void **state) { - (void) state; - - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57key=\"wazuh_fim\""; - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_UNKNOWN_KEY); -} - -void test_filterkey_audit_events_missing_equal_sign(void **state) { - (void) state; - - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key\"wazuh_fim\""; - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_UNKNOWN_KEY); -} - -void test_filterkey_audit_events_no_key(void **state) { - (void) state; - - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57"; - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_UNKNOWN_KEY); -} - -void test_filterkey_audit_events_key_at_the_beggining(void **state) { - (void) state; - - audit_key_type ret; - char * event = "key=\"wazuh_fim\" type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57"; - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_KEY); -} - -void test_filterkey_audit_events_key_end_line(void **state) { - (void) state; - - audit_key_type ret; - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 \nkey=\"wazuh_fim\""; - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_KEY); -} - -void test_filterkey_audit_events_hex_coded_key_no_fim(void **state) { - (void) state; - - audit_key_type ret; - snprintf(syscheck.audit_key[0], OS_SIZE_64, "key_1"); - - // The decoded key in the event is "key_1\001key_2" - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=6B65795F31016B65795F32"; - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "key_1"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_CUSTOM_KEY); -} - -void test_filterkey_audit_events_hex_coded_key_no_fim_second_key(void **state) { - (void) state; - - audit_key_type ret; - snprintf(syscheck.audit_key[0], OS_SIZE_64, "key_2"); - // The decoded key in the event is "key_1\001key_2" - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=6B65795F31016B65795F32"; - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "key_2"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_CUSTOM_KEY); -} - -void test_filterkey_audit_events_hex_coded_key_fim(void **state) { - (void) state; - - audit_key_type ret; - // The decoded key of the event is "wazuh_fim\001key_2\001key_1" - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=77617A75685F66696D016B65795F32016B65795F31 "; - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_KEY); -} - -void test_filterkey_audit_events_path_named_key(void **state) { - (void) state; - - audit_key_type ret; - snprintf(syscheck.audit_key[0], OS_SIZE_64, "key_1"); - // The decoded key in the event is "key_1\001key_2" - char * event = "path=\"key\" type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=6B65795F31016B65795F32"; - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "key_1"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_CUSTOM_KEY); -} - -void test_filterkey_audit_events_separator(void **state) { - (void) state; - - audit_key_type ret; - // The decoded key of the event is "wazuh_fim\001key_2\001key_1" - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=77617A75685F66696D016B65795F32016B65795F31\035ARCH= "; - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_KEY); -} - -void test_filterkey_audit_events_separator_in_key(void **state) { - (void) state; - - audit_key_type ret; - // The decoded key of the event is "wazuh_f`5\001key_2\001key_1" - char * event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 key=77617A75685F666035016B65795F32016B65795F31\035ARCH= "; - snprintf(syscheck.audit_key[0], OS_SIZE_64, "wazuh_f`5"); - - char audit_key_msg[OS_SIZE_128] = {0}; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_f`5"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - ret = filterkey_audit_events(event); - - assert_int_equal(ret, FIM_AUDIT_CUSTOM_KEY); -} - - -void test_gen_audit_path(void **state) { - (void) state; - - char * cwd = "/root"; - char * path0 = "/root/test/"; - char * path1 = "/root/test/file"; - - char * ret; - ret = gen_audit_path(cwd, path0, path1); - *state = ret; - - assert_string_equal(ret, "/root/test/file"); -} - - -void test_gen_audit_path2(void **state) { - (void) state; - - char * cwd = "/root"; - char * path0 = "./test/"; - char * path1 = "./test/file"; - - char * ret; - ret = gen_audit_path(cwd, path0, path1); - *state = ret; - - assert_string_equal(ret, "/root/test/file"); -} - - -void test_gen_audit_path3(void **state) { - (void) state; - - char * cwd = "/"; - char * path0 = "root/test/"; - char * path1 = "root/test/file"; - - char * ret; - ret = gen_audit_path(cwd, path0, path1); - *state = ret; - - assert_string_equal(ret, "/root/test/file"); -} - - -void test_gen_audit_path4(void **state) { - (void) state; - - char * cwd = "/"; - char * path0 = "/file"; - - char * ret; - ret = gen_audit_path(cwd, path0, NULL); - *state = ret; - - assert_string_equal(ret, "/file"); -} - - -void test_gen_audit_path5(void **state) { - (void) state; - - char * cwd = "/root/test"; - char * path0 = "../test/"; - char * path1 = "../test/file"; - - char * ret; - ret = gen_audit_path(cwd, path0, path1); - *state = ret; - - assert_string_equal(ret, "/root/test/file"); -} - - -void test_gen_audit_path6(void **state) { - (void) state; - - char * cwd = "/root"; - char * path0 = "./file"; - - char * ret; - ret = gen_audit_path(cwd, path0, NULL); - *state = ret; - - assert_string_equal(ret, "/root/file"); -} - - -void test_gen_audit_path7(void **state) { - (void) state; - - char * cwd = "/root"; - char * path0 = "../file"; - - char * ret; - ret = gen_audit_path(cwd, path0, NULL); - *state = ret; - - assert_string_equal(ret, "/file"); -} - - -void test_gen_audit_path8(void **state) { - (void) state; - - char * cwd = "/root"; - char * path0 = "file"; - - char * ret; - ret = gen_audit_path(cwd, path0, NULL); - *state = ret; - - assert_string_equal(ret, "/root/file"); -} - -void test_get_process_parent_info_failed(void **state) { - (void) state; - - char *parent_name; - char *parent_cwd; - - parent_name = malloc(10); - parent_cwd = malloc(10); - errno = 17; - will_return(__wrap_readlink, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Failure to obtain the name of the process: '1515'. Error: File exists"); - - will_return(__wrap_readlink, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Failure to obtain the cwd of the process: '1515'. Error: File exists"); - get_parent_process_info("1515", &parent_name, &parent_cwd); - errno = 0; - - assert_string_equal(parent_name, ""); - assert_string_equal(parent_cwd, ""); - - if (parent_name != NULL) { - free(parent_name); - parent_name = NULL; - } - - if (parent_cwd != NULL) { - free(parent_cwd); - parent_cwd = NULL; - } -} - -void test_get_process_parent_info_passsed(void **state) { - (void) state; - - char *parent_name; - char *parent_cwd; - - parent_name = malloc(10); - parent_cwd = malloc(10); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - get_parent_process_info("1515", &parent_name, &parent_cwd); - - assert_string_equal(parent_name, ""); - assert_string_equal(parent_cwd, ""); - - if (parent_name != NULL) { - free(parent_name); - parent_name = NULL; - } - - if (parent_cwd != NULL) { - free(parent_cwd); - parent_cwd = NULL; - } -} - -void test_audit_parse(void **state) { - (void) state; - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571914029.306:3004254): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c5f8170490 a2=0 a3=7ff365c5eca0 items=2 ppid=3211 pid=44082 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"test\" exe=\"74657374C3B1\" key=\"wazuh_fim\" \ - type=CWD msg=audit(1571914029.306:3004254): cwd=\"/root/test\" \ - type=PATH msg=audit(1571914029.306:3004254): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571914029.306:3004254): item=1 name=\"test\" inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571914029.306:3004254): proctitle=726D0074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_string(__wrap__mdebug1, formatted_msg, FIM_AUDIT_INVALID_AUID); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6247): audit_event: uid=root, auid=, euid=root, gid=root, pid=44082, ppid=3211, inode=19, path=/root/test/test, pname=74657374C3B1"); - - expect_string(__wrap_realpath, path, "/root/test/test"); - will_return(__wrap_realpath, strdup("/root/test/test")); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 44082); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "74657374C3B1"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/test"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "19"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3211); - - audit_parse(buffer); -} - - -void test_audit_parse3(void **state) { - (void) state; - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571914029.306:3004254): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c5f8170490 a2=0 a3=7ff365c5eca0 items=3 ppid=3211 pid=44082 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"test\" exe=\"74657374C3B1\" key=\"wazuh_fim\" \ - type=CWD msg=audit(1571914029.306:3004254): cwd=\"/root/test\" \ - type=PATH msg=audit(1571925844.299:3004308): item=0 name=\"./\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=1 name=\"folder/\" inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=2 name=\"./test\" inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571914029.306:3004254): proctitle=726D0074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6247): audit_event: uid=root, auid=, euid=root, gid=root, pid=44082, ppid=3211, inode=28, path=/root/test/test, pname=74657374C3B1"); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 44082); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "74657374C3B1"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/test"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "28"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3211); - - audit_parse(buffer); -} - - -void test_audit_parse4(void **state) { - (void) state; - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571923546.947:3004294): arch=c000003e syscall=316 success=yes exit=0 a0=ffffff9c a1=7ffe425fc770 a2=ffffff9c a3=7ffe425fc778 items=4 ppid=3212 pid=51452 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"mv\" exe=66696C655FC3B1 key=\"wazuh_fim\" \ - type=CWD msg=audit(1571923546.947:3004294): cwd=2F726F6F742F746573742F74657374C3B1 \ - type=PATH msg=audit(1571923546.947:3004294): item=0 name=\"./\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571923546.947:3004294): item=1 name=\"folder/\" inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571923546.947:3004294): item=2 name=\"./test\" inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571923546.947:3004294): item=3 name=\"folder/test\" inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571923546.947:3004294): proctitle=6D760066696C655FC3B1002E2E2F74657374C3B1322F66696C655FC3B163 \ - "; - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6248): audit_event_1/2: uid=root, auid=root, euid=root, gid=root, pid=51452, ppid=3212, inode=19, path=/root/test/testñ/test, pname=file_ñ"); - expect_string(__wrap__mdebug2, formatted_msg, - "(6249): audit_event_2/2: uid=root, auid=root, euid=root, gid=root, pid=51452, ppid=3212, inode=19, path=/root/test/testñ/folder/test, pname=file_ñ"); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 51452); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "file_ñ"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/testñ/test"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "19"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3212); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 51452); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "file_ñ"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/testñ/folder/test"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "19"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3212); - - audit_parse(buffer); -} - - -void test_audit_parse_hex(void **state) { - (void) state; - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571923546.947:3004294): arch=c000003e syscall=316 success=yes exit=0 a0=ffffff9c a1=7ffe425fc770 a2=ffffff9c a3=7ffe425fc778 items=4 ppid=3212 pid=51452 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"mv\" exe=66696C655FC3B1 key=\"wazuh_fim\" \ - type=CWD msg=audit(1571923546.947:3004294): cwd=2F726F6F742F746573742F74657374C3B1 \ - type=PATH msg=audit(1571923546.947:3004294): item=0 name=2F726F6F742F746573742F74657374C3B1 inode=19 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571923546.947:3004294): item=1 name=2E2E2F74657374C3B1322F inode=30 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571923546.947:3004294): item=2 name=66696C655FC3B1 inode=29 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571923546.947:3004294): item=3 name=2E2E2F74657374C3B1322F66696C655FC3B163 inode=29 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=CREATE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571923546.947:3004294): proctitle=6D760066696C655FC3B1002E2E2F74657374C3B1322F66696C655FC3B163 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6248): audit_event_1/2: uid=root, auid=root, euid=root, gid=root, pid=51452, ppid=3212, inode=29, path=/root/test/testñ/file_ñ, pname=file_ñ"); - expect_string(__wrap__mdebug2, formatted_msg, - "(6249): audit_event_2/2: uid=root, auid=root, euid=root, gid=root, pid=51452, ppid=3212, inode=29, path=/root/test/testñ2/file_ñc, pname=file_ñ"); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 51452); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "file_ñ"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/testñ/file_ñ"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "29"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3212); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 51452); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "file_ñ"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/testñ2/file_ñc"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "29"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3212); - - audit_parse(buffer); -} - - -void test_audit_parse_empty_fields(void **state) { - (void) state; - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571914029.306:3004254): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c5f8170490 a2=0 a3=7ff365c5eca0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"test\" key=\"wazuh_fim\" \ - type=PROCTITLE msg=audit(1571914029.306:3004254): proctitle=726D0074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - audit_parse(buffer); -} - - -void test_audit_parse_delete(void **state) { - (void) state; - char audit_key_msg[OS_SIZE_128] = {0}; - - - char * buffer = "type=CONFIG_CHANGE msg=audit(1571920603.069:3004276): auid=0 ses=5 op=\"remove_rule\" key=\"wazuh_fim\" list=4 res=1"; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - will_return(__wrap_fim_manipulated_audit_rules, 0); - expect_string(__wrap__mwarn, formatted_msg, "(6911): Detected Audit rules manipulation: Audit rules removed."); - - expect_string(__wrap_SendMSG, message, "ossec: Audit: Detected rules manipulation: Audit rules removed"); - expect_string(__wrap_SendMSG, locmsg, SYSCHECK); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - expect_function_call(__wrap_fim_audit_reload_rules); - - audit_parse(buffer); -} - - -void test_audit_parse_delete_recursive(void **state) { - char * buffer = "type=CONFIG_CHANGE msg=audit(1571920603.069:3004276): auid=0 ses=5 op=remove_rule key=\"wazuh_fim\" list=4 res=1"; - - syscheck.max_audit_entries = 100; - char audit_key_msg[OS_SIZE_128] = {0}; - - count_reload_retries = 0; - // In audit_reload_rules() - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string_count(__wrap__mdebug2, formatted_msg, audit_key_msg, 5); - - will_return_count(__wrap_fim_manipulated_audit_rules, 0, 5); - expect_string_count(__wrap__mwarn, formatted_msg, FIM_WARN_AUDIT_RULES_MODIFIED, 5); - expect_function_calls(__wrap_fim_audit_reload_rules, 4); - - expect_value(__wrap_atomic_int_set, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_set, 0); - - expect_string_count(__wrap_SendMSG, message, "ossec: Audit: Detected rules manipulation: Audit rules removed", 5); - expect_string_count(__wrap_SendMSG, locmsg, SYSCHECK, 6); - expect_value_count(__wrap_SendMSG, loc, LOCALFILE_MQ, 6); - will_return_always(__wrap_SendMSG, 1); - - expect_string(__wrap_SendMSG, message, "ossec: Audit: Detected rules manipulation: Max rules reload retries"); - int i; - for (i = 0; i < 5; i++) { - audit_parse(buffer); - } - - count_reload_retries = 0; -} - - -void test_audit_parse_mv(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571925844.299:3004308): arch=c000003e syscall=82 success=yes exit=0 a0=7ffdbb76377e a1=556c16f6c2e0 a2=0 a3=100 items=5 ppid=3210 pid=52277 auid=20 uid=30 gid=40 euid=50 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"mv\" exe=\"/usr/bin/mv\" key=\"wazuh_fim\" \ - type=CWD msg=audit(1571925844.299:3004308): cwd=\"/root/test\" \ - type=PATH msg=audit(1571925844.299:3004308): item=0 name=\"./\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=1 name=\"folder/\" inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=2 name=\"./test\" inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=3 name=\"folder/test\" inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=4 name=\"folder/test\" inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=CREATE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571925844.299:3004308): proctitle=6D76002E2F7465737400666F6C646572 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 30); - will_return(__wrap_get_user, strdup("user30")); - expect_value(__wrap_get_user, uid, 20); - will_return(__wrap_get_user, strdup("user20")); - expect_value(__wrap_get_user, uid, 50); - will_return(__wrap_get_user, strdup("user50")); - - expect_value(__wrap_get_group, gid, 40); - will_return(__wrap_get_group, strdup("src")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6247): audit_event: uid=user30, auid=user20, euid=user50, gid=src, pid=52277, ppid=3210, inode=28, path=/root/test/folder/test, pname=/usr/bin/mv"); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 52277); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "30"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "40"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "/usr/bin/mv"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/folder/test"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "20"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "50"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "28"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3210); - - audit_parse(buffer); -} - - -void test_audit_parse_mv_hex(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571925844.299:3004308): arch=c000003e syscall=82 success=yes exit=0 a0=7ffdbb76377e a1=556c16f6c2e0 a2=0 a3=100 items=5 ppid=3210 pid=52277 auid=20 uid=30 gid=40 euid=50 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"mv\" exe=\"/usr/bin/mv\" key=\"wazuh_fim\" \ - type=CWD msg=audit(1571925844.299:3004308): cwd=\"/root/test\" \ - type=PATH msg=audit(1571925844.299:3004308): item=0 name=\"./\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=1 name=\"folder/\" inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=2 name=\"./test\" inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=3 name=666F6C6465722F74657374 inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=4 name=666F6C6465722F74657374 inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=CREATE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571925844.299:3004308): proctitle=6D76002E2F7465737400666F6C646572 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 30); - will_return(__wrap_get_user, strdup("user30")); - expect_value(__wrap_get_user, uid, 20); - will_return(__wrap_get_user, strdup("user20")); - expect_value(__wrap_get_user, uid, 50); - will_return(__wrap_get_user, strdup("user50")); - - expect_value(__wrap_get_group, gid, 40); - will_return(__wrap_get_group, strdup("src")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6247): audit_event: uid=user30, auid=user20, euid=user50, gid=src, pid=52277, ppid=3210, inode=28, path=/root/test/folder/test, pname=/usr/bin/mv"); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 52277); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "30"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "40"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "/usr/bin/mv"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/folder/test"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "20"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "50"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "28"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3210); - - audit_parse(buffer); -} - - -void test_audit_parse_rm(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571988027.797:3004340): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55578e6d8490 a2=200 a3=7f9cd931bca0 items=3 ppid=3211 pid=56650 auid=2 uid=30 gid=5 euid=2 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"rm\" exe=\"/usr/bin/rm\" key=\"wazuh_fim\" \ - type=CWD msg=audit(1571988027.797:3004340): cwd=\"/root/test\" \ - type=PATH msg=audit(1571988027.797:3004340): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=1 name=(null) inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=2 name=(null) inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571988027.797:3004340): proctitle=726D002D726600666F6C6465722F \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 30); - will_return(__wrap_get_user, strdup("user30")); - expect_value(__wrap_get_user, uid, 2); - will_return(__wrap_get_user, strdup("daemon")); - expect_value(__wrap_get_user, uid, 2); - will_return(__wrap_get_user, strdup("daemon")); - - expect_value(__wrap_get_group, gid, 5); - will_return(__wrap_get_group, strdup("tty")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6247): audit_event: uid=user30, auid=daemon, euid=daemon, gid=tty, pid=56650, ppid=3211, inode=24, path=/root/test/, pname=/usr/bin/rm"); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 56650); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "30"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "5"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "/usr/bin/rm"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "2"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "2"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "24"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3211); - - audit_parse(buffer); -} - - -void test_audit_parse_chmod(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571992092.822:3004348): arch=c000003e syscall=268 success=yes exit=0 a0=ffffff9c a1=5648a8ab74c0 a2=1ff a3=fff items=1 ppid=3211 pid=58280 auid=4 uid=99 gid=78 euid=29 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"chmod\" exe=\"/usr/bin/chmod\" key=\"wazuh_fim\" \ - type=CWD msg=audit(1571992092.822:3004348): cwd=\"/root/test\" \ - type=PATH msg=audit(1571992092.822:3004348): item=0 name=\"/root/test/file\" inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571992092.822:3004348): proctitle=63686D6F6400373737002F726F6F742F746573742F66696C65 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_value(__wrap_get_user, uid, 99); - will_return(__wrap_get_user, strdup("user99")); - expect_value(__wrap_get_user, uid, 4); - will_return(__wrap_get_user, strdup("lp")); - expect_value(__wrap_get_user, uid, 29); - will_return(__wrap_get_user, strdup("user29")); - - expect_value(__wrap_get_group, gid, 78); - will_return(__wrap_get_group, NULL); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6247): audit_event: uid=user99, auid=lp, euid=user29, gid=, pid=58280, ppid=3211, inode=19, path=/root/test/file, pname=/usr/bin/chmod"); - - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 58280); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "99"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "78"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "/usr/bin/chmod"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test/file"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "4"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "29"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "19"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 3211); - - audit_parse(buffer); -} - - -void test_audit_parse_rm_hc(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571988027.797:3004340): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55578e6d8490 a2=200 a3=7f9cd931bca0 items=3 ppid=3211 pid=56650 auid=2 uid=30 gid=5 euid=2 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"rm\" exe=\"/usr/bin/rm\" key=\"wazuh_hc\" \ - type=CWD msg=audit(1571988027.797:3004340): cwd=\"/root/test\" \ - type=PATH msg=audit(1571988027.797:3004340): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=1 name=(null) inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=2 name=(null) inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571988027.797:3004340): proctitle=726D002D726600666F6C6465722F \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_hc"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - expect_string(__wrap__mdebug2, formatted_msg, "(6253): Whodata health-check: Detected file deletion event (263)"); - - audit_parse(buffer); -} - - -void test_audit_parse_add_hc(void **state) { - (void) state; - extern atomic_int_t audit_health_check_creation; - char audit_key_msg[OS_SIZE_128] = {0}; - - char * buffer = " \ - type=SYSCALL msg=audit(1571988027.797:3004340): arch=c000003e syscall=257 success=yes exit=0 a0=ffffff9c a1=55578e6d8490 a2=200 a3=7f9cd931bca0 items=3 ppid=3211 pid=56650 auid=2 uid=30 gid=5 euid=2 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"touch\" exe=\"/usr/bin/touch\" key=\"wazuh_hc\" \ - type=CWD msg=audit(1571988027.797:3004340): cwd=\"/root/test\" \ - type=PATH msg=audit(1571988027.797:3004340): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=1 name=(null) inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=2 name=(null) inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571988027.797:3004340): proctitle=726D002D726600666F6C6465722F \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_hc"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - expect_string(__wrap__mdebug2, formatted_msg, "(6252): Whodata health-check: Detected file creation event (257)"); - - expect_value(__wrap_atomic_int_set, atomic, &audit_health_check_creation); - will_return(__wrap_atomic_int_set, 1); - - audit_parse(buffer); -} - - -void test_audit_parse_unknown_hc(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=SYSCALL msg=audit(1571988027.797:3004340): arch=c000003e syscall=90 success=yes exit=0 a0=ffffff9c a1=55578e6d8490 a2=200 a3=7f9cd931bca0 items=3 ppid=3211 pid=56650 auid=2 uid=30 gid=5 euid=2 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"chmod\" exe=\"/usr/bin/chmod\" key=\"wazuh_hc\" \ - type=CWD msg=audit(1571988027.797:3004340): cwd=\"/root/test\" \ - type=PATH msg=audit(1571988027.797:3004340): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=1 name=(null) inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571988027.797:3004340): item=2 name=(null) inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1571988027.797:3004340): proctitle=726D002D726600666F6C6465722F \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_hc"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - expect_string(__wrap__mdebug2, formatted_msg, "(6254): Whodata health-check: Unrecognized event (90)"); - - audit_parse(buffer); -} - - -void test_audit_parse_delete_folder(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=CONFIG_CHANGE msg=audit(1572878838.610:220): op=remove_rule dir=\"/root/test\" key=\"wazuh_fim\" list=4 res=1 \ - type=SYSCALL msg=audit(1572878838.610:220): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c2b7d7f490 a2=200 a3=7f2b8055bca0 items=2 ppid=4340 pid=62845 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=7 comm=\"rm\" exe=\"/usr/bin/rm\" key=(null) \ - type=CWD msg=audit(1572878838.610:220): cwd=\"/root\" \ - type=PATH msg=audit(1572878838.610:220): item=0 name=\"/root\" inode=655362 dev=08:02 mode=040700 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1572878838.610:220): item=1 name=\"test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1572878838.610:220): proctitle=726D002D72660074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - expect_string(__wrap__minfo, formatted_msg, "(6027): Monitored directory '/root/test' was removed: Audit rule removed."); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6247): audit_event: uid=root, auid=root, euid=root, gid=root, pid=62845, ppid=4340, inode=110, path=/root/test, pname=/usr/bin/rm"); - - expect_string(__wrap_realpath, path, "/root/test"); - will_return(__wrap_realpath, strdup("/root/test")); - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 62845); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "/usr/bin/rm"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "110"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 4340); - - expect_string(__wrap_SendMSG, message, "ossec: Audit: Monitored directory was removed: Audit rule removed"); - expect_string(__wrap_SendMSG, locmsg, SYSCHECK); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - audit_parse(buffer); -} - - -void test_audit_parse_delete_folder_hex(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=CONFIG_CHANGE msg=audit(1572878838.610:220): op=remove_rule dir=2F726F6F742F746573742F74657374C3B1 key=\"wazuh_fim\" list=4 res=1 \ - type=SYSCALL msg=audit(1572878838.610:220): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c2b7d7f490 a2=200 a3=7f2b8055bca0 items=2 ppid=4340 pid=62845 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=7 comm=\"rm\" exe=\"/usr/bin/rm\" key=(null) \ - type=CWD msg=audit(1572878838.610:220): cwd=\"/root\" \ - type=PATH msg=audit(1572878838.610:220): item=0 name=\"/root\" inode=655362 dev=08:02 mode=040700 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1572878838.610:220): item=1 name=\"test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1572878838.610:220): proctitle=726D002D72660074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - expect_string(__wrap__minfo, formatted_msg, "(6027): Monitored directory '/root/test/testñ' was removed: Audit rule removed."); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6247): audit_event: uid=root, auid=root, euid=root, gid=root, pid=62845, ppid=4340, inode=110, path=/root/test, pname=/usr/bin/rm"); - - expect_string(__wrap_realpath, path, "/root/test"); - will_return(__wrap_realpath, strdup("/root/test")); - - - expect_value(__wrap_fim_whodata_event, w_evt->process_id, 62845); - expect_string(__wrap_fim_whodata_event, w_evt->user_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->group_id, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->process_name, "/usr/bin/rm"); - expect_string(__wrap_fim_whodata_event, w_evt->path, "/root/test"); - expect_string(__wrap_fim_whodata_event, w_evt->audit_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->effective_uid, "0"); - expect_string(__wrap_fim_whodata_event, w_evt->inode, "110"); - expect_value(__wrap_fim_whodata_event, w_evt->ppid, 4340); - - expect_string(__wrap_SendMSG, message, "ossec: Audit: Monitored directory was removed: Audit rule removed"); - expect_string(__wrap_SendMSG, locmsg, SYSCHECK); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - audit_parse(buffer); -} - - -void test_audit_parse_delete_folder_hex3_error(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=CONFIG_CHANGE msg=audit(1572878838.610:220): op=remove_rule dir=0 key=\"wazuh_fim\" list=4 res=1 \ - type=SYSCALL msg=audit(1572878838.610:220): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c2b7d7f490 a2=200 a3=7f2b8055bca0 items=3 ppid=4340 pid=62845 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=7 comm=\"rm\" exe=1 key=(null) \ - type=CWD msg=audit(1572878838.610:220): cwd=2 \ - type=PATH msg=audit(1571925844.299:3004308): item=0 name=3 inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=1 name=4 inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=2 name=5 inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1572878838.610:220): proctitle=726D002D72660074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '0'"); - - will_return(__wrap_fim_manipulated_audit_rules, 0); - expect_string(__wrap__mwarn, formatted_msg, "(6911): Detected Audit rules manipulation: Audit rules removed."); - expect_function_call(__wrap_fim_audit_reload_rules); - - expect_string(__wrap_SendMSG, message, "ossec: Audit: Detected rules manipulation: Audit rules removed"); - expect_string(__wrap_SendMSG, locmsg, SYSCHECK); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '1'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '2'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '3'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '4'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '5'"); - - audit_parse(buffer); -} - - -void test_audit_parse_delete_folder_hex4_error(void **state) { - (void) state; - char audit_key_msg[OS_SIZE_128] = {0}; - - char * buffer = " \ - type=CONFIG_CHANGE msg=audit(1572878838.610:220): op=remove_rule dir=0 key=\"wazuh_fim\" list=4 res=1 \ - type=SYSCALL msg=audit(1572878838.610:220): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c2b7d7f490 a2=200 a3=7f2b8055bca0 items=4 ppid=4340 pid=62845 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=7 comm=\"rm\" exe=1 key=(null) \ - type=CWD msg=audit(1572878838.610:220): cwd=2 \ - type=PATH msg=audit(1571925844.299:3004308): item=0 name=3 inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=1 name=4 inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=2 name=5 inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=3 name=6 inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1572878838.610:220): proctitle=726D002D72660074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '0'"); - - will_return(__wrap_fim_manipulated_audit_rules, 0); - expect_string(__wrap__mwarn, formatted_msg, "(6911): Detected Audit rules manipulation: Audit rules removed."); - expect_function_call(__wrap_fim_audit_reload_rules); - - expect_string(__wrap_SendMSG, message, "ossec: Audit: Detected rules manipulation: Audit rules removed"); - expect_string(__wrap_SendMSG, locmsg, SYSCHECK); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '1'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '2'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '3'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '4'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '5'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '6'"); - - audit_parse(buffer); -} - - -void test_audit_parse_delete_folder_hex5_error(void **state) { - (void) state; - - char audit_key_msg[OS_SIZE_128] = {0}; - char * buffer = " \ - type=CONFIG_CHANGE msg=audit(1572878838.610:220): op=remove_rule dir=0 key=\"wazuh_fim\" list=4 res=1 \ - type=SYSCALL msg=audit(1572878838.610:220): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c2b7d7f490 a2=200 a3=7f2b8055bca0 items=5 ppid=4340 pid=62845 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=7 comm=\"rm\" exe=1 key=(null) \ - type=CWD msg=audit(1572878838.610:220): cwd=2 \ - type=PATH msg=audit(1571925844.299:3004308): item=0 name=3 inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=1 name=4 inode=24 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=2 name=5 inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=3 name=6 inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PATH msg=audit(1571925844.299:3004308): item=4 name=7 inode=28 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=CREATE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 \ - type=PROCTITLE msg=audit(1572878838.610:220): proctitle=726D002D72660074657374 \ - "; - - snprintf(audit_key_msg, OS_SIZE_128, FIM_AUDIT_MATCH_KEY, "wazuh_fim"); - expect_string(__wrap__mdebug2, formatted_msg, audit_key_msg); - - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '0'"); - - will_return(__wrap_fim_manipulated_audit_rules, 0); - expect_string(__wrap__mwarn, formatted_msg, "(6911): Detected Audit rules manipulation: Audit rules removed."); - expect_function_call(__wrap_fim_audit_reload_rules); - - expect_string(__wrap_SendMSG, message, "ossec: Audit: Detected rules manipulation: Audit rules removed"); - expect_string(__wrap_SendMSG, locmsg, SYSCHECK); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - expect_value(__wrap_get_user, uid, 0); - will_return(__wrap_get_user, strdup("root")); - - expect_value(__wrap_get_group, gid, 0); - will_return(__wrap_get_group, strdup("root")); - - will_return(__wrap_readlink, 0); - will_return(__wrap_readlink, 0); - - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '1'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '2'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '3'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '4'"); - expect_string(__wrap__merror, formatted_msg, "Error found while decoding HEX bufer: '7'"); - - audit_parse(buffer); -} -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_filterkey_audit_events_custom, setup_custom_key, teardown_custom_key), - cmocka_unit_test(test_filterkey_audit_events_discard), - cmocka_unit_test(test_filterkey_audit_events_fim), - cmocka_unit_test(test_filterkey_audit_events_hc), - cmocka_unit_test(test_filterkey_audit_events_missing_whitespace), - cmocka_unit_test(test_filterkey_audit_events_missing_equal_sign), - cmocka_unit_test(test_filterkey_audit_events_no_key), - cmocka_unit_test(test_filterkey_audit_events_key_at_the_beggining), - cmocka_unit_test(test_filterkey_audit_events_key_end_line), - cmocka_unit_test(test_filterkey_audit_events_hex_coded_key_fim), - cmocka_unit_test(test_filterkey_audit_events_separator), - cmocka_unit_test_setup_teardown(test_filterkey_audit_events_separator_in_key, setup_custom_key, teardown_custom_key), - cmocka_unit_test_setup_teardown(test_filterkey_audit_events_hex_coded_key_no_fim, setup_custom_key, teardown_custom_key), - cmocka_unit_test_setup_teardown(test_filterkey_audit_events_hex_coded_key_no_fim_second_key, setup_custom_key, teardown_custom_key), - cmocka_unit_test_setup_teardown(test_filterkey_audit_events_path_named_key, setup_custom_key, teardown_custom_key), - cmocka_unit_test_teardown(test_gen_audit_path, free_string), - cmocka_unit_test_teardown(test_gen_audit_path2, free_string), - cmocka_unit_test_teardown(test_gen_audit_path3, free_string), - cmocka_unit_test_teardown(test_gen_audit_path4, free_string), - cmocka_unit_test_teardown(test_gen_audit_path5, free_string), - cmocka_unit_test_teardown(test_gen_audit_path6, free_string), - cmocka_unit_test_teardown(test_gen_audit_path7, free_string), - cmocka_unit_test_teardown(test_gen_audit_path8, free_string), - cmocka_unit_test(test_get_process_parent_info_failed), - cmocka_unit_test(test_get_process_parent_info_passsed), - cmocka_unit_test(test_audit_parse), - cmocka_unit_test(test_audit_parse3), - cmocka_unit_test(test_audit_parse4), - cmocka_unit_test(test_audit_parse_hex), - cmocka_unit_test(test_audit_parse_empty_fields), - cmocka_unit_test(test_audit_parse_delete), - cmocka_unit_test_setup_teardown(test_audit_parse_delete_recursive, setup_config, teardown_config), - cmocka_unit_test(test_audit_parse_mv), - cmocka_unit_test(test_audit_parse_mv_hex), - cmocka_unit_test(test_audit_parse_rm), - cmocka_unit_test(test_audit_parse_chmod), - cmocka_unit_test(test_audit_parse_rm_hc), - cmocka_unit_test(test_audit_parse_add_hc), - cmocka_unit_test(test_audit_parse_unknown_hc), - cmocka_unit_test(test_audit_parse_delete_folder), - cmocka_unit_test(test_audit_parse_delete_folder_hex), - cmocka_unit_test(test_audit_parse_delete_folder_hex3_error), - cmocka_unit_test(test_audit_parse_delete_folder_hex4_error), - cmocka_unit_test(test_audit_parse_delete_folder_hex5_error), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/syscheckd/whodata/test_audit_rule_handling.c b/src/unit_tests/syscheckd/whodata/test_audit_rule_handling.c deleted file mode 100644 index 5f594468453..00000000000 --- a/src/unit_tests/syscheckd/whodata/test_audit_rule_handling.c +++ /dev/null @@ -1,491 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../../syscheckd/include/syscheck.h" -#include "../../../syscheckd/src/whodata/syscheck_audit.h" - - -#include "wrappers/externals/audit/libaudit_wrappers.h" -#include "wrappers/externals/procpc/readproc_wrappers.h" -#include "wrappers/libc/stdio_wrappers.h" -#include "wrappers/libc/stdlib_wrappers.h" -#include "wrappers/posix/unistd_wrappers.h" -#include "wrappers/wazuh/shared/audit_op_wrappers.h" -#include "wrappers/wazuh/shared/debug_op_wrappers.h" -#include "wrappers/wazuh/shared/file_op_wrappers.h" -#include "wrappers/wazuh/syscheckd/audit_parse_wrappers.h" - - -#define PERMS (AUDIT_PERM_WRITE | AUDIT_PERM_ATTR) -#define CHECK_ALL \ - (CHECK_MD5SUM | CHECK_SHA1SUM | CHECK_SHA256SUM | CHECK_PERM | CHECK_SIZE | CHECK_OWNER | CHECK_GROUP | \ - CHECK_MTIME | CHECK_INODE) - -extern OSList *whodata_directories; -OSList *GENERAL_CONFIG; -OSList *RELOAD_CONFIG; - -extern int audit_rule_manipulation; - -extern atomic_int_t audit_thread_active; - -/* setup/teardown */ -static int setup_group(void **state) { - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - directory_t *directory0 = fim_create_directory("/testdir0", CHECK_ALL | WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - directory_t *directory1 = fim_create_directory("/testdir1", CHECK_ALL | WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - directory_t *directory2 = fim_create_directory("/testdir2", CHECK_ALL | WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - directory_t *directory3 = fim_create_directory("/testdir3", CHECK_ALL | WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - directory_t *directory4 = fim_create_directory("/testdir4", CHECK_ALL | WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - directory_t *directory5 = fim_create_directory("/testdir5", CHECK_ALL | WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - directory_t *directory6 = fim_create_directory("/etc", CHECK_ALL | WHODATA_ACTIVE, NULL, 512, NULL, 1024, 0); - - directory_t *general_directory0 = fim_copy_directory(directory0); - directory_t *general_directory1 = fim_copy_directory(directory1); - directory_t *general_directory2 = fim_copy_directory(directory2); - directory_t *general_directory3 = fim_copy_directory(directory3); - directory_t *general_directory4 = fim_copy_directory(directory4); - - // Initialize directories list - GENERAL_CONFIG = OSList_Create(); - RELOAD_CONFIG = OSList_Create(); - if (GENERAL_CONFIG == NULL || RELOAD_CONFIG == NULL) { - return -1; - } - - OSList_InsertData(GENERAL_CONFIG, NULL, general_directory0); - OSList_InsertData(GENERAL_CONFIG, NULL, general_directory1); - OSList_InsertData(GENERAL_CONFIG, NULL, general_directory2); - OSList_InsertData(GENERAL_CONFIG, NULL, general_directory3); - OSList_InsertData(GENERAL_CONFIG, NULL, general_directory4); - - OSList_InsertData(RELOAD_CONFIG, NULL, directory0); - OSList_InsertData(RELOAD_CONFIG, NULL, directory1); - OSList_InsertData(RELOAD_CONFIG, NULL, directory2); - OSList_InsertData(RELOAD_CONFIG, NULL, directory3); - OSList_InsertData(RELOAD_CONFIG, NULL, directory4); - OSList_InsertData(RELOAD_CONFIG, NULL, directory5); - OSList_InsertData(RELOAD_CONFIG, NULL, directory6); - - syscheck.directories = GENERAL_CONFIG; - - // The basic list needs to be created, we won't test this function. - fim_audit_rules_init(); - - return 0; -} - -static int teardown_group(void **state) { - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - if (GENERAL_CONFIG) { - OSList_foreach(node_it, GENERAL_CONFIG) { - free_directory(node_it->data); - node_it->data = NULL; - } - OSList_Destroy(GENERAL_CONFIG); - GENERAL_CONFIG = NULL; - } - - if (RELOAD_CONFIG) { - OSList_foreach(node_it, RELOAD_CONFIG) { - free_directory(node_it->data); - node_it->data = NULL; - } - OSList_Destroy(RELOAD_CONFIG); - RELOAD_CONFIG = NULL; - } - - return 0; -} - -static int teardown_clean_rules_list(void **state) { - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - OSList_CleanNodes(whodata_directories); - - return 0; -} - -static int setup_add_directories_to_whodata_list(void **state) { - directory_t *dir_it; - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - syscheck.directories = RELOAD_CONFIG; - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - whodata_directory_t *dir = calloc(1, sizeof(whodata_directory_t)); - - if (dir == NULL) { - return -1; - } - - dir->path = strdup(dir_it->path); - - if (dir->path == NULL) { - return -1; - } - - OSList_AddData(whodata_directories, dir); - } - - syscheck.max_audit_entries = whodata_directories->currently_size; - - return 0; -} - -static int teardown_reload_rules(void **state) { - syscheck.directories = GENERAL_CONFIG; - - syscheck.max_audit_entries = 256; - - teardown_clean_rules_list(state); - - return 0; -} - -static void test_add_whodata_directory(void **state) { - const char *test_string = "/some/path"; - whodata_directory_t *probe; - - assert_int_equal(whodata_directories->currently_size, 0); - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - add_whodata_directory(test_string); - - assert_int_equal(whodata_directories->currently_size, 1); - - probe = whodata_directories->first_node->data; - assert_string_equal(probe->path, test_string); - - probe->pending_removal = 1; - - add_whodata_directory(test_string); - - assert_ptr_equal(probe, whodata_directories->first_node->data); - assert_int_equal(probe->pending_removal, 0); -} - -static void test_remove_audit_rule_syscheck(void **state) { - whodata_directory_t *dir = calloc(1, sizeof(whodata_directory_t)); - - if (dir == NULL) { - fail_msg("Failed to allocate memory for whodata_directory_t"); - } - - dir->pending_removal = 0; - dir->path = strdup("/some/path"); - - if (dir->path == NULL) { - fail_msg("Failed to allocate memory for path"); - } - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - if (OSList_AddData(whodata_directories, dir) == NULL) { - fail_msg("Failed to add directory to the whodata rules list"); - } - - remove_audit_rule_syscheck("/some/path"); - - assert_int_equal(dir->pending_removal, 1); -} - -static void test_fim_manipulated_audit_rules(void **state) { - audit_rule_manipulation = 2; - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - assert_int_equal(fim_manipulated_audit_rules(), 2); - assert_int_equal(fim_manipulated_audit_rules(), 1); - assert_int_equal(fim_manipulated_audit_rules(), 0); - assert_int_equal(fim_manipulated_audit_rules(), 0); -} - -void test_rules_initial_load_new_rules(void **state) { - char log_messages[5][OS_SIZE_512]; - int total_rules; - - syscheck.max_audit_entries = 256; // Default value - - will_return(__wrap_audit_open, 1); - will_return(__wrap_audit_get_rule_list, 1); - will_return(__wrap_audit_close, 1); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // First directory will be added - will_return(__wrap_search_audit_rule, 0); - will_return(__wrap_audit_add_rule, 15); - - snprintf(log_messages[0], OS_SIZE_512, FIM_AUDIT_NEWRULE, ((directory_t *)OSList_GetDataFromIndex(GENERAL_CONFIG, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, log_messages[0]); - - // Second directory will have the rule already configured - will_return(__wrap_search_audit_rule, 0); - will_return(__wrap_audit_add_rule, -EEXIST); - - snprintf(log_messages[1], OS_SIZE_512, FIM_AUDIT_ALREADY_ADDED, ((directory_t *)OSList_GetDataFromIndex(GENERAL_CONFIG, 1))->path); - expect_string(__wrap__mdebug2, formatted_msg, log_messages[1]); - - // Third directory will encounter an error - will_return(__wrap_search_audit_rule, 0); - will_return(__wrap_audit_add_rule, -1); - snprintf(log_messages[2], OS_SIZE_512, FIM_WARN_WHODATA_ADD_RULE, ((directory_t *)OSList_GetDataFromIndex(GENERAL_CONFIG, 2))->path); - expect_string(__wrap__mwarn, formatted_msg, log_messages[2]); - - // Fourth directory will be duplicated on the audit_op list - will_return(__wrap_search_audit_rule, 1); - - snprintf(log_messages[3], OS_SIZE_512, FIM_AUDIT_RULEDUP, ((directory_t *)OSList_GetDataFromIndex(GENERAL_CONFIG, 3))->path); - expect_string(__wrap__mdebug2, formatted_msg, log_messages[3]); - - // Fifth directory will encounter an error - will_return(__wrap_search_audit_rule, -1); - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_WHODATA_CHECK_RULE); - - total_rules = fim_rules_initial_load(); - - assert_int_equal(total_rules, 1); -} - -void test_rules_initial_load_max_audit_entries(void **state) { - char log_messages[2][OS_SIZE_512]; - int total_rules; - - syscheck.max_audit_entries = 1; - - will_return(__wrap_audit_open, 1); - will_return(__wrap_audit_get_rule_list, 1); - will_return(__wrap_audit_close, 1); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // First directory will be added - will_return(__wrap_search_audit_rule, 0); - will_return(__wrap_audit_add_rule, 15); - - snprintf(log_messages[0], OS_SIZE_512, FIM_AUDIT_NEWRULE, ((directory_t *)OSList_GetDataFromIndex(GENERAL_CONFIG, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, log_messages[0]); - - // Second directory will be ignored, since we have room for 1 entry - snprintf(log_messages[1], OS_SIZE_512, FIM_ERROR_WHODATA_MAXNUM_WATCHES, ((directory_t *)OSList_GetDataFromIndex(GENERAL_CONFIG, 1))->path, - syscheck.max_audit_entries); - expect_string(__wrap__merror, formatted_msg, log_messages[1]); - - total_rules = fim_rules_initial_load(); - - assert_int_equal(total_rules, 1); -} - -static void test_clean_rules(void **state) { - // Ensure there are rules loaded prior to trying to delete them - assert_int_not_equal(whodata_directories->currently_size, 0); - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_AUDIT_DELETE_RULE); - - expect_value(__wrap_atomic_int_set, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_set, 0); - - expect_any_count(__wrap_audit_delete_rule, path, whodata_directories->currently_size); - expect_any_count(__wrap_audit_delete_rule, perms, whodata_directories->currently_size); - expect_any_count(__wrap_audit_delete_rule, key, whodata_directories->currently_size); - will_return_count(__wrap_audit_delete_rule, 1, whodata_directories->currently_size); - - clean_rules(); - - assert_int_equal(whodata_directories->currently_size, 0); -} - -static void test_fim_audit_reload_rules(void **state) { - char log_messages[7][OS_SIZE_512]; - int initial_rules = whodata_directories->currently_size; - whodata_directory_t *probe; - - assert_int_not_equal(initial_rules, 0); - - // We will mark the first and third entry for removal. - probe = whodata_directories->first_node->data; - probe->pending_removal = 1; - - probe = whodata_directories->first_node->next->next->data; - probe->pending_removal = 1; - - expect_string(__wrap__mdebug1, formatted_msg, FIM_AUDIT_RELOADING_RULES); - - will_return(__wrap_audit_open, 1); - will_return(__wrap_audit_get_rule_list, 1); - will_return(__wrap_audit_close, 1); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // First directory won't have a configured rule - will_return(__wrap_search_audit_rule, 0); - - // Second directory will be added to audit - will_return(__wrap_search_audit_rule, 0); - will_return(__wrap_audit_add_rule, 15); - - snprintf(log_messages[1], OS_SIZE_512, FIM_AUDIT_NEWRULE, ((directory_t *)OSList_GetDataFromIndex(RELOAD_CONFIG, 1))->path); - expect_string(__wrap__mdebug2, formatted_msg, log_messages[1]); - - // Third directory will be removed from audit - will_return(__wrap_search_audit_rule, 1); - expect_string(__wrap_audit_delete_rule, path, ((directory_t *)OSList_GetDataFromIndex(RELOAD_CONFIG, 2))->path); - expect_value(__wrap_audit_delete_rule, perms, PERMS); - expect_string(__wrap_audit_delete_rule, key, AUDIT_KEY); - will_return(__wrap_audit_delete_rule, 1); - - // Fourth directory will be a rule that is already added to audit - will_return(__wrap_search_audit_rule, 1); - - snprintf(log_messages[3], OS_SIZE_512, FIM_AUDIT_RULEDUP, ((directory_t *)OSList_GetDataFromIndex(RELOAD_CONFIG, 3))->path); - expect_string(__wrap__mdebug2, formatted_msg, log_messages[3]); - - // Fifth directory will fail to be added - will_return(__wrap_search_audit_rule, 0); - will_return(__wrap_audit_add_rule, -1); - snprintf(log_messages[4], OS_SIZE_512, FIM_WARN_WHODATA_ADD_RULE, ((directory_t *)OSList_GetDataFromIndex(RELOAD_CONFIG, 4))->path); - expect_string(__wrap__mdebug1, formatted_msg, log_messages[4]); - - // Sixth directory will attempt to be added, but find it's duplicated - will_return(__wrap_search_audit_rule, 0); - will_return(__wrap_audit_add_rule, -EEXIST); - - snprintf(log_messages[5], OS_SIZE_512, FIM_AUDIT_ALREADY_ADDED, ((directory_t *)OSList_GetDataFromIndex(RELOAD_CONFIG, 5))->path); - expect_string(__wrap__mdebug2, formatted_msg, log_messages[5]); - - // Seventh directory will encounter an error when searching the rule - will_return(__wrap_search_audit_rule, -1); - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_WHODATA_CHECK_RULE); - - expect_any(__wrap__mdebug1, formatted_msg); - - fim_audit_reload_rules(); - - assert_int_equal(whodata_directories->currently_size, initial_rules - 2); - assert_int_equal(audit_rule_manipulation, 1); -} - -static void test_fim_audit_reload_rules_full(void **state) { - char log_messages[7][OS_SIZE_512]; - int initial_rules = whodata_directories->currently_size; - int i = 0; - OSListNode *node_it; - directory_t *dir_it; - - // We trick fim_audit_reload_rules() into thinking it already has added all possible rules. - syscheck.max_audit_entries = 0; - - assert_int_not_equal(initial_rules, 0); - - expect_string(__wrap__mdebug1, formatted_msg, FIM_AUDIT_RELOADING_RULES); - - will_return(__wrap_audit_open, 1); - will_return(__wrap_audit_get_rule_list, 1); - will_return(__wrap_audit_close, 1); - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - will_return_always(__wrap_search_audit_rule, 0); - - OSList_foreach(node_it, RELOAD_CONFIG) { - dir_it = node_it->data; - snprintf(log_messages[i], OS_SIZE_512, FIM_ERROR_WHODATA_MAXNUM_WATCHES, dir_it->path, 0); - if (i == 0) { - // First directory will cause an error message - expect_string(__wrap__merror, formatted_msg, log_messages[i]); - } else { - // The rest of them will trigger debug messages - expect_string(__wrap__mdebug2, formatted_msg, log_messages[i]); - } - i++; - } - - expect_any(__wrap__mdebug1, formatted_msg); - - fim_audit_reload_rules(); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_teardown(test_add_whodata_directory, teardown_clean_rules_list), - cmocka_unit_test_teardown(test_remove_audit_rule_syscheck, teardown_clean_rules_list), - cmocka_unit_test(test_fim_manipulated_audit_rules), - - // fim_rules_initial_load - cmocka_unit_test_teardown(test_rules_initial_load_new_rules, teardown_clean_rules_list), - cmocka_unit_test(test_rules_initial_load_max_audit_entries), - - cmocka_unit_test_setup(test_clean_rules, setup_add_directories_to_whodata_list), - - cmocka_unit_test_setup_teardown(test_fim_audit_reload_rules, setup_add_directories_to_whodata_list, - teardown_reload_rules), - cmocka_unit_test_setup_teardown(test_fim_audit_reload_rules_full, setup_add_directories_to_whodata_list, - teardown_reload_rules), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/syscheckd/whodata/test_syscheck_audit.c b/src/unit_tests/syscheckd/whodata/test_syscheck_audit.c deleted file mode 100644 index edd3870a6f8..00000000000 --- a/src/unit_tests/syscheckd/whodata/test_syscheck_audit.c +++ /dev/null @@ -1,1534 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "wrappers/common.h" -#include "../../../syscheckd/include/syscheck.h" -#include "../../../syscheckd/src/whodata/syscheck_audit.h" - -#include "wrappers/externals/procpc/readproc_wrappers.h" -#include "wrappers/libc/stdio_wrappers.h" -#include "wrappers/libc/stdlib_wrappers.h" -#include "wrappers/posix/unistd_wrappers.h" -#include "wrappers/wazuh/shared/debug_op_wrappers.h" -#include "wrappers/wazuh/shared/file_op_wrappers.h" -#include "wrappers/wazuh/shared/mq_op_wrappers.h" -#include "wrappers/wazuh/os_net/os_net_wrappers.h" -#include "wrappers/wazuh/os_crypto/sha1_op_wrappers.h" -#include "wrappers/wazuh/syscheckd/audit_parse_wrappers.h" -#include "wrappers/wazuh/syscheckd/audit_rule_handling_wrappers.h" - -#include "../../../external/procps/readproc.h" - -extern atomic_int_t audit_health_check_creation; -extern atomic_int_t hc_thread_active; -extern atomic_int_t audit_thread_active; -extern atomic_int_t audit_parse_thread_active; -extern w_queue_t * audit_queue; - -#define AUDIT_RULES_FILE "etc/audit_rules_wazuh.rules" -#define AUDIT_RULES_LINK "/etc/audit/rules.d/audit_rules_wazuh.rules" - -int hc_success = 0; - -int __wrap_recv(int __fd, void *__buf, size_t __n, int __flags) { - int ret; - int n; - check_expected(__fd); - n = mock(); - if(n < __n) - ret = n; - else - ret = __n; - if(ret > 0) - memcpy(__buf, mock_type(void*), ret); - - return ret; -} - - -/* setup/teardown */ -static int setup_group(void **state) { - (void) state; - test_mode = 1; - w_mutex_init(&(audit_health_check_creation.mutex), NULL); - w_mutex_init(&(hc_thread_active.mutex), NULL); - w_mutex_init(&(audit_thread_active.mutex), NULL); - w_mutex_init(&(audit_parse_thread_active.mutex), NULL); - audit_queue = queue_init(2); - - return 0; -} - -static int teardown_group(void **state) { - (void) state; - memset(&syscheck, 0, sizeof(syscheck_config)); - Free_Syscheck(&syscheck); - test_mode = 0; - return 0; -} - -static int free_string(void **state) { - char * string = *state; - free(string); - return 0; -} - -static char *CUSTOM_KEY[] = { [0] = "custom_key", [1] = NULL }; - -static int setup_syscheck_dir_links(void **state) { - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - syscheck.audit_key = CUSTOM_KEY; - - directory_t *directory0 = fim_create_directory("/test0", WHODATA_ACTIVE, NULL, 512, - NULL, -1, 0); - - directory_t *directory1 = fim_create_directory("/test1", WHODATA_ACTIVE, NULL, 512, - NULL, -1, 0); - - syscheck.directories = OSList_Create(); - if (syscheck.directories == NULL) { - return (1); - } - - OSList_InsertData(syscheck.directories, NULL, directory0); - OSList_InsertData(syscheck.directories, NULL, directory1); - - return 0; -} - -static int teardown_syscheck_dir_links(void **state) { - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - if (syscheck.directories) { - OSList_foreach(node_it, syscheck.directories) { - free_directory(node_it->data); - node_it->data = NULL; - } - OSList_Destroy(syscheck.directories); - syscheck.directories = NULL; - } - - return 0; -} - -static int teardown_rules_to_realtime(void **state) { - OSHash_Free(syscheck.realtime->dirtb); - free(syscheck.realtime); - syscheck.realtime = NULL; - teardown_syscheck_dir_links(state); - return 0; -} - -void test_check_auditd_enabled_success(void **state) { - (void) state; - int ret; - - proc_t *mock_proc; - - mock_proc = calloc(3, sizeof(proc_t)); - - snprintf(mock_proc[0].cmd, 16, "not-auditd"); - mock_proc[0].tid = 20; - - snprintf(mock_proc[1].cmd, 16, "something"); - mock_proc[1].tid = 25; - - snprintf(mock_proc[2].cmd, 16, "auditd"); - mock_proc[2].tid = 15; - - expect_value(__wrap_openproc, flags, PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLCOM); - will_return(__wrap_openproc, 1234); - - expect_value_count(__wrap_readproc, PT, 1234, 3); - expect_value_count(__wrap_readproc, p, NULL, 3); - will_return(__wrap_readproc, &mock_proc[0]); - will_return(__wrap_readproc, &mock_proc[1]); - will_return(__wrap_readproc, &mock_proc[2]); - - expect_value(__wrap_freeproc, p, &mock_proc[0]); - expect_value(__wrap_freeproc, p, &mock_proc[1]); - expect_value(__wrap_freeproc, p, &mock_proc[2]); - - expect_value(__wrap_closeproc, PT, 1234); - - ret = check_auditd_enabled(); - assert_return_code(ret, 0); - free(mock_proc); -} - -void test_check_auditd_enabled_openproc_error(void **state) { - (void) state; - int ret; - - expect_value(__wrap_openproc, flags, PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLCOM); - will_return(__wrap_openproc, NULL); - - ret = check_auditd_enabled(); - assert_int_equal(ret, -1); -} - -void test_check_auditd_enabled_readproc_error(void **state) { - (void) state; - int ret; - - expect_value(__wrap_openproc, flags, PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLCOM); - will_return(__wrap_openproc, 1234); - - expect_value(__wrap_readproc, PT, 1234); - expect_value(__wrap_readproc, p, NULL); - will_return(__wrap_readproc, NULL); - - expect_value(__wrap_closeproc, PT, 1234); - - ret = check_auditd_enabled(); - assert_int_equal(ret, -1); -} - -static int test_audit_read_events_setup(void **state) { - int *audit_sock; - audit_sock = calloc(1, sizeof(int)); - *state = audit_sock; - return 0; -} - -static int test_audit_read_events_teardown(void **state) { - int *audit_sock = *state; - free(audit_sock); - return 0; -} - - -/* tests */ - -void test_init_auditd_socket_success(void **state) { - (void) state; - int ret; - - expect_any(__wrap_OS_ConnectUnixDomain, path); - expect_any(__wrap_OS_ConnectUnixDomain, type); - expect_any(__wrap_OS_ConnectUnixDomain, max_msg_size); - will_return(__wrap_OS_ConnectUnixDomain, 124); - - ret = init_auditd_socket(); - assert_int_equal(ret, 124); -} - - -void test_init_auditd_socket_failure(void **state) { - (void) state; - int ret; - char buffer[OS_SIZE_128] = {0}; - - expect_any(__wrap_OS_ConnectUnixDomain, path); - expect_any(__wrap_OS_ConnectUnixDomain, type); - expect_any(__wrap_OS_ConnectUnixDomain, max_msg_size); - will_return(__wrap_OS_ConnectUnixDomain, -5); - - snprintf(buffer, OS_SIZE_128, FIM_ERROR_WHODATA_SOCKET_CONNECT, AUDIT_SOCKET); - expect_string(__wrap__merror, formatted_msg, buffer); - - ret = init_auditd_socket(); - assert_int_equal(ret, -1); -} - - -void test_set_auditd_config_audit3_plugin_created(void **state) { - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - expect_abspath(AUDIT_SOCKET, 0); - - // Plugin already created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_IsSocket, sock, AUDIT_SOCKET); - will_return(__wrap_IsSocket, 0); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 0); -} - - -void test_set_auditd_config_wrong_audit_version(void **state) { - (void) state; - - // Not Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 1); - // Not Audit 2 - expect_string(__wrap_IsDir, file, "/etc/audisp/plugins.d"); - will_return(__wrap_IsDir, 1); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 0); -} - - -void test_set_auditd_config_audit2_plugin_created(void **state) { - // Not Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 1); - // Audit 2 - expect_string(__wrap_IsDir, file, "/etc/audisp/plugins.d"); - will_return(__wrap_IsDir, 0); - - expect_abspath(AUDIT_SOCKET, 0); - - // Plugin already created - const char *audit2_socket = "/etc/audisp/plugins.d/af_wazuh.conf"; - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit2_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_IsSocket, sock, AUDIT_SOCKET); - will_return(__wrap_IsSocket, 0); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 0); -} - - -void test_set_auditd_config_audit_socket_not_created(void **state) { - char buffer[OS_SIZE_128] = {0}; - syscheck.restart_audit = 0; - - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - expect_abspath(AUDIT_SOCKET, 0); - - // Plugin already created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - will_return(__wrap_OS_SHA1_File, 0); - - snprintf(buffer, OS_SIZE_128, FIM_WARN_AUDIT_SOCKET_NOEXIST, AUDIT_SOCKET); - expect_string(__wrap_IsSocket, sock, AUDIT_SOCKET); - - will_return(__wrap_IsSocket, 1); - - expect_string(__wrap__mwarn, formatted_msg, buffer); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 1); -} - - -void test_set_auditd_config_audit_socket_not_created_restart(void **state) { - char buffer[OS_SIZE_128] = {0}; - syscheck.restart_audit = 1; - - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - expect_abspath(AUDIT_SOCKET, 0); - - // Plugin already created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - will_return(__wrap_OS_SHA1_File, 0); - - snprintf(buffer, OS_SIZE_128, FIM_AUDIT_NOSOCKET, AUDIT_SOCKET); - expect_string(__wrap__minfo, formatted_msg, buffer); - expect_string(__wrap_IsSocket, sock, AUDIT_SOCKET); - will_return(__wrap_IsSocket, 1); - - will_return(__wrap_audit_restart, 99); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 99); -} - - -void test_set_auditd_config_audit_plugin_tampered_configuration(void **state) { - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "0123456789abcdef0123456789abcdef01234567"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Create plugin - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, -1); - errno = EEXIST; - - expect_string(__wrap_unlink, file, "/etc/audit/plugins.d/af_wazuh.conf"); - will_return(__wrap_unlink, 0); - - // Delete and create - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6025): Audit plugin configuration (etc/af_wazuh.conf) was modified. Restarting Auditd service."); - - // Restart - syscheck.restart_audit = 1; - will_return(__wrap_audit_restart, 99); - - int ret; - ret = set_auditd_config(); - - errno = 0; - assert_int_equal(ret, 99); -} - - -void test_set_auditd_config_audit_plugin_not_created(void **state) { - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - will_return(__wrap_OS_SHA1_File, -1); - - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Create plugin - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, 1); - - expect_string(__wrap__minfo, formatted_msg, "(6025): Audit plugin configuration (etc/af_wazuh.conf) was modified. Restarting Auditd service."); - - // Restart - syscheck.restart_audit = 1; - will_return(__wrap_audit_restart, 99); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 99); -} - - -void test_set_auditd_config_audit_plugin_not_created_fopen_error(void **state) { - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "0123456789abcdef0123456789abcdef01234567"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 0); - - expect_string(__wrap__merror, formatted_msg, "(1103): Could not open file 'etc/af_wazuh.conf' due to [(0)-(Success)]."); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, -1); -} - - -void test_set_auditd_config_audit_plugin_not_created_fclose_error(void **state) { - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "0123456789abcdef0123456789abcdef01234567"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, -1); - - expect_string(__wrap__merror, formatted_msg, "(1140): Could not close file 'etc/af_wazuh.conf' due to [(0)-(Success)]."); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, -1); -} - - -void test_set_auditd_config_audit_plugin_not_created_recreate_symlink(void **state) { - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "0123456789abcdef0123456789abcdef01234567"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Create plugin - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, -1); - errno = EEXIST; - - expect_string(__wrap_unlink, file, "/etc/audit/plugins.d/af_wazuh.conf"); - will_return(__wrap_unlink, 0); - - // Delete and create - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, 0); - - // Do not restart - syscheck.restart_audit = 0; - - expect_string(__wrap__mwarn, formatted_msg, "(6910): Audit plugin configuration was modified. You need to restart Auditd. Who-data will be disabled."); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 1); -} - - -void test_set_auditd_config_audit_plugin_not_created_recreate_symlink_restart(void **state) { - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "0123456789abcdef0123456789abcdef01234567"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Create plugin - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, -1); - errno = EEXIST; - - expect_string(__wrap_unlink, file, "/etc/audit/plugins.d/af_wazuh.conf"); - will_return(__wrap_unlink, 0); - - // Delete and create - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6025): Audit plugin configuration (etc/af_wazuh.conf) was modified. Restarting Auditd service."); - - // Restart - syscheck.restart_audit = 1; - will_return(__wrap_audit_restart, 99); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, 99); -} - - -void test_set_auditd_config_audit_plugin_not_created_recreate_symlink_error(void **state) { - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "0123456789abcdef0123456789abcdef01234567"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Create plugin - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, -1); - errno = EEXIST; - - expect_string(__wrap_unlink, file, "/etc/audit/plugins.d/af_wazuh.conf"); - will_return(__wrap_unlink, 0); - - // Delete and create - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, -1); - - expect_string(__wrap__merror, formatted_msg, "(1134): Unable to link from '/etc/audit/plugins.d/af_wazuh.conf' to 'etc/af_wazuh.conf' due to [(17)-(File exists)]."); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, -1); -} - - -void test_set_auditd_config_audit_plugin_not_created_recreate_symlink_unlink_error(void **state) { - // Audit 3 - expect_string(__wrap_IsDir, file, "/etc/audit/plugins.d"); - will_return(__wrap_IsDir, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6024): Generating Auditd socket configuration file: 'etc/af_wazuh.conf'"); - - // Plugin not created - const char *audit3_socket = "/etc/audit/plugins.d/af_wazuh.conf"; - - expect_abspath(AUDIT_SOCKET, 1); - expect_abspath(AUDIT_CONF_FILE, 1); - - expect_any(__wrap_OS_SHA1_Str, str); - expect_any(__wrap_OS_SHA1_Str, length); - will_return(__wrap_OS_SHA1_Str, "6e3a100fc85241f04ed9686d37738e7d08086fb4"); - - expect_string(__wrap_OS_SHA1_File, fname, audit3_socket); - expect_value(__wrap_OS_SHA1_File, mode, OS_TEXT); - will_return(__wrap_OS_SHA1_File, "0123456789abcdef0123456789abcdef01234567"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string(__wrap_wfopen, path, "etc/af_wazuh.conf"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fwrite, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Create plugin - expect_string(__wrap_symlink, path1, "etc/af_wazuh.conf"); - expect_string(__wrap_symlink, path2, audit3_socket); - will_return(__wrap_symlink, -1); - errno = EEXIST; - - expect_string(__wrap_unlink, file, "/etc/audit/plugins.d/af_wazuh.conf"); - will_return(__wrap_unlink, -1); - - expect_string(__wrap__merror, formatted_msg, "(1123): Unable to delete file: '/etc/audit/plugins.d/af_wazuh.conf' due to [(17)-(File exists)]."); - - int ret; - ret = set_auditd_config(); - - assert_int_equal(ret, -1); -} - - -void test_audit_get_id(void **state) { - (void) state; - - const char* event = "type=LOGIN msg=audit(1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 res=1"; - - char *ret; - ret = audit_get_id(event); - *state = ret; - - assert_string_equal(ret, "1571145421.379:659"); -} - - -void test_audit_get_id_begin_error(void **state) { - (void) state; - - const char* event = "audit1571145421.379:659): pid=16455 uid=0 old-auid=4294967295 auid=0 tty=(none) old-ses=4294967295 ses=57 res=1"; - - char *ret; - ret = audit_get_id(event); - - assert_null(ret); -} - - -void test_audit_get_id_end_error(void **state) { - (void) state; - - const char* event = "type=LOGIN msg=audit(1571145421.379:659"; - - char *ret; - ret = audit_get_id(event); - - assert_null(ret); - -} - - -void test_init_regex(void **state) { - (void) state; - int ret; - - ret = init_regex(); - - assert_int_equal(ret, 0); -} - - -void test_audit_read_events_select_error(void **state) { - (void) state; - int *audit_sock = *state; - - audit_thread_active.data = 1; - errno = EEXIST; - - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 1); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 0); - - // Switch - will_return(__wrap_select, -1); - expect_string(__wrap__merror, formatted_msg, "(1114): Error during select()-call due to [(17)-(File exists)]."); - expect_value(__wrap_sleep, seconds, 1); - - audit_read_events(audit_sock, &audit_thread_active); -} - -void test_audit_read_events_select_case_0(void **state) { - (void) state; - int *audit_sock = *state; - errno = EEXIST; - char * buffer = " \ - type=SYSCALL msg=audit(1571914029.306:3004254): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c5f8170490 a2=0 a3=7ff365c5eca0 items=2 ppid=3211 pid=44082 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"test\" exe=\"74657374C3B1\" key=\"wazuh_fim\"\n\ - type=CWD msg=audit(1571914029.306:3004254): cwd=\"/root/test\"\n\ - type=PATH msg=audit(1571914029.306:3004254): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0\n\ - type=PATH msg=audit(1571914029.306:3004254): item=1 name=\"test\" inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0\n\ - type=PROCTITLE msg=audit(1571914029.306:3004254): proctitle=726D0074657374\n"; - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 1); - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 0); - - // Switch - will_return(__wrap_select, 1); - will_return(__wrap_select, 0); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, strlen(buffer)); - will_return(__wrap_recv, buffer); - - audit_read_events(audit_sock, &audit_thread_active); -} - -void test_audit_read_events_select_success_recv_error_audit_connection_closed(void **state) { - (void) state; - int *audit_sock = *state; - audit_thread_active.data = 1; - errno = EEXIST; - int counter = 0; - int max_retries = 5; - char buffer[OS_SIZE_128] = {0}; - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - - - // Switch - will_return(__wrap_select, 1); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, 0); - expect_string(__wrap__mwarn, formatted_msg, "(6912): Audit: connection closed."); - expect_value(__wrap_sleep, seconds, 1); - expect_string(__wrap__minfo, formatted_msg, "(6029): Audit: reconnecting... (1)"); - - // init_auditd_socket failure - expect_any(__wrap_OS_ConnectUnixDomain, path); - expect_any(__wrap_OS_ConnectUnixDomain, type); - expect_any(__wrap_OS_ConnectUnixDomain, max_msg_size); - will_return(__wrap_OS_ConnectUnixDomain, -5); - snprintf(buffer, OS_SIZE_128, FIM_ERROR_WHODATA_SOCKET_CONNECT, AUDIT_SOCKET); - expect_string(__wrap__merror, formatted_msg, buffer); - - while (++counter < max_retries){ - expect_any(__wrap__minfo, formatted_msg); - expect_value(__wrap_sleep, seconds, 1); - // init_auditd_socket failure - expect_any(__wrap_OS_ConnectUnixDomain, path); - expect_any(__wrap_OS_ConnectUnixDomain, type); - expect_any(__wrap_OS_ConnectUnixDomain, max_msg_size); - will_return(__wrap_OS_ConnectUnixDomain, -5); - expect_string(__wrap__merror, formatted_msg, buffer); - } - expect_string(__wrap_SendMSG, message, "ossec: Audit: Connection closed"); - expect_string(__wrap_SendMSG, locmsg, SYSCHECK); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 1); - - audit_read_events(audit_sock, &audit_thread_active); -} - -void test_audit_read_events_select_success_recv_error_audit_reconnect(void **state) { - (void) state; - int *audit_sock = *state; - audit_thread_active.data = 1; - char buffer[OS_SIZE_128] = {0}; - errno = EEXIST; - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 0); - - // Switch - will_return(__wrap_select, 1); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, 0); - expect_string(__wrap__mwarn, formatted_msg, "(6912): Audit: connection closed."); - expect_value(__wrap_sleep, seconds, 1); - expect_string(__wrap__minfo, formatted_msg, "(6029): Audit: reconnecting... (1)"); - - // init_auditd_socket failure - expect_any(__wrap_OS_ConnectUnixDomain, path); - expect_any(__wrap_OS_ConnectUnixDomain, type); - expect_any(__wrap_OS_ConnectUnixDomain, max_msg_size); - will_return(__wrap_OS_ConnectUnixDomain, -5); - snprintf(buffer, OS_SIZE_128, FIM_ERROR_WHODATA_SOCKET_CONNECT, AUDIT_SOCKET); - expect_string(__wrap__merror, formatted_msg, buffer); - - // While (*audit_sock < 0) - // init_auditd_socket succes - expect_any(__wrap__minfo, formatted_msg); - expect_value(__wrap_sleep, seconds, 1); - expect_any(__wrap_OS_ConnectUnixDomain, path); - expect_any(__wrap_OS_ConnectUnixDomain, type); - expect_any(__wrap_OS_ConnectUnixDomain, max_msg_size); - will_return(__wrap_OS_ConnectUnixDomain, 124); - - expect_string(__wrap__minfo, formatted_msg, "(6030): Audit: connected."); - - // In audit_reload_rules() - expect_function_call(__wrap_fim_audit_reload_rules); - audit_read_events(audit_sock, &audit_thread_active); -} - -void test_audit_read_events_select_success_recv_success(void **state) { - (void) state; - int *audit_sock = *state; - audit_thread_active.data = 1; - errno = EEXIST; - char * buffer = " \ - type=SYSCALL msg=audit(1571914029.306:3004254): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c5f8170490 a2=0 a3=7ff365c5eca0 items=2 ppid=3211 pid=44082 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"test\" exe=\"74657374C3B1\" key=\"wazuh_fim\"\n\ - type=CWD msg=audit(1571914029.306:3004254): cwd=\"/root/test\"\n\ - type=PATH msg=audit(1571914029.306:3004254): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0\n\ - type=PATH msg=audit(1571914029.306:3004254): item=1 name=\"test\" inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0\n\ - type=PROCTITLE msg=audit(1571914029.306:3004254): proctitle=726D0074657374\n\ - type=EOE msg=audit(1571914029.306:3004254):\n\ - type=SYSCALL msg=audit(1571914029.306:3004255): arch=c000003e syscall=263 success=yes exit=0 a0=ffffff9c a1=55c5f8170490 a2=0 a3=7ff365c5eca0 items=2 ppid=3211 pid=44082 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts3 ses=5 comm=\"test\" exe=\"74657374C3B1\" key=\"wazuh_fim\"\n\ - type=CWD msg=audit(1571914029.306:3004255): cwd=\"/root/test\"\n\ - type=PATH msg=audit(1571914029.306:3004255): item=0 name=\"/root/test\" inode=110 dev=08:02 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0\n\ - type=PATH msg=audit(1571914029.306:3004255): item=1 name=\"test\" inode=19 dev=08:02 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=DELETE cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0\n\ - type=PROCTITLE msg=audit(1571914029.306:3004255): proctitle=726D0074657374\n\ - type=EOE msg=audit(1571914029.306:3004255):\n"; - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mwarn, formatted_msg, FIM_FULL_AUDIT_QUEUE); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 0); - // Switch - will_return(__wrap_select, 1); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, strlen(buffer)); - will_return(__wrap_recv, buffer); - - audit_read_events(audit_sock, &audit_thread_active); -} - -void test_audit_read_events_select_success_recv_success_no_endline(void **state) { - (void) state; - int *audit_sock = *state; - audit_thread_active.data = 1; - errno = EEXIST; - char * buffer = " \ - type=SYSCALL msg=audit(1571914029.306:3004254): arch=c000003e syscall=263 success=yes exit\ - "; - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 0); - - // Switch - will_return(__wrap_select, 1); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, strlen(buffer)); - will_return(__wrap_recv, buffer); - - audit_read_events(audit_sock, &audit_thread_active); -} - -void test_audit_read_events_select_success_recv_success_no_id(void **state) { - (void) state; - int *audit_sock = *state; - audit_thread_active.data = 1; - errno = EEXIST; - char * buffer = " \ - type=SYSC arch=c000003e syscall=263 success=yes exit\n\ - "; - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 0); - - // Switch - will_return(__wrap_select, 1); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, strlen(buffer)); - will_return(__wrap_recv, buffer); - - expect_string(__wrap__mwarn, formatted_msg, "(6928): Couldn't get event ID from Audit message. Line: ' type=SYSC arch=c000003e syscall=263 success=yes exit'."); - - audit_read_events(audit_sock, &audit_thread_active); -} - -void test_audit_read_events_select_success_recv_success_too_long(void **state) { - (void) state; - int *audit_sock = *state; - audit_thread_active.data = 1; - errno = EEXIST; - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - expect_value_count(__wrap_atomic_int_get, atomic, &audit_thread_active, 2); - will_return_count(__wrap_atomic_int_get, 1, 2); - - expect_value(__wrap_atomic_int_get, atomic, &audit_thread_active); - will_return(__wrap_atomic_int_get, 0); - // Event too long, 65535 char - char * buffer = malloc(65530 * sizeof(char)); - char * extra_buffer = "aaaaaaaaaa"; - strcpy (buffer,"type=SYSCALLmsg=audit(1571914029.306:3004254):"); - for (int i = 0; i < 6548; i++) { - strcat (buffer, extra_buffer); - } - strcat (buffer,"\n"); - - // Switch - will_return(__wrap_select, 1); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, strlen(buffer)); - will_return(__wrap_recv, buffer); - - - char * buffer2 = "type=SYSCALLmsg=audit(1571914029.306:3004254):aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"; - - will_return(__wrap_select, 1); - - // If (!byteRead) - expect_value(__wrap_recv, __fd, *audit_sock); - will_return(__wrap_recv, strlen(buffer2)); - will_return(__wrap_recv, buffer2); - - expect_string(__wrap__mwarn, formatted_msg, "(6929): Caching Audit message: event too long. Event with ID: '1571914029.306:3004254' will be discarded."); - - audit_read_events(audit_sock, &audit_thread_active); - - os_free(buffer); -} - -void test_audit_parse_thread(void **state) { - audit_parse_thread_active.data = 1; - - expect_value(__wrap_atomic_int_get, atomic, &audit_parse_thread_active); - will_return(__wrap_atomic_int_get, 1); - - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_function_call(__wrap_audit_parse); - - expect_value(__wrap_atomic_int_get, atomic, &audit_parse_thread_active); - will_return(__wrap_atomic_int_get, 0); - - audit_parse_thread(); -} - -void test_audit_rules_to_realtime(void **state) { - char error_msg[OS_SIZE_128]; - char error_msg2[OS_SIZE_128]; - - // Mutex - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - will_return(__wrap_audit_open, 1); - will_return(__wrap_audit_get_rule_list, 1); - will_return(__wrap_audit_close, 1); - - will_return_count(__wrap_search_audit_rule, 0, 4); - - snprintf(error_msg, OS_SIZE_128, FIM_ERROR_WHODATA_ADD_DIRECTORY, "/test0"); - expect_string(__wrap__mwarn, formatted_msg, error_msg); - snprintf(error_msg2, OS_SIZE_128, FIM_ERROR_WHODATA_ADD_DIRECTORY, "/test1"); - expect_string(__wrap__mwarn, formatted_msg, error_msg2); - - audit_rules_to_realtime(); - - // Check that the options have been correctly changed - if (((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->options & WHODATA_ACTIVE) { - fail(); - } - - if (((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))->options & WHODATA_ACTIVE) { - fail(); - } -} - -void test_audit_rules_to_realtime_first_search_audit_rule_fail(void **state) { - char error_msg[OS_SIZE_128]; - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - will_return(__wrap_audit_open, 1); - will_return(__wrap_audit_get_rule_list, 1); - will_return(__wrap_audit_close, 1); - - will_return(__wrap_search_audit_rule, 1); - will_return_count(__wrap_search_audit_rule, 0, 2); - - snprintf(error_msg, OS_SIZE_128, FIM_ERROR_WHODATA_ADD_DIRECTORY, "/test1"); - expect_string(__wrap__mwarn, formatted_msg, error_msg); - - audit_rules_to_realtime(); - - // Check that the options have been correctly changed - if (((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->options & ~WHODATA_ACTIVE) { - fail(); - } - - if (((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))->options & WHODATA_ACTIVE) { - fail(); - } -} - -void test_audit_rules_to_realtime_second_search_audit_rule_fail(void **state) { - char error_msg[OS_SIZE_128]; - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - will_return(__wrap_audit_open, 1); - will_return(__wrap_audit_get_rule_list, 1); - will_return(__wrap_audit_close, 1); - - will_return_count(__wrap_search_audit_rule, 0, 2); - will_return(__wrap_search_audit_rule, 1); - - snprintf(error_msg, OS_SIZE_128, FIM_ERROR_WHODATA_ADD_DIRECTORY, "/test0"); - expect_string(__wrap__mwarn, formatted_msg, error_msg); - - audit_rules_to_realtime(); - - // Check that the options have been correctly changed - if (((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->options & WHODATA_ACTIVE) { - fail(); - } - - if (((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 1))->options & ~WHODATA_ACTIVE) { - fail(); - } -} - -void test_audit_create_rules_file(void **state) { - expect_string(__wrap_wfopen, path, AUDIT_RULES_FILE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test0' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test0 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test1' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test1 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 0); - - expect_abspath(AUDIT_RULES_FILE, 0); - - expect_string(__wrap_symlink, path1, AUDIT_RULES_FILE); - expect_string(__wrap_symlink, path2, AUDIT_RULES_LINK); - will_return(__wrap_symlink, 1); - - expect_string(__wrap__minfo, formatted_msg, "(6045): Created audit rules file, due to audit immutable mode rules will be loaded in the next reboot."); - - audit_create_rules_file(); -} - -void test_audit_create_rules_file_fopen_fail(void **state) { - char error_msg[OS_SIZE_128]; - - expect_string(__wrap_wfopen, path, AUDIT_RULES_FILE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 0); - - snprintf(error_msg, OS_SIZE_128, FOPEN_ERROR, AUDIT_RULES_FILE, errno, strerror(errno)); - expect_string(__wrap__merror, formatted_msg, error_msg); - - audit_create_rules_file(); -} - -void test_audit_create_rules_file_fclose_fail(void **state) { - char error_msg[OS_SIZE_128]; - - expect_string(__wrap_wfopen, path, AUDIT_RULES_FILE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test0' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test0 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test1' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test1 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 1); - - snprintf(error_msg, OS_SIZE_128, FCLOSE_ERROR, AUDIT_RULES_FILE, errno, strerror(errno)); - expect_string(__wrap__merror, formatted_msg, error_msg); - - audit_create_rules_file(); -} - -void test_audit_create_rules_file_symlink_exist(void **state) { - expect_string(__wrap_wfopen, path, AUDIT_RULES_FILE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test0' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test0 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test1' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test1 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 0); - - expect_abspath(AUDIT_RULES_FILE, 0); - - expect_string(__wrap_symlink, path1, AUDIT_RULES_FILE); - expect_string(__wrap_symlink, path2, AUDIT_RULES_LINK); - will_return(__wrap_symlink, -1); - - errno = EEXIST; - - expect_string(__wrap_unlink, file, AUDIT_RULES_LINK); - will_return(__wrap_unlink, 0); - - expect_string(__wrap_symlink, path1, AUDIT_RULES_FILE); - expect_string(__wrap_symlink, path2, AUDIT_RULES_LINK); - will_return(__wrap_symlink, 0); - - expect_string(__wrap__minfo, formatted_msg, "(6045): Created audit rules file, due to audit immutable mode rules will be loaded in the next reboot."); - - audit_create_rules_file(); -} - -void test_audit_create_rules_file_unlink_fail(void **state) { - char error_msg[OS_SIZE_128]; - - expect_string(__wrap_wfopen, path, AUDIT_RULES_FILE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test0' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test0 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test1' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test1 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 0); - - expect_abspath(AUDIT_RULES_FILE, 0); - - expect_string(__wrap_symlink, path1, AUDIT_RULES_FILE); - expect_string(__wrap_symlink, path2, AUDIT_RULES_LINK); - will_return(__wrap_symlink, -1); - - errno = EEXIST; - - expect_string(__wrap_unlink, file, AUDIT_RULES_LINK); - will_return(__wrap_unlink, -1); - - snprintf(error_msg, OS_SIZE_128, UNLINK_ERROR, AUDIT_RULES_LINK, errno, strerror(errno)); - expect_string(__wrap__merror, formatted_msg, error_msg); - - audit_create_rules_file(); -} - -void test_audit_create_rules_file_symlink_fail(void **state) { - char error_msg[OS_SIZE_256]; - - expect_string(__wrap_wfopen, path, AUDIT_RULES_FILE); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 1); - - // Mutex inside get_real_path - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test0' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test0 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6365): Added directory '/test1' to audit rules file."); - - expect_any(__wrap_fprintf, __stream); - expect_string(__wrap_fprintf, formatted_msg, "-w /test1 -p wa -k wazuh_fim\n"); - will_return(__wrap_fprintf, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 0); - - expect_abspath(AUDIT_RULES_FILE, 0); - - expect_string(__wrap_symlink, path1, AUDIT_RULES_FILE); - expect_string(__wrap_symlink, path2, AUDIT_RULES_LINK); - will_return(__wrap_symlink, -1); - - errno = 1; - - snprintf(error_msg, OS_SIZE_256, LINK_ERROR, AUDIT_RULES_LINK, AUDIT_RULES_FILE, errno, strerror(errno)); - expect_string(__wrap__merror, formatted_msg, error_msg); - - audit_create_rules_file(); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_check_auditd_enabled_success), - cmocka_unit_test(test_check_auditd_enabled_openproc_error), - cmocka_unit_test(test_check_auditd_enabled_readproc_error), - cmocka_unit_test(test_init_auditd_socket_success), - cmocka_unit_test(test_init_auditd_socket_failure), - cmocka_unit_test(test_set_auditd_config_wrong_audit_version), - cmocka_unit_test(test_set_auditd_config_audit2_plugin_created), - cmocka_unit_test(test_set_auditd_config_audit3_plugin_created), - cmocka_unit_test(test_set_auditd_config_audit_socket_not_created), - cmocka_unit_test(test_set_auditd_config_audit_socket_not_created_restart), - cmocka_unit_test(test_set_auditd_config_audit_plugin_tampered_configuration), - cmocka_unit_test(test_set_auditd_config_audit_plugin_not_created), - cmocka_unit_test(test_set_auditd_config_audit_plugin_not_created_fopen_error), - cmocka_unit_test(test_set_auditd_config_audit_plugin_not_created_fclose_error), - cmocka_unit_test(test_set_auditd_config_audit_plugin_not_created_recreate_symlink), - cmocka_unit_test(test_set_auditd_config_audit_plugin_not_created_recreate_symlink_restart), - cmocka_unit_test(test_set_auditd_config_audit_plugin_not_created_recreate_symlink_error), - cmocka_unit_test(test_set_auditd_config_audit_plugin_not_created_recreate_symlink_unlink_error), - cmocka_unit_test_teardown(test_audit_get_id, free_string), - cmocka_unit_test(test_audit_get_id_begin_error), - cmocka_unit_test(test_audit_get_id_end_error), - cmocka_unit_test(test_init_regex), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_error, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_case_0, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_success_recv_error_audit_connection_closed, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_success_recv_error_audit_reconnect, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_success_recv_success, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_success_recv_success_no_endline, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_success_recv_success_no_id, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test_setup_teardown(test_audit_read_events_select_success_recv_success_too_long, test_audit_read_events_setup, test_audit_read_events_teardown), - cmocka_unit_test(test_audit_parse_thread), - cmocka_unit_test_setup_teardown(test_audit_rules_to_realtime, setup_syscheck_dir_links, teardown_rules_to_realtime), - cmocka_unit_test_setup_teardown(test_audit_rules_to_realtime_first_search_audit_rule_fail, setup_syscheck_dir_links, teardown_rules_to_realtime), - cmocka_unit_test_setup_teardown(test_audit_rules_to_realtime_second_search_audit_rule_fail, setup_syscheck_dir_links, teardown_rules_to_realtime), - cmocka_unit_test_setup_teardown(test_audit_create_rules_file, setup_syscheck_dir_links, teardown_syscheck_dir_links), - cmocka_unit_test_setup_teardown(test_audit_create_rules_file_fopen_fail, setup_syscheck_dir_links, teardown_syscheck_dir_links), - cmocka_unit_test_setup_teardown(test_audit_create_rules_file_fclose_fail, setup_syscheck_dir_links, teardown_syscheck_dir_links), - cmocka_unit_test_setup_teardown(test_audit_create_rules_file_symlink_exist, setup_syscheck_dir_links, teardown_syscheck_dir_links), - cmocka_unit_test_setup_teardown(test_audit_create_rules_file_unlink_fail, setup_syscheck_dir_links, teardown_syscheck_dir_links), - cmocka_unit_test_setup_teardown(test_audit_create_rules_file_symlink_fail, setup_syscheck_dir_links, teardown_syscheck_dir_links), - }; - - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/syscheckd/whodata/test_win_whodata.c b/src/unit_tests/syscheckd/whodata/test_win_whodata.c deleted file mode 100644 index 8bd807441e5..00000000000 --- a/src/unit_tests/syscheckd/whodata/test_win_whodata.c +++ /dev/null @@ -1,8359 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "wrappers/common.h" -#include "wrappers/libc/stdio_wrappers.h" -#include "wrappers/libc/stdlib_wrappers.h" -#include "wrappers/wazuh/shared/debug_op_wrappers.h" -#include "wrappers/wazuh/shared/file_op_wrappers.h" -#include "wrappers/wazuh/shared/fs_op_wrappers.h" -#include "wrappers/wazuh/shared/hash_op_wrappers.h" -#include "wrappers/wazuh/shared/mq_op_wrappers.h" -#include "wrappers/wazuh/shared/string_op_wrappers.h" -#include "wrappers/wazuh/shared/randombytes_wrappers.h" -#include "wrappers/wazuh/syscheckd/config_wrappers.h" -#include "wrappers/wazuh/syscheckd/create_db_wrappers.h" -#include "wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" -#include "wrappers/wazuh/shared/validate_op_wrappers.h" -#include "wrappers/windows/winevt_wrappers.h" -#include "wrappers/windows/ntsecapi_wrappers.h" - - -#include "../../../syscheckd/include/syscheck.h" - -int set_winsacl(const char *dir, directory_t *configuration); -extern int set_privilege(HANDLE hdle, LPCTSTR privilege, int enable); -extern int w_update_sacl(const char *obj_path); -extern char *get_whodata_path(const short unsigned int *win_path); -extern int whodata_path_filter(char **path); -extern int whodata_check_arch(); -extern int is_valid_sacl(PACL sacl, int is_file); -extern void replace_device_path(char **path); -extern int get_drive_names(wchar_t *volume_name, char *device); -extern int get_volume_names(); -extern void notify_SACL_change(char *dir); -extern int whodata_hash_add(OSHash *table, char *id, void *data, char *tag); -extern void restore_sacls(); -extern int restore_audit_policies(); -extern void audit_restore(); -extern int check_object_sacl(char *obj, int is_file); -extern void set_subscription_query(wchar_t *query); -extern int set_policies(); -extern void whodata_list_set_values(); -extern void whodata_list_remove_multiple(size_t quantity); -unsigned long WINAPI whodata_callback(EVT_SUBSCRIBE_NOTIFY_ACTION action, __attribute__((unused)) void *_void, EVT_HANDLE event); -extern int whodata_audit_start(); -extern PEVT_VARIANT whodata_event_render(EVT_HANDLE event); -extern int whodata_get_event_id(const PEVT_VARIANT raw_data, short *event_id); -extern int whodata_get_handle_id(const PEVT_VARIANT raw_data, unsigned __int64 *handle_id); -extern int whodata_get_access_mask(const PEVT_VARIANT raw_data, unsigned long *mask); -extern int whodata_event_parse(const PEVT_VARIANT raw_data, whodata_evt *event_data); -int policy_check(); -void win_whodata_release_resources(whodata *wdata); - -extern char sys_64; -extern PSID everyone_sid; -extern size_t ev_sid_size; -extern int restore_policies; -extern int policies_checked; -extern EVT_HANDLE context; -extern atomic_int_t whodata_end; - -extern const wchar_t* event_fields[]; - -const int NUM_EVENTS = 10; -int SIZE_EVENTS; - -const PWCHAR WCS_TEST_PATH = L"C:\\Windows\\a\\path"; -const char *STR_TEST_PATH = "c:\\windows\\a\\path"; - -static const char *guid_ObjectAccess = "{6997984A-797A-11D9-BED3-505054503030}"; -static const char *guid_FileSystem = "{0CCE921D-69AE-11D9-BED3-505054503030}"; -static const char *guid_Handle = "{0CCE9223-69AE-11D9-BED3-505054503030}"; - -typedef struct PolicyInfo { - GUID *category_guid; - GUID *subcategory_guid1; - GUID *subcategory_guid2; - PPOLICY_AUDIT_EVENTS_INFO audit_event_info; - AUDIT_POLICY_INFORMATION *paudit_policy; -} policy_info; - -/**************************************************************************/ -/*******************Helper functions*************************************/ -static void successful_whodata_event_render(EVT_HANDLE event, PEVT_VARIANT raw_data) { - /* EvtRender first call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, 0); // BufferSize - will_return(wrap_EvtRender, NULL); // Buffer - will_return(wrap_EvtRender, SIZE_EVENTS); // BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 0); - - /* EvtRender second call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, SIZE_EVENTS); // BufferSize - will_return(wrap_EvtRender, raw_data); // Buffer - will_return(wrap_EvtRender, SIZE_EVENTS); // BufferUsed - will_return(wrap_EvtRender, 9); // PropertyCount - will_return(wrap_EvtRender, 1); -} - -void expect_policy_check_match_call(NTSTATUS status1, - PPOLICY_AUDIT_EVENTS_INFO audit_event_info, NTSTATUS status2, - GUID *category_guid, BOOLEAN ret1, - ULONG subcategory_count, BOOLEAN ret2, - AUDIT_POLICY_INFORMATION *paudit_policy, BOOLEAN ret3) { - - will_return(wrap_LsaOpenPolicy, status1); - - if (status1 == (NTSTATUS)0){ - will_return(wrap_LsaQueryInformationPolicy, audit_event_info); - will_return(wrap_LsaQueryInformationPolicy, status2); - - if (status2 == (NTSTATUS)0){ - will_return(wrap_AuditLookupCategoryGuidFromCategoryId, category_guid); - will_return(wrap_AuditLookupCategoryGuidFromCategoryId, ret1); - - if (ret1 == true){ - will_return(wrap_AuditEnumerateSubCategories, subcategory_count); - will_return(wrap_AuditEnumerateSubCategories, ret2); - - if (ret2 == true){ - will_return(wrap_AuditQuerySystemPolicy, paudit_policy); - will_return(wrap_AuditQuerySystemPolicy, ret3); - - if (ret3 == true){ - return; - } - } - } - } - } - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - will_return(wrap_FormatMessage, "Access is denied"); - expect_string(__wrap__mwarn, formatted_msg, "(6951): Unable to check the necessary policies for whodata: Access is denied (5)."); -} - -/**************************************************************************/ -/*************************WRAPS - FIXTURES*********************************/ -int syscheck_teardown(void ** state) { - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - // Free wdata - if (syscheck.wdata.fd) { - OSHash_Free(syscheck.wdata.fd); - } - - if (syscheck.wdata.directories) { - OSHash_Free(syscheck.wdata.directories); - } - - if (syscheck.wdata.drive) { - free_strarray(syscheck.wdata.drive); - } - - if (syscheck.wdata.device) { - free_strarray(syscheck.wdata.device); - } - - syscheck.wdata.fd = NULL; - syscheck.wdata.directories = NULL; - syscheck.wdata.drive = NULL; - syscheck.wdata.device = NULL; - - // Free everything else in syscheck - Free_Syscheck(&syscheck); - - syscheck.scan_day = NULL; - syscheck.scan_time = NULL; - syscheck.ignore = NULL; - syscheck.ignore_regex = NULL; - syscheck.nodiff = NULL; - syscheck.nodiff_regex = NULL; - syscheck.directories = NULL; - syscheck.key_ignore = NULL; - syscheck.key_ignore_regex = NULL; - syscheck.registry = NULL; - syscheck.realtime = NULL; - syscheck.prefilter_cmd = NULL; - syscheck.audit_key = NULL; - - return 0; -} - -int test_group_setup(void **state) { - int ret; - expect_string(__wrap__mdebug1, formatted_msg, "(6287): Reading configuration file: '../test_syscheck.conf'"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex node .log$|.htm$|.jpg$|.png$|.chm$|.pnf$|.evtx$|.swp$"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex node .log$|.htm$|.jpg$|.png$|.chm$|.pnf$|.evtx$|.swp$ OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found ignore regex size 0"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node ^file"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node ^file OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex size 0"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node test_$"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex node test_$ OK?"); - expect_string(__wrap__mdebug1, formatted_msg, "Found nodiff regex size 1"); - expect_string(__wrap__mdebug1, formatted_msg, "(6208): Reading Client Configuration [../test_syscheck.conf]"); - will_return_always(__wrap_getDefine_Int, 0); - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - - test_mode = 0; - ret = Read_Syscheck_Config("../test_syscheck.conf"); - - SIZE_EVENTS = sizeof(EVT_VARIANT) * NUM_EVENTS; - test_mode = 1; - return ret; -} - -static int test_group_teardown(void **state) { - test_mode = 0; - - if (syscheck_teardown(state) != 0) - return -1; - - return 0; -} - -OSHash * __real_OSHash_Create(); -int __real_OSHash_SetFreeDataPointer(OSHash * self, void(free_data_function)(void *)); -static int setup_whodata_callback_group(void ** state) { -#ifdef TEST_WINAGENT - will_return_count(__wrap_os_random, 12345, 2); -#endif - if (syscheck.wdata.directories = __real_OSHash_Create(), !syscheck.wdata.directories) { - return -1; - } - - __real_OSHash_SetFreeDataPointer(syscheck.wdata.directories, free); - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - syscheck.directories = OSList_Create(); - if (syscheck.directories == NULL) { - return -1; - } - - int options = CHECK_SIZE | CHECK_PERM | CHECK_OWNER | CHECK_GROUP | CHECK_MTIME | CHECK_INODE | - CHECK_MD5SUM | CHECK_SHA1SUM | CHECK_SHA256SUM | CHECK_ATTRS | WHODATA_ACTIVE; - directory_t *directory0 = fim_create_directory("c:\\windows", options, NULL, 50, NULL, -1, 0); - directory0->dirs_status.status = WD_CHECK_WHODATA; - - OSList_InsertData(syscheck.directories, NULL, directory0); - - OSHash_Add_ex_check_data = 0; - SIZE_EVENTS = sizeof(EVT_VARIANT) * NUM_EVENTS; - test_mode = 1; - return 0; -} - -static int teardown_whodata_callback_group(void ** state) { - if (test_group_teardown(state)) - return -1; - - OSHash_Add_ex_check_data = 1; - return 0; -} - -static int setup_policy_check(void ** state) { - policy_info *pol_data = NULL; - os_calloc(1, sizeof(policy_info), pol_data); - - AUDIT_POLICY_INFORMATION *audit_pol_array; - os_calloc(2, sizeof(AUDIT_POLICY_INFORMATION), audit_pol_array); - AUDIT_POLICY_INFORMATION file_system_policy; - AUDIT_POLICY_INFORMATION handle_policy; - - PPOLICY_AUDIT_EVENTS_INFO AuditEvents; - os_calloc(1, sizeof(PPOLICY_AUDIT_EVENTS_INFO), AuditEvents); - - AuditEvents->AuditingMode = true; - AuditEvents->MaximumAuditEventCount = 1; - - GUID *guid_ObjectAccess; - os_calloc(1, sizeof(GUID), guid_ObjectAccess); - GUID *guid_FileSystem; - os_calloc(1, sizeof(GUID), guid_FileSystem); - GUID *guid_Handle; - os_calloc(1, sizeof(GUID), guid_Handle); - - CLSIDFromString(OLESTR("{6997984a-797a-11d9-bed3-505054503030}"), guid_ObjectAccess); - CLSIDFromString(OLESTR("{0CCE921D-69AE-11D9-BED3-505054503030}"), guid_FileSystem); - CLSIDFromString(OLESTR("{0CCE9223-69AE-11D9-BED3-505054503030}"), guid_Handle); - - file_system_policy.AuditSubCategoryGuid = *guid_FileSystem; - file_system_policy.AuditingInformation = POLICY_AUDIT_EVENT_SUCCESS; - handle_policy.AuditSubCategoryGuid = *guid_Handle; - handle_policy.AuditingInformation = POLICY_AUDIT_EVENT_SUCCESS; - - audit_pol_array[0] = file_system_policy; - audit_pol_array[1] = handle_policy; - - pol_data->category_guid = guid_ObjectAccess; - pol_data->audit_event_info = AuditEvents; - pol_data->paudit_policy = audit_pol_array; - pol_data->subcategory_guid1 = guid_FileSystem; - pol_data->subcategory_guid2 = guid_Handle; - - *state = pol_data; - - return 0; -} - -static int teardown_policy_check(void ** state) { - policy_info *pol_data = *state; - - os_free(pol_data->category_guid); - os_free(pol_data->subcategory_guid1); - os_free(pol_data->subcategory_guid2); - os_free(pol_data->audit_event_info); - os_free(pol_data->paudit_policy); - - os_free(pol_data); - - return 0; -} - -static int setup_wdata_dirs_cleanup(void ** state) { -#ifdef TEST_WINAGENT - will_return_count(__wrap_os_random, 12345, 2); -#endif - if (syscheck.wdata.directories = __real_OSHash_Create(), !syscheck.wdata.directories) { - return -1; - } - - __real_OSHash_SetFreeDataPointer(syscheck.wdata.directories, free); - - syscheck.directories = OSList_Create(); - if (syscheck.directories == NULL) { - return -1; - } - - if (setup_policy_check(state) != 0) - return -1; - - test_mode = 1; - - return 0; -} - -static int teardown_memblock(void **state) { - if(*state) - free(*state); - - return 0; -} - -static int teardown_wdata_device() { - free_strarray(syscheck.wdata.device); - free_strarray(syscheck.wdata.drive); - - syscheck.wdata.device = NULL; - syscheck.wdata.drive = NULL; - - return 0; -} - -static int setup_replace_device_path(void **state) { - syscheck.wdata.device = calloc(10, sizeof(char*)); - syscheck.wdata.drive = calloc(10, sizeof(char *)); - - if(syscheck.wdata.device == NULL || syscheck.wdata.drive == NULL) - return -1; - - return 0; -} - -static int teardown_replace_device_path(void **state) { - if(teardown_wdata_device(state)) - return -1; - - if(teardown_memblock(state)) - return -1; - - return 0; -} - -static int teardown_reset_errno(void **state) { - errno = 0; - return 0; -} - -static int setup_state_checker(void ** state) { - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - syscheck.directories = OSList_Create(); - if (!syscheck.directories) { - return -1; - } - - directory_t *directory0 = fim_create_directory("c:\\a\\path", WHODATA_ACTIVE, NULL, 50, NULL, -1, 0); - directory0->dirs_status.status = WD_CHECK_WHODATA; - directory0->dirs_status.object_type = WD_STATUS_DIR_TYPE; - directory0->dirs_status.status = WD_CHECK_WHODATA | WD_STATUS_EXISTS; - - OSList_InsertData(syscheck.directories, NULL, directory0); - -#ifdef TEST_WINAGENT - will_return_count(__wrap_os_random, 12345, 2); -#endif - - if (syscheck.wdata.directories = __real_OSHash_Create(), !syscheck.wdata.directories) { - return -1; - } - - __real_OSHash_SetFreeDataPointer(syscheck.wdata.directories, free); - - if (setup_policy_check(state) != 0) - return -1; - - test_mode = 1; - - return 0; -} - -static int teardown_state_checker(void ** state) { - test_mode = 0; - - if (teardown_policy_check(state) != 0) - return -1; - - if (syscheck_teardown(state) != 0) - return -1; - - return 0; -} - -static int teardown_whodata_audit_start(void ** state) { - syscheck.wdata.directories = NULL; - syscheck.wdata.fd = NULL; - - return 0; -} - -static int setup_win_whodata_evt(void **state) { - whodata_evt *w_evt = calloc(1, sizeof(whodata_evt)); - - if(!w_evt) - return -1; - - *state = w_evt; - - return 0; -} - -static int teardown_win_whodata_evt(void **state) { - whodata_evt *w_evt = *state; - - free_whodata_event(w_evt); - - return 0; -} - -static int teardown_whodata_callback_restore_globals(void ** state) { - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - directory_t *directory0 = ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0)); - directory0->dirs_status.status |= WD_CHECK_WHODATA; - directory0->recursion_level = 50; - return 0; -} - -static int teardown_state_checker_restore_globals(void ** state) { - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - OSList_CleanNodes(syscheck.directories); - directory_t *directory0 = fim_create_directory("c:\\a\\path", WHODATA_ACTIVE, NULL, 50, NULL, -1, 0); - - directory0->dirs_status.object_type = WD_STATUS_DIR_TYPE; - directory0->dirs_status.status = WD_CHECK_WHODATA | WD_STATUS_EXISTS; - - OSList_InsertData(syscheck.directories, NULL, directory0); - - return 0; -} - -static int teardown_clean_directories_hash(void ** state) { - // Destroy and recreate the hash table for future tests - OSHash_Free(syscheck.wdata.directories); - -#ifdef TEST_WINAGENT - will_return_count(__wrap_os_random, 12345, 2); -#endif - - if (syscheck.wdata.directories = __real_OSHash_Create(), !syscheck.wdata.directories) { - return -1; - } - - __real_OSHash_SetFreeDataPointer(syscheck.wdata.directories, free); - - return 0; -} - -/**************************************************************************/ -/***************************set_winsacl************************************/ -void test_set_winsacl_failed_opening(void **state) { - char debug_msg[OS_MAXSTR]; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg, OS_MAXSTR, FIM_SACL_CONFIGURE, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 0); - - will_return(wrap_GetLastError, (unsigned int) 500); - expect_string(__wrap__merror, formatted_msg, "(6648): OpenProcessToken() failed. Error '500'."); - - set_winsacl(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); -} - -void test_set_winsacl_failed_privileges(void **state) { - char debug_msg[OS_MAXSTR]; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg, OS_MAXSTR, FIM_SACL_CONFIGURE, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_LookupPrivilegeValue, 0); // Fail lookup privilege - - will_return(wrap_GetLastError, (unsigned int) 500); - expect_string(__wrap__merror, formatted_msg, "(6647): Could not find the 'SeSecurityPrivilege' privilege. Error: 500"); - - will_return(wrap_GetLastError, (unsigned int) 501); - expect_string(__wrap__merror, formatted_msg, "(6659): The privilege could not be activated. Error: '501'."); - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - set_winsacl(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); -} - -void test_set_winsacl_failed_security_descriptor(void **state) { - char debug_msg[OS_MAXSTR]; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg, OS_MAXSTR, FIM_SACL_CONFIGURE, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_LookupPrivilegeValue, 1); - - // Increase privileges - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, -1); - expect_string(__wrap__merror, formatted_msg, "(6650): GetNamedSecurityInfo() failed. Error '-1'"); - - // Reduce Privilege - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - set_winsacl(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); -} - -void test_set_winsacl_no_need_to_configure_acl(void **state) { - ACL old_sacl; - ACCESS_ALLOWED_ACE ace; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - everyone_sid = NULL; - ev_sid_size = 1; - - // Set the ACL and ACE data - ace.Header.AceFlags = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG; - ace.Mask = FILE_WRITE_DATA | FILE_APPEND_DATA | WRITE_DAC | FILE_WRITE_ATTRIBUTES | DELETE; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &ace); - will_return(wrap_GetAce, 1); - - will_return(wrap_EqualSid, 1); - } - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 0); -} - -void test_set_winsacl_unable_to_get_acl_info(void **state) { - ACL old_sacl; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 0); - - expect_string(__wrap__merror, formatted_msg, "(6651): The size of the 'C:\\a\\path' SACL could not be obtained."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_set_winsacl_fail_to_alloc_new_sacl(void **state) { - ACL old_sacl; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, NULL); - - expect_string(__wrap__merror, formatted_msg, "(6652): No memory could be reserved for the new SACL of 'C:\\a\\path'."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_set_winsacl_fail_to_initialize_new_sacl(void **state) { - ACL old_sacl; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 0); - - expect_string(__wrap__merror, formatted_msg, "(6653): The new SACL for 'C:\\a\\path' could not be created."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_set_winsacl_fail_getting_ace_from_old_sacl(void **state) { - ACL old_sacl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, NULL); - will_return(wrap_GetAce, 0); - - expect_string(__wrap__merror, formatted_msg, "(6654): The ACE number 0 for 'C:\\a\\path' could not be obtained."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_set_winsacl_fail_adding_old_ace_into_new_sacl(void **state) { - ACL old_sacl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 0); - - expect_string(__wrap__merror, formatted_msg, - "(6655): The ACE number 0 of 'C:\\a\\path' could not be copied to the new ACL."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} -void test_set_winsacl_fail_to_alloc_new_ace(void **state) { - ACL old_sacl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, NULL); - - expect_string(__wrap__merror, formatted_msg, - "(6656): No memory could be reserved for the new ACE of 'C:\\a\\path'."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); -} - -void test_set_winsacl_fail_to_copy_sid(void **state) { - ACL old_sacl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SYSTEM_AUDIT_ACE ace; - - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 0); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); - assert_int_equal(ace.Header.AceType, SYSTEM_AUDIT_ACE_TYPE); - assert_int_equal(ace.Header.AceFlags, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG); - assert_int_equal(ace.Header.AceSize, 9); - assert_int_equal(ace.Mask, DELETE | FILE_WRITE_DATA | FILE_APPEND_DATA | WRITE_DAC | FILE_WRITE_ATTRIBUTES); -} - -void test_set_winsacl_fail_to_add_ace(void **state) { - ACL old_sacl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SYSTEM_AUDIT_ACE ace; - - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 0); - - expect_string(__wrap__merror, formatted_msg, "(6657): The new ACE could not be added to 'C:\\a\\path'."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); - assert_int_equal(ace.Header.AceType, SYSTEM_AUDIT_ACE_TYPE); - assert_int_equal(ace.Header.AceFlags, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG); - assert_int_equal(ace.Header.AceSize, 9); - assert_int_equal(ace.Mask, DELETE | FILE_WRITE_DATA | FILE_APPEND_DATA | WRITE_DAC | FILE_WRITE_ATTRIBUTES); -} - -void test_set_winsacl_fail_to_set_security_info(void **state) { - ACL old_sacl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SYSTEM_AUDIT_ACE ace; - - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, 1234); - will_return(wrap_SetNamedSecurityInfo, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6658): SetNamedSecurityInfo() failed. Error: '5'."); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 1); - assert_int_equal(ace.Header.AceType, SYSTEM_AUDIT_ACE_TYPE); - assert_int_equal(ace.Header.AceFlags, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG); - assert_int_equal(ace.Header.AceSize, 9); - assert_int_equal(ace.Mask, DELETE | FILE_WRITE_DATA | FILE_APPEND_DATA | WRITE_DAC | FILE_WRITE_ATTRIBUTES); -} - -void test_set_winsacl_success(void **state) { - ACL old_sacl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SYSTEM_AUDIT_ACE ace; - - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - int ret; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'C:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_sacl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &old_sacl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'C:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, 1234); - will_return(wrap_SetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = set_winsacl("C:\\a\\path", ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))); - - assert_int_equal(ret, 0); - assert_int_equal(ace.Header.AceType, SYSTEM_AUDIT_ACE_TYPE); - assert_int_equal(ace.Header.AceFlags, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG); - assert_int_equal(ace.Header.AceSize, 9); - assert_int_equal(ace.Mask, DELETE | FILE_WRITE_DATA | FILE_APPEND_DATA | WRITE_DAC | FILE_WRITE_ATTRIBUTES); -} - -/**************************************************************************/ - -void test_set_privilege_lookup_error (void **state) { - int ret; - - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_LookupPrivilegeValue, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6647): Could not find the 'SeSecurityPrivilege' privilege. Error: 5"); - - ret = set_privilege((HANDLE)123456, "SeSecurityPrivilege", 0); - - assert_int_equal(ret, 1); -} - -void test_set_privilege_adjust_token_error (void **state) { - int ret; - - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6634): AdjustTokenPrivileges() failed. Error: '5'"); - - ret = set_privilege((HANDLE)123456, "SeSecurityPrivilege", 0); - - assert_int_equal(ret, 1); -} - -void test_set_privilege_elevate_privilege (void **state) { - int ret; - - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - - ret = set_privilege((HANDLE)123456, "SeSecurityPrivilege", 1); - - assert_int_equal(ret, 0); -} - -void test_set_privilege_reduce_privilege (void **state) { - int ret; - - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - - ret = set_privilege((HANDLE)123456, "SeSecurityPrivilege", 0); - - assert_int_equal(ret, 0); -} - -void test_w_update_sacl_AllocateAndInitializeSid_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - - everyone_sid = NULL; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6683): Could not obtain the sid of Everyone. Error '5'."); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_OpenProcessToken_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) NULL); - will_return(wrap_OpenProcessToken, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6684): OpenProcessToken() failed. Error '5'."); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_add_privilege_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_LookupPrivilegeValue, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6647): Could not find the 'SeSecurityPrivilege' privilege. Error: 5"); - } - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6685): The privilege could not be activated. Error: '5'."); - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_GetNamedSecurityInfo_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, ERROR_FILE_NOT_FOUND); - - expect_string(__wrap__merror, formatted_msg, "(6686): GetNamedSecurityInfo() failed. Error '2'"); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_GetAclInformation_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACL old_acl; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 0); - - expect_string(__wrap__merror, formatted_msg, "(6687): The size of the 'C:\\a\\path' SACL could not be obtained."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_alloc_new_sacl_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACL old_acl; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, NULL); - - expect_string(__wrap__merror, formatted_msg, "(6688): No memory could be reserved for the new SACL of 'C:\\a\\path'."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_InitializeAcl_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACL old_acl; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, - "(6689): The new SACL for 'C:\\a\\path' could not be created. Error: '5'."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_alloc_ace_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACL old_acl; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, NULL); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, - "(6690): No memory could be reserved for the new ACE of 'C:\\a\\path'. Error: '5'."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_CopySid_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACL old_acl; - SYSTEM_AUDIT_ACE ace; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, NULL); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, - "(6691): Could not copy the everyone SID for 'C:\\a\\path'. Error: '1-5'."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_old_sacl_GetAce_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - SYSTEM_AUDIT_ACE ace; - ACL old_acl; - ACL_SIZE_INFORMATION old_sacl_info = { - .AceCount = 1, - }; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - will_return(wrap_GetAce, NULL); - will_return(wrap_GetAce, 0); - - expect_string(__wrap__merror, formatted_msg, - "(6692): The ACE number 0 for 'C:\\a\\path' could not be obtained."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_old_sacl_AddAce_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - SYSTEM_AUDIT_ACE ace; - ACL old_acl; - ACL_SIZE_INFORMATION old_sacl_info = { - .AceCount = 1, - }; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 0); - - expect_string(__wrap__merror, formatted_msg, - "(6693): The ACE number 0 of 'C:\\a\\path' could not be copied to the new ACL."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_new_sacl_AddAce_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - SYSTEM_AUDIT_ACE ace; - ACL old_acl; - ACL_SIZE_INFORMATION old_sacl_info = { - .AceCount = 1, - }; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, - "(6694): The new ACE could not be added to 'C:\\a\\path'. Error: '5'."); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_SetNamedSecurityInfo_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - SYSTEM_AUDIT_ACE ace; - ACL old_acl; - ACL_SIZE_INFORMATION old_sacl_info = { - .AceCount = 1, - }; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, 34567); - will_return(wrap_SetNamedSecurityInfo, ERROR_PATH_NOT_FOUND); - - expect_string(__wrap__merror, formatted_msg, - "(6695): SetNamedSecurityInfo() failed. Error: '3'"); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, OS_INVALID); -} - -void test_w_update_sacl_remove_privilege_error(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - SYSTEM_AUDIT_ACE ace; - ACL old_acl; - ACL_SIZE_INFORMATION old_sacl_info = { - .AceCount = 1, - }; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, 34567); - will_return(wrap_SetNamedSecurityInfo, ERROR_SUCCESS); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_LookupPrivilegeValue, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6647): Could not find the 'SeSecurityPrivilege' privilege. Error: 5"); - } - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6685): The privilege could not be activated. Error: '5'."); - - /* Retry set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, 0); -} - -void test_w_update_sacl_success(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - SYSTEM_AUDIT_ACE ace; - ACL old_acl; - ACL_SIZE_INFORMATION old_sacl_info = { - .AceCount = 1, - }; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &old_acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR) 2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 13); - will_return(wrap_win_alloc, (LPVOID) 34567); - - expect_value(wrap_InitializeAcl, pAcl, (LPVOID) 34567); - expect_value(wrap_InitializeAcl, nAclLength, 13); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 1); - - expect_value(wrap_AddAce, pAcl, 34567); - will_return(wrap_AddAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, 34567); - will_return(wrap_SetNamedSecurityInfo, ERROR_SUCCESS); - - /* goto end */ - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = w_update_sacl("C:\\a\\path"); - - assert_int_equal(ret, 0); -} - -void test_whodata_check_arch_open_registry_key_error(void **state) { - int ret; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, NULL); - will_return(wrap_RegOpenKeyEx, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, - "(1758): Unable to open registry key: 'System\\CurrentControlSet\\Control\\Session Manager\\Environment'."); - - ret = whodata_check_arch(); - - assert_int_equal(ret, OS_INVALID); -} - -void test_whodata_check_arch_query_key_value_error(void **state) { - int ret; - HKEY key; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, NULL); - will_return(wrap_RegQueryValueEx, ERROR_OUTOFMEMORY); - - expect_string(__wrap__merror, formatted_msg, - "(6682): Error reading 'Architecture' from Windows registry. (Error 14)"); - - ret = whodata_check_arch(); - - assert_int_equal(ret, OS_INVALID); -} - -void test_whodata_check_arch_not_supported_arch(void **state) { - int ret; - HKEY key; - const BYTE data[64] = "N/A"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - - ret = whodata_check_arch(); - - assert_int_equal(ret, OS_INVALID); -} - -void test_whodata_check_arch_x86(void **state) { - int ret; - HKEY key; - const BYTE data[64] = "x86"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - - ret = whodata_check_arch(); - - assert_int_equal(ret, 0); - assert_int_equal(sys_64, 0); -} - -void test_whodata_check_arch_amd64(void **state) { - int ret; - HKEY key; - const BYTE data[64] = "AMD64"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - - ret = whodata_check_arch(); - - assert_int_equal(ret, 0); - assert_int_equal(sys_64, 1); -} - -void test_whodata_check_arch_ia64(void **state) { - int ret; - HKEY key; - const BYTE data[64] = "IA64"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - - ret = whodata_check_arch(); - - assert_int_equal(ret, 0); - assert_int_equal(sys_64, 1); -} - -void test_whodata_check_arch_arm64(void **state) { - int ret; - HKEY key; - const BYTE data[64] = "ARM64"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - - ret = whodata_check_arch(); - - assert_int_equal(ret, 0); - assert_int_equal(sys_64, 1); -} - -void test_whodata_path_filter_32_bit_system(void **state) { - char *path = "C:\\windows\\system32\\test"; - int ret; - - sys_64 = 0; - - ret = whodata_path_filter(&path); - - assert_int_equal(ret, 0); - assert_string_equal(path, "C:\\windows\\system32\\test"); -} - -void test_get_whodata_path_error_determining_buffer_size(void **state) { - const char *win_path = "C:\\a\\path"; - char *ret; - - expect_string(wrap_WideCharToMultiByte, lpWideCharStr, "C:\\a\\path"); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mdebug1, formatted_msg, "(6306): The path could not be processed in Whodata mode. Error: 5"); - - ret = get_whodata_path((const short unsigned int *)win_path); - - assert_null(ret); -} - -void test_get_whodata_path_error_copying_buffer(void **state) { - const char *win_path = "C:\\a\\path"; - char *ret; - - expect_string(wrap_WideCharToMultiByte, lpWideCharStr, "C:\\a\\path"); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, 10); - - expect_string(wrap_WideCharToMultiByte, lpWideCharStr, "C:\\a\\path"); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, ""); - will_return(wrap_WideCharToMultiByte, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mdebug1, formatted_msg, "(6306): The path could not be processed in Whodata mode. Error: 5"); - - ret = get_whodata_path((const short unsigned int *)win_path); - - assert_null(ret); -} - -void test_get_whodata_path_success(void **state) { - const char *win_path = "C:\\a\\path"; - char *ret; - - expect_string(wrap_WideCharToMultiByte, lpWideCharStr, "C:\\a\\path"); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, 21); - - expect_string(wrap_WideCharToMultiByte, lpWideCharStr, "C:\\a\\path"); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, "C:\\another\\path.file"); - will_return(wrap_WideCharToMultiByte, 21); - - ret = get_whodata_path((const short unsigned int *)win_path); - - *state = ret; - - assert_non_null(ret); - assert_string_equal(ret, "C:\\another\\path.file"); -} - -void test_is_valid_sacl_sid_error(void **state) { - int ret = 0; - PACL sacl = NULL; - everyone_sid = NULL; - - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6632): Could not obtain the sid of Everyone. Error '700'."); - - ret = is_valid_sacl(sacl, 0); - assert_int_equal(ret, 2); -} - -void test_is_valid_sacl_sacl_not_found(void **state) { - int ret = 0; - PACL sacl = NULL; - everyone_sid = NULL; - - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6267): No SACL found on target. A new one will be created."); - - ret = is_valid_sacl(sacl, 0); - assert_int_equal(ret, 1); -} - -void test_is_valid_sacl_ace_not_found(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - PACL new_sacl = NULL; - unsigned long new_sacl_size; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - // Set the new ACL size - new_sacl_size = sizeof(SYSTEM_AUDIT_ACE) + ev_sid_size - sizeof(unsigned long); - new_sacl = (PACL) win_alloc(new_sacl_size); - InitializeAcl(new_sacl, new_sacl_size, ACL_REVISION); - new_sacl->AceCount=1; - - will_return(wrap_GetAce, NULL); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 800); - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '800'."); - - ret = is_valid_sacl(new_sacl, 0); - assert_int_equal(ret, 1); -} - -void test_is_valid_sacl_not_valid(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - PACL new_sacl = NULL; - unsigned long new_sacl_size; - - everyone_sid = NULL; - ev_sid_size = 1; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - // Set the new ACL size - new_sacl_size = sizeof(SYSTEM_AUDIT_ACE) + ev_sid_size - sizeof(unsigned long); - new_sacl = (PACL) win_alloc(new_sacl_size); - InitializeAcl(new_sacl, new_sacl_size, ACL_REVISION); - new_sacl->AceCount=1; - - will_return(wrap_GetAce, &new_sacl); - will_return(wrap_GetAce, 1); - - ret = is_valid_sacl(new_sacl, 1); - assert_int_equal(ret, 1); -} - -void test_is_valid_sacl_valid(void **state) { - int ret; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACL new_sacl; - ACCESS_ALLOWED_ACE ace; - - everyone_sid = NULL; - ev_sid_size = 1; - - // Set the ACL and ACE data - new_sacl.AceCount=1; - ace.Header.AceFlags = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG; - ace.Mask = FILE_WRITE_DATA | WRITE_DAC | FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | DELETE; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &ace); - will_return(wrap_GetAce, 1); - - will_return(wrap_EqualSid, 1); - - ret = is_valid_sacl(&new_sacl, 1); - assert_int_equal(ret, 0); -} - -void test_replace_device_path_invalid_path(void **state) { - char *path = strdup("invalid\\path"); - - replace_device_path(&path); - - *state = path; - - assert_string_equal(path, "invalid\\path"); -} - -void test_replace_device_path_empty_wdata_device(void **state) { - char *path = strdup("\\C:\\a\\path"); - - replace_device_path(&path); - - *state = path; - - assert_string_equal(path, "\\C:\\a\\path"); -} - -void test_replace_device_path_device_not_found(void **state) { - char *path = strdup("\\Device\\NotFound0\\a\\path"); - syscheck.wdata.device[0] = strdup("\\Device\\HarddiskVolume1"); - syscheck.wdata.drive[0] = strdup("D:"); - syscheck.wdata.device[1] = strdup("\\Device\\Floppy0"); - syscheck.wdata.drive[1] = strdup("A:"); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6304): Find device '\\Device\\HarddiskVolume1' in path '\\Device\\NotFound0\\a\\path'"); - expect_string(__wrap__mdebug2, formatted_msg, - "(6304): Find device '\\Device\\Floppy0' in path '\\Device\\NotFound0\\a\\path'"); - - replace_device_path(&path); - - *state = path; - - assert_string_equal(path, "\\Device\\NotFound0\\a\\path"); -} - -void test_replace_device_path_device_found(void **state) { - char *path = strdup("\\Device\\Floppy0\\a\\path"); - syscheck.wdata.device[0] = strdup("\\Device\\HarddiskVolume1"); - syscheck.wdata.drive[0] = strdup("D:"); - syscheck.wdata.device[1] = strdup("\\Device\\Floppy0"); - syscheck.wdata.drive[1] = strdup("A:"); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6304): Find device '\\Device\\HarddiskVolume1' in path '\\Device\\Floppy0\\a\\path'"); - expect_string(__wrap__mdebug2, formatted_msg, - "(6304): Find device '\\Device\\Floppy0' in path '\\Device\\Floppy0\\a\\path'"); - expect_string(__wrap__mdebug2, formatted_msg, - "(6305): Replacing '\\Device\\Floppy0\\a\\path' to 'A:\\a\\path'"); - - replace_device_path(&path); - - *state = path; - - assert_string_equal(path, "A:\\a\\path"); -} - -void test_get_drive_names_access_denied_error(void **state) { - wchar_t *volume_name = L"\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"; - char *device = "C"; - - expect_memory(wrap_GetVolumePathNamesForVolumeNameW, lpszVolumeName, volume_name, wcslen(volume_name)); - will_return(wrap_GetVolumePathNamesForVolumeNameW, OS_MAXSTR); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mwarn, formatted_msg, "GetVolumePathNamesForVolumeNameW (5)'Input/output error'"); - - get_drive_names(volume_name, device); -} - -void test_get_drive_names_more_data_error(void **state) { - wchar_t *volume_name = L"\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"; - char *device = "C"; - - expect_string(wrap_GetVolumePathNamesForVolumeNameW, - lpszVolumeName, L"\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"); - - will_return(wrap_GetVolumePathNamesForVolumeNameW, OS_MAXSTR); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 0); - - will_return(wrap_GetLastError, ERROR_MORE_DATA); - - expect_memory(wrap_GetVolumePathNamesForVolumeNameW, lpszVolumeName, volume_name, wcslen(volume_name)); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 1); - will_return(wrap_GetVolumePathNamesForVolumeNameW, L""); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mwarn, formatted_msg, "GetVolumePathNamesForVolumeNameW (5)'Input/output error'"); - - get_drive_names(volume_name, device); -} - -void test_get_drive_names_success(void **state) { - wchar_t *volume_name = L"\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"; - char *device = "C"; - wchar_t *volume_paths = L"A\0C\0\\Some\\path\0"; - - expect_memory(wrap_GetVolumePathNamesForVolumeNameW, lpszVolumeName, volume_name, wcslen(volume_name)); - - will_return(wrap_GetVolumePathNamesForVolumeNameW, 16); - will_return(wrap_GetVolumePathNamesForVolumeNameW, volume_paths); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 1); - - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C' associated with the mounting point 'A'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C' associated with the mounting point 'C'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C' associated with the mounting point '\\Some\\path'"); - - - get_drive_names(volume_name, device); -} - -void test_get_volume_names_unable_to_find_first_volume(void **state) { - int ret; - will_return(wrap_FindFirstVolumeW, L""); - will_return(wrap_FindFirstVolumeW, INVALID_HANDLE_VALUE); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mwarn, formatted_msg, "FindFirstVolumeW failed (5)'Input/output error'"); - - expect_value(wrap_FindVolumeClose, hFindVolume, INVALID_HANDLE_VALUE); - will_return(wrap_FindVolumeClose, 1); - - ret = get_volume_names(); - - assert_int_equal(ret, -1); -} - -void test_get_volume_names_bad_path(void **state) { - int ret; - will_return(wrap_FindFirstVolumeW, L"Not a valid volume"); - will_return(wrap_FindFirstVolumeW, (HANDLE)123456); - - expect_string(__wrap__mwarn, formatted_msg, "Find Volume returned a bad path: Not a valid volume"); - - expect_value(wrap_FindVolumeClose, hFindVolume, (HANDLE)123456); - will_return(wrap_FindVolumeClose, 1); - - ret = get_volume_names(); - - assert_int_equal(ret, -1); -} - -void test_get_volume_names_no_dos_device(void **state) { - int ret; - wchar_t *str = L""; - will_return(wrap_FindFirstVolumeW, L"\\\\?\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}\\"); - will_return(wrap_FindFirstVolumeW, (HANDLE)123456); - - expect_string(wrap_QueryDosDeviceW, lpDeviceName, L"Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"); - will_return(wrap_QueryDosDeviceW, wcslen(str)); - will_return(wrap_QueryDosDeviceW, str); - will_return(wrap_QueryDosDeviceW, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mwarn, formatted_msg, "QueryDosDeviceW failed (5)'Input/output error'"); - - expect_value(wrap_FindVolumeClose, hFindVolume, (HANDLE)123456); - will_return(wrap_FindVolumeClose, 1); - - ret = get_volume_names(); - - assert_int_equal(ret, -1); -} - -void test_get_volume_names_error_on_next_volume(void **state) { - int ret; - wchar_t *str = L"C:"; - wchar_t *volume_name = L"\\\\?\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}\\"; - - will_return(wrap_FindFirstVolumeW, volume_name); - will_return(wrap_FindFirstVolumeW, (HANDLE)123456); - - expect_string(wrap_QueryDosDeviceW, lpDeviceName, L"Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"); - will_return(wrap_QueryDosDeviceW, wcslen(str)); - will_return(wrap_QueryDosDeviceW, str); - will_return(wrap_QueryDosDeviceW, wcslen(str)); - - // Inside get_drive_names - { - wchar_t *volume_paths = L"A\0C\0\\Some\\path\0"; - - expect_memory(wrap_GetVolumePathNamesForVolumeNameW, lpszVolumeName, volume_name, wcslen(volume_name)); - - will_return(wrap_GetVolumePathNamesForVolumeNameW, 16); - will_return(wrap_GetVolumePathNamesForVolumeNameW, volume_paths); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 1); - - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point 'A'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point 'C'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point '\\Some\\path'"); - } - - expect_value(wrap_FindNextVolumeW, hFindVolume, (HANDLE)123456); - will_return(wrap_FindNextVolumeW, L""); - will_return(wrap_FindNextVolumeW, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mwarn, formatted_msg, "FindNextVolumeW failed (5)'Input/output error'"); - - expect_value(wrap_FindVolumeClose, hFindVolume, (HANDLE)123456); - will_return(wrap_FindVolumeClose, 1); - - ret = get_volume_names(); - - assert_int_equal(ret, -1); -} - -void test_get_volume_names_no_more_files(void **state) { - int ret; - wchar_t *str = L"C:"; - wchar_t *volume_name = L"\\\\?\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}\\"; - - will_return(wrap_FindFirstVolumeW, volume_name); - will_return(wrap_FindFirstVolumeW, (HANDLE)123456); - - expect_string(wrap_QueryDosDeviceW, lpDeviceName, L"Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"); - will_return(wrap_QueryDosDeviceW, wcslen(str)); - will_return(wrap_QueryDosDeviceW, str); - will_return(wrap_QueryDosDeviceW, wcslen(str)); - - // Inside get_drive_names - { - wchar_t *volume_paths = L"A\0C\0\\Some\\path\0"; - - expect_memory(wrap_GetVolumePathNamesForVolumeNameW, lpszVolumeName, volume_name, wcslen(volume_name)); - - will_return(wrap_GetVolumePathNamesForVolumeNameW, 16); - will_return(wrap_GetVolumePathNamesForVolumeNameW, volume_paths); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 1); - - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point 'A'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point 'C'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point '\\Some\\path'"); - } - - expect_value(wrap_FindNextVolumeW, hFindVolume, (HANDLE)123456); - will_return(wrap_FindNextVolumeW, L""); - will_return(wrap_FindNextVolumeW, 0); - - will_return(wrap_GetLastError, ERROR_NO_MORE_FILES); - - expect_value(wrap_FindVolumeClose, hFindVolume, (HANDLE)123456); - will_return(wrap_FindVolumeClose, 1); - - ret = get_volume_names(); - - assert_int_equal(ret, 0); -} - -void test_notify_SACL_change(void **state) { - expect_string(__wrap_SendMSG, message, - "ossec: Audit: The SACL of 'C:\\a\\path' has been modified and can no longer be scanned in whodata mode."); - expect_string(__wrap_SendMSG, locmsg, "syscheck"); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 0); // Return value is discarded - - notify_SACL_change("C:\\a\\path"); -} - -void test_whodata_hash_add_unable_to_add(void **state) { - wchar_t *data = L"Some random data"; - int ret; - - expect_value(__wrap_OSHash_Add_ex, self, (OSHash*)123456); - expect_string(__wrap_OSHash_Add_ex, key, "key"); - expect_memory(__wrap_OSHash_Add_ex, data, data, wcslen(data)); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, - "(6631): The event could not be added to the 'tag' hash table. Target: 'key'."); - - ret = whodata_hash_add((OSHash*)123456, "key", data, "tag"); - - assert_int_equal(ret, 0); -} - -void test_whodata_hash_add_duplicate_entry(void **state) { - wchar_t *data = L"Some random data"; - int ret; - - expect_value(__wrap_OSHash_Add_ex, self, (OSHash*)123456); - expect_string(__wrap_OSHash_Add_ex, key, "key"); - expect_memory(__wrap_OSHash_Add_ex, data, data, wcslen(data)); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6630): The event could not be added to the 'tag' hash table because it is duplicated. Target: 'key'."); - - ret = whodata_hash_add((OSHash*)123456, "key", data, "tag"); - - assert_int_equal(ret, 1); -} - -void test_whodata_hash_add_success(void **state) { - wchar_t *data = L"Some random data"; - int ret; - - expect_value(__wrap_OSHash_Add_ex, self, (OSHash*)123456); - expect_string(__wrap_OSHash_Add_ex, key, "key"); - expect_memory(__wrap_OSHash_Add_ex, data, data, wcslen(data)); - will_return(__wrap_OSHash_Add_ex, 2); - - ret = whodata_hash_add((OSHash*)123456, "key", data, "tag"); - - assert_int_equal(ret, 2); -} -/*****************************restore_sacls********************************/ -void test_restore_sacls_openprocesstoken_failed(void **state){ - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 0); - - will_return(wrap_GetLastError, (unsigned int) 500); - - expect_string(__wrap__merror, formatted_msg, - "(6648): OpenProcessToken() failed. Error '500'."); - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - expect_value(wrap_CloseHandle, hObject, (HANDLE)4321); - will_return(wrap_CloseHandle, 0); - - restore_sacls(); -} - -void test_restore_sacls_set_privilege_failed(void **state){ - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // set_privilege - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - expect_string(__wrap__merror, formatted_msg, "(6647): Could not find the 'SeSecurityPrivilege' privilege. Error: 5"); - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - expect_string(__wrap__merror, formatted_msg, "(6659): The privilege could not be activated. Error: '5'."); - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - expect_value(wrap_CloseHandle, hObject, (HANDLE)4321); - will_return(wrap_CloseHandle, 0); - restore_sacls(); -} - -int setup_restore_sacls(void **state) { - directory_t *dir_it; - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - dir_it->dirs_status.status &= ~WD_IGNORE_REST; - } - - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status |= WD_IGNORE_REST; - - return 0; -} - -int teardown_restore_sacls(void **state) { - directory_t *dir_it; - OSListNode *node_it; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - OSList_foreach(node_it, syscheck.directories) { - dir_it = node_it->data; - if (FIM_MODE(dir_it->options) == FIM_WHODATA) { - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status |= WD_IGNORE_REST; - } - } - - return 0; -} - -void test_restore_sacls_securityNameInfo_failed(void **state){ - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, ERROR_FILE_NOT_FOUND); - expect_string(__wrap__merror, formatted_msg, "(6650): GetNamedSecurityInfo() failed. Error '2'"); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - expect_value(wrap_CloseHandle, hObject, (HANDLE)4321); - will_return(wrap_CloseHandle, 0); - - restore_sacls(); -} - -void test_restore_sacls_deleteAce_failed(void **state){ - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - ACL acl; - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - expect_value(wrap_DeleteAce, pAcl, &acl); - expect_value(wrap_DeleteAce, dwAceIndex, 0); - will_return(wrap_DeleteAce, 0); - will_return(wrap_GetLastError, 500); - expect_string(__wrap__merror, formatted_msg, "(6646): DeleteAce() failed restoring the SACLs. Error '500'"); - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - expect_value(wrap_CloseHandle, hObject, (HANDLE)4321); - will_return(wrap_CloseHandle, 0); - - restore_sacls(); -} - -void test_restore_sacls_SetNamedSecurityInfo_failed(void **state){ - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - ACL acl; - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - expect_value(wrap_DeleteAce, pAcl, &acl); - expect_value(wrap_DeleteAce, dwAceIndex, 0); - will_return(wrap_DeleteAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, &acl); - will_return(wrap_SetNamedSecurityInfo, ERROR_PATH_NOT_FOUND); - expect_string(__wrap__merror, formatted_msg, "(6658): SetNamedSecurityInfo() failed. Error: '3'."); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - expect_value(wrap_CloseHandle, hObject, (HANDLE)4321); - will_return(wrap_CloseHandle, 0); - - restore_sacls(); -} - -void test_restore_sacls_success(void **state){ - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - ACL acl; - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - expect_value(wrap_DeleteAce, pAcl, &acl); - expect_value(wrap_DeleteAce, dwAceIndex, 0); - will_return(wrap_DeleteAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, &acl); - will_return(wrap_SetNamedSecurityInfo, ERROR_SUCCESS); - - char debug_msg[OS_MAXSTR]; - - snprintf(debug_msg, OS_MAXSTR, FIM_SACL_RESTORED, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - expect_value(wrap_CloseHandle, hObject, (HANDLE)4321); - will_return(wrap_CloseHandle, 0); - - restore_sacls(); -} -/***********************************restore_audit_policies***********************************/ -void test_restore_audit_policies_backup_not_found(void **state) { - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, -1); - expect_string(__wrap__merror, formatted_msg, "(6622): There is no backup of audit policies. Policies will not be restored."); - - int ret = restore_audit_policies(); - assert_int_equal(ret, 1); -} - -void test_restore_audit_policies_command_failed(void **state) { - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - - int i; - int retries = 5; - char error_msgs[retries + 1][OS_SIZE_1024]; - - for (i = 0; i <= retries; i++) { - expect_wm_exec("auditpol /restore /file:\"tmp\\backup-policies\"", retries+i, NULL, "OUTPUT COMMAND", -1, -1); - expect_string(__wrap__merror, formatted_msg, "(6635): Auditpol backup error: 'failed to execute command'."); - snprintf(error_msgs[i], sizeof(error_msgs[i]), "(6955): Auditpol command failed, attempt number: %d", i + 1); - expect_string(__wrap__merror, formatted_msg, error_msgs[i]); - } - - expect_string(__wrap__merror, formatted_msg, "(6956): After 6 attempts the Auditpol command could not be executed successfully."); - int ret = restore_audit_policies(); - assert_int_equal(ret, 1); -} - -void test_restore_audit_policies_command2_failed(void **state) { - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - - int i; - int retries = 5; - char error_msgs[retries + 1][OS_SIZE_1024]; - - - for (i = 0; i <= retries; i++) { - expect_wm_exec("auditpol /restore /file:\"tmp\\backup-policies\"", retries+i, NULL, "OUTPUT COMMAND", -1, 1); - expect_string(__wrap__merror, formatted_msg, "(6635): Auditpol backup error: 'time overtaken while running the command'."); - snprintf(error_msgs[i], sizeof(error_msgs[i]), "(6955): Auditpol command failed, attempt number: %d", i + 1); - expect_string(__wrap__merror, formatted_msg, error_msgs[i]); - } - - expect_string(__wrap__merror, formatted_msg, "(6956): After 6 attempts the Auditpol command could not be executed successfully."); - int ret = restore_audit_policies(); - assert_int_equal(ret, 1); -} - -void test_restore_audit_policies_command3_failed(void **state) { - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - - int i; - int retries = 5; - char error_msgs[retries + 1][OS_SIZE_1024]; - - for (i = 0; i <= retries; i++) { - expect_wm_exec("auditpol /restore /file:\"tmp\\backup-policies\"", retries+i, NULL, "OUTPUT COMMAND", -1, 0); - expect_string(__wrap__merror, formatted_msg, "(6635): Auditpol backup error: 'command returned failure'. Output: 'OUTPUT COMMAND'."); - snprintf(error_msgs[i], sizeof(error_msgs[i]), "(6955): Auditpol command failed, attempt number: %d", i + 1); - expect_string(__wrap__merror, formatted_msg, error_msgs[i]); - } - - expect_string(__wrap__merror, formatted_msg, "(6956): After 6 attempts the Auditpol command could not be executed successfully."); - int ret = restore_audit_policies(); - assert_int_equal(ret, 1); -} - -void test_restore_audit_policies_success(void **state) { - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap_wm_exec, command, "auditpol /restore /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, "OUTPUT COMMAND"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - int ret = restore_audit_policies(); - assert_int_equal(ret, 0); -} -/****************************************audit_restore**************************************/ -void test_audit_restore(void **state) { - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // restore_sacls - { - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE) 123456); - will_return(wrap_OpenProcessToken, 1); - - // set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - ACL acl; - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - expect_value(wrap_DeleteAce, pAcl, &acl); - expect_value(wrap_DeleteAce, dwAceIndex, 0); - will_return(wrap_DeleteAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, &acl); - will_return(wrap_SetNamedSecurityInfo, ERROR_SUCCESS); - - char debug_msg[OS_MAXSTR]; - - snprintf(debug_msg, OS_MAXSTR, FIM_SACL_RESTORED, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - /* Inside set_privilege */ - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - expect_value(wrap_CloseHandle, hObject, (HANDLE)4321); - will_return(wrap_CloseHandle, 0); - } - - // restore_audit_policies - { - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap_wm_exec, command, "auditpol /restore /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, "OUTPUT COMMAND"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - } - - restore_policies = 1; - audit_restore(); - -} - -/********************************************************************************************/ -/**********************************whodata_event_render**************************************/ -void test_whodata_event_render_fail_to_render_event(void **state) { - EVT_HANDLE event = NULL; - PEVT_VARIANT result = NULL; - - /* EvtRender first call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, 0); // BufferSize - will_return(wrap_EvtRender, NULL); // Buffer - will_return(wrap_EvtRender, 0); // BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 0); - - /* EvtRender second call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, 0); // BufferSize - will_return(wrap_EvtRender, NULL); // Buffer - will_return(wrap_EvtRender, 0);// BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 0); - - will_return(wrap_GetLastError, 500); - expect_string(__wrap__mwarn, formatted_msg, "(6933): Error rendering the event. Error 500."); - - result = whodata_event_render(event); - - assert_null(result); -} - -void test_whodata_event_render_wrong_property_count(void **state) { - EVT_HANDLE event = NULL; - EVT_VARIANT buffer[NUM_EVENTS]; - PEVT_VARIANT result = NULL; - - /* EvtRender first call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, 0); // BufferSize - will_return(wrap_EvtRender, NULL); // Buffer - will_return(wrap_EvtRender, SIZE_EVENTS); // BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 0); - - /* EvtRender second call */ - memset(buffer, 0, SIZE_EVENTS); - buffer[0].Type = EvtVarTypeNull; // Wrong buffer type - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, SIZE_EVENTS); // BufferSize - will_return(wrap_EvtRender, buffer); // Buffer - will_return(wrap_EvtRender, SIZE_EVENTS);// BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 1); - - expect_string(__wrap__mwarn, formatted_msg, "(6934): Invalid number of rendered parameters."); - - result = whodata_event_render(event); - assert_null(result); -} - -void test_whodata_event_render_success(void **state) { - EVT_HANDLE event = NULL; - EVT_VARIANT buffer[NUM_EVENTS]; - PEVT_VARIANT result = NULL; - - /* EvtRender first call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, 0); // BufferSize - will_return(wrap_EvtRender, NULL); // Buffer - will_return(wrap_EvtRender, SIZE_EVENTS); // BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 0); - - /* EvtRender second call */ - memset(buffer, 0, SIZE_EVENTS); - buffer[0].Type = EvtVarTypeNull; // Wrong buffer type - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, SIZE_EVENTS); // BufferSize - will_return(wrap_EvtRender, buffer); // Buffer - will_return(wrap_EvtRender, SIZE_EVENTS);// BufferUsed - will_return(wrap_EvtRender, 9); // PropertyCount - will_return(wrap_EvtRender, 1); - - result = whodata_event_render(event); - - *state = result; - assert_non_null(result); - assert_int_equal(result[0].Type, EvtVarTypeNull); -} - -/********************************************************************************************/ -/**********************************whodata_get_event_id**************************************/ -void test_whodata_get_event_id_null_raw_data(void **state) { - PEVT_VARIANT raw_data = NULL; - short event_id; - int result; - - result = whodata_get_event_id(raw_data, &event_id); - - assert_int_equal(result, -1); -} - -void test_whodata_get_event_id_null_event_id(void **state) { - EVT_VARIANT raw_data; - int result; - - result = whodata_get_event_id(&raw_data, NULL); - - assert_int_equal(result, -1); -} - -void test_whodata_get_event_id_wrong_event_type(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - short event_id; - int result; - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'event_id'."); - - result = whodata_get_event_id(raw_data, &event_id); - - assert_int_equal(result, -1); -} - -void test_whodata_get_event_id_success(void **state) { - EVT_VARIANT raw_data[] = { - { .UInt16Val=1234, .Count=1, .Type=EvtVarTypeUInt16 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - short event_id; - int result; - - result = whodata_get_event_id(raw_data, &event_id); - - assert_int_equal(result, 0); - assert_int_equal(event_id, 1234); -} - -/********************************************************************************************/ -/**********************************whodata_get_handle_id**************************************/ -void test_whodata_get_handle_id_null_raw_data(void **state) { - PEVT_VARIANT raw_data = NULL; - unsigned __int64 handle_id; - int result; - - result = whodata_get_handle_id(raw_data, &handle_id); - - assert_int_equal(result, -1); -} - -void test_whodata_get_handle_id_null_handle_id(void **state) { - EVT_VARIANT raw_data; - int result; - - result = whodata_get_handle_id(&raw_data, NULL); - - assert_int_equal(result, -1); -} - -void test_whodata_get_handle_id_64bit_handle_success(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned __int64 handle_id; - int result; - - result = whodata_get_handle_id(raw_data, &handle_id); - - assert_int_equal(result, 0); - assert_int_equal(handle_id, 0x123456); -} - -void test_whodata_get_handle_id_32bit_handle_wrong_type(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned __int64 handle_id; - int result; - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'handle_id'."); - - result = whodata_get_handle_id(raw_data, &handle_id); - - assert_int_equal(result, -1); -} - -void test_whodata_get_handle_id_32bit_success(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeSizeT }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned __int64 handle_id; - int result; - - result = whodata_get_handle_id(raw_data, &handle_id); - - assert_int_equal(result, 0); - assert_int_equal(handle_id, 0x123456); -} - -void test_whodata_get_handle_id_32bit_hex_success(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned __int64 handle_id; - int result; - - result = whodata_get_handle_id(raw_data, &handle_id); - - assert_int_equal(result, 0); - assert_int_equal(handle_id, 0x123456); -} - -/********************************************************************************************/ -/**********************************whodata_get_access_mask**************************************/ -void test_whodata_get_access_mask_null_raw_data(void **state) { - PEVT_VARIANT raw_data = NULL; - unsigned long mask; - int result; - - result = whodata_get_access_mask(raw_data, &mask); - - assert_int_equal(result, -1); -} - -void test_whodata_get_access_mask_null_mask(void **state) { - EVT_VARIANT raw_data; - int result; - - result = whodata_get_access_mask(&raw_data, NULL); - - assert_int_equal(result, -1); -} - -void test_whodata_get_access_mask_wrong_type(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long mask; - int result; - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'mask'."); - - result = whodata_get_access_mask(raw_data, &mask); - - assert_int_equal(result, -1); -} - -void test_whodata_get_access_mask_success(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long mask; - int result; - - result = whodata_get_access_mask(raw_data, &mask); - - assert_int_equal(result, 0); - assert_int_equal(mask, 0x123456); -} - -/********************************************************************************************/ -/**********************************whodata_event_parse**************************************/ -void test_whodata_event_parse_null_raw_data(void **state) { - PEVT_VARIANT raw_data = NULL; - whodata_evt event_data; - int result; - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, -1); -} - -void test_whodata_event_parse_null_event_data(void **state) { - EVT_VARIANT raw_data; - int result; - - result = whodata_event_parse(&raw_data, NULL); - - assert_int_equal(result, -1); -} - -void test_whodata_event_parse_wrong_path_type(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - whodata_evt event_data; - int result; - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'path'."); - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, -1); -} - -void test_whodata_event_parse_fail_to_get_path(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - whodata_evt event_data; - int result; - - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__mdebug1, formatted_msg, "(6306): The path could not be processed in Whodata mode. Error: 5"); - } - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, -1); -} - -void test_whodata_event_parse_filter_path(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"C:\\$recycle.bin\\test.file", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - whodata_evt event_data; - int result; - - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, - lpWideCharStr, - L"C:\\$recycle.bin\\test.file", - wcslen(L"C:\\$recycle.bin\\test.file")); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, 27); - - expect_memory(wrap_WideCharToMultiByte, - lpWideCharStr, - L"C:\\$recycle.bin\\test.file", - wcslen(L"C:\\$recycle.bin\\test.file")); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, "C:\\$recycle.bin\\test.file"); - will_return(wrap_WideCharToMultiByte, 27); - } - - // Inside whodata_path_filter - { - expect_string(__wrap__mdebug2, formatted_msg, - "(6289): File 'c:\\$recycle.bin\\test.file' is in the recycle bin. It will be discarded."); - } - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, -1); -} - -void test_whodata_event_parse_wrong_types(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - }; - whodata_evt event_data; - int result; - - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'user_name'."); - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'process_name'."); - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'process_id'."); - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'user_id'."); - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, 0); - assert_string_equal(event_data.path, STR_TEST_PATH); - assert_null(event_data.user_name); - assert_null(event_data.process_name); - assert_null(event_data.process_id); - assert_null(event_data.user_id); -} - -void test_whodata_event_parse_32bit_process_id(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeSizeT }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - whodata_evt event_data; - int result; - - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, NULL); - will_return(wrap_ConvertSidToStringSid, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "(6246): Invalid identifier for user 'user_name'"); - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, -1); - assert_string_equal(event_data.path, STR_TEST_PATH); - assert_string_equal(event_data.user_name, "user_name"); - assert_string_equal(event_data.process_name, "process_name"); - assert_int_equal(event_data.process_id, 0x123456); - assert_null(event_data.user_id); -} - -void test_whodata_event_parse_32bit_hex_process_id(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Arr=NULL, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Arr=NULL, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .Int64Arr=NULL, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - whodata_evt event_data; - int result; - - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'user_name'."); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, NULL); - will_return(wrap_ConvertSidToStringSid, 0); - - expect_string(__wrap__mdebug1, formatted_msg, FIM_WHODATA_INVALID_UNKNOWN_UID); - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, -1); - assert_string_equal(event_data.path, STR_TEST_PATH); - assert_null(event_data.user_name); - assert_string_equal(event_data.process_name, "process_name"); - assert_int_equal(event_data.process_id, 0x123456); - assert_null(event_data.user_id); -} - -void test_whodata_event_parse_64bit_process_id(void **state) { - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - whodata_evt event_data; - int result; - - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - - result = whodata_event_parse(raw_data, &event_data); - - assert_int_equal(result, 0); - assert_string_equal(event_data.path, STR_TEST_PATH); - assert_string_equal(event_data.user_name, "user_name"); - assert_string_equal(event_data.process_name, "process_name"); - assert_int_equal(event_data.process_id, 0x123456); - assert_string_equal(event_data.user_id, "S-8-15"); -} - -/********************************************************************************************/ -/**********************************whodata_callback**************************************/ -void test_whodata_callback_fail_to_render_event(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - unsigned long result; - - // Inside whodata_event_render - { - /* EvtRender first call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, 0); // BufferSize - will_return(wrap_EvtRender, NULL); // Buffer - will_return(wrap_EvtRender, 0); // BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 0); - - /* EvtRender second call */ - expect_value(wrap_EvtRender, Context, context); - expect_value(wrap_EvtRender, Fragment, event); - expect_value(wrap_EvtRender, Flags, EvtRenderEventValues); - expect_value(wrap_EvtRender, BufferSize, 0); // BufferSize - will_return(wrap_EvtRender, NULL); // Buffer - will_return(wrap_EvtRender, 0);// BufferUsed - will_return(wrap_EvtRender, 0); // PropertyCount - will_return(wrap_EvtRender, 0); - - will_return(wrap_GetLastError, 500); - expect_string(__wrap__mwarn, formatted_msg, "(6933): Error rendering the event. Error 500."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_fail_to_get_event_id(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_get_event_id - { - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'event_id'."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_fail_to_get_handle_id(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_get_handle_id - { - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'handle_id'."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_fail_to_parse_event(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'path'."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_fail_to_get_access_mask(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - // Inside whodata_get_access_mask - { - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'mask'."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_non_monitored_directory(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"C:\\non\\monitored", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123450, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, L"C:\\non\\monitored", wcslen(L"C:\\non\\monitored") * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen("c:\\non\\monitored")); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, L"C:\\non\\monitored", wcslen(L"C:\\non\\monitored") * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, "c:\\non\\monitored"); - will_return(wrap_WideCharToMultiByte, strlen("c:\\non\\monitored")); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6319): No configuration found for (file):'c:\\non\\monitored'"); - expect_string(__wrap__mdebug2, formatted_msg, "(6239): 'c:\\non\\monitored' is discarded because its monitoring is not activated."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_non_whodata_directory(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123450, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - - unsigned long result; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status &= ~WD_CHECK_WHODATA; - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - expect_string(__wrap__mdebug2, formatted_msg, - "(6240): The monitoring of 'c:\\windows\\a\\path' in whodata mode has been canceled. Added to the ignore list."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_path_above_recursion_level(void ** state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x10000, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->recursion_level = 0; - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6217): Maximum level of recursion reached. Depth:1 recursion_level:0 'c:\\windows\\a\\path'"); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_fail_to_add_event_to_hashmap(void ** state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x10000, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - expect_string(__wrap_check_path_type, dir, STR_TEST_PATH); - will_return(__wrap_check_path_type, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "(6298): Removed folder event received for 'c:\\windows\\a\\path'"); - - // Inside whodata_hash_add - { - expect_value(__wrap_OSHash_Add_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Add_ex, key, "1193046"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, - "(6631): The event could not be added to the 'whodata' hash table. Target: '1193046'."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_duplicate_handle_id_fail_to_delete(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - expect_string(__wrap_check_path_type, dir, STR_TEST_PATH); - will_return(__wrap_check_path_type, 2); - - // Inside whodata_hash_add - { - expect_value(__wrap_OSHash_Add_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Add_ex, key, "1193046"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6630): The event could not be added to the 'whodata' hash table because it is duplicated. Target: '1193046'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6229): The handler ('1193046') will be updated."); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, (whodata_evt *)NULL); - - expect_string(__wrap__merror, formatted_msg, - "(6626): The handler '1193046' could not be removed from the whodata hash table."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_duplicate_handle_id_fail_to_readd(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evtdup = malloc(sizeof(whodata_evt)); - - if(w_evtdup == NULL) - fail(); - - memset(w_evtdup, 0, sizeof(whodata_evt)); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - expect_string(__wrap_check_path_type, dir, STR_TEST_PATH); - will_return(__wrap_check_path_type, 2); - - // Inside whodata_hash_add - { - expect_value(__wrap_OSHash_Add_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Add_ex, key, "1193046"); - will_return(__wrap_OSHash_Add_ex, 1); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6630): The event could not be added to the 'whodata' hash table because it is duplicated. Target: '1193046'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6229): The handler ('1193046') will be updated."); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, w_evtdup); - - // Inside whodata_hash_add - { - expect_value(__wrap_OSHash_Add_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Add_ex, key, "1193046"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, - "(6631): The event could not be added to the 'whodata' hash table. Target: '1193046'."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4656_success(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4656, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - successful_whodata_event_render(event, raw_data); - - // Inside whodata_event_parse - { - // Inside get_whodata_path - { - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - - expect_memory(wrap_WideCharToMultiByte, lpWideCharStr, WCS_TEST_PATH, wcslen(WCS_TEST_PATH) * sizeof(WCHAR)); - expect_value(wrap_WideCharToMultiByte, cchWideChar, -1); - will_return(wrap_WideCharToMultiByte, STR_TEST_PATH); - will_return(wrap_WideCharToMultiByte, strlen(STR_TEST_PATH)); - } - - expect_memory(__wrap_convert_windows_string, string, L"user_name", wcslen(L"user_name")); - will_return(__wrap_convert_windows_string, strdup("user_name")); - - expect_memory(__wrap_convert_windows_string, string, L"process_name", wcslen(L"process_name")); - will_return(__wrap_convert_windows_string, strdup("process_name")); - - will_return(wrap_ConvertSidToStringSid, "S-8-15"); - will_return(wrap_ConvertSidToStringSid, 6); - } - - expect_string(__wrap_check_path_type, dir, STR_TEST_PATH); - will_return(__wrap_check_path_type, 2); - - // Inside whodata_hash_add - { - expect_value(__wrap_OSHash_Add_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Add_ex, key, "1193046"); - will_return(__wrap_OSHash_Add_ex, 2); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4719_success(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4719, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - policies_checked = 1; - - successful_whodata_event_render(event, raw_data); - - expect_string(__wrap__mwarn, formatted_msg, FIM_WHODATA_POLICY_CHANGE_CHANNEL); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4663_fail_to_get_mask(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'mask'."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4663_no_permissions(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x0, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4663_fail_to_recover_event(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, NULL); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -void test_whodata_callback_4663_event_is_on_file(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=72623859790382856, .Count=1, .Type=EvtVarTypeFileTime }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - w_evt->scan_directory = 0; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); - assert_int_equal(w_evt->mask, 0x123456); -} - -void test_whodata_callback_4663_event_is_not_rename_or_copy(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x10000, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=72623859790382856, .Count=1, .Type=EvtVarTypeFileTime }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - w_evt->scan_directory = 1; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); - assert_int_equal(w_evt->mask, 0x10000); -} - -void test_whodata_callback_4663_non_monitored_directory(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=72623859790382856, .Count=1, .Type=EvtVarTypeFileTime }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\a\\path"), !w_evt->path) - fail(); - - w_evt->scan_directory = 1; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6319): No configuration found for (file):'c:\\a\\path'"); - expect_string(__wrap__mdebug2, formatted_msg, - "(6243): The 'c:\\a\\path' directory has been discarded because it is not being monitored in whodata mode."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); - assert_int_equal(w_evt->mask, 0x123456); - assert_int_equal(w_evt->scan_directory, 2); -} - -void test_whodata_callback_4663_fail_to_add_new_directory(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=72623859790382856, .Count=1, .Type=EvtVarTypeFileTime }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\windows"), !w_evt->path) - fail(); - - w_evt->scan_directory = 1; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.directories); - expect_string(__wrap_OSHash_Get, key, "c:\\windows"); - will_return(__wrap_OSHash_Get, NULL); - - // Inside whodata_hash_add - { - expect_value(__wrap_OSHash_Add_ex, self, syscheck.wdata.directories); - expect_string(__wrap_OSHash_Add_ex, key, "c:\\windows"); - will_return(__wrap_OSHash_Add_ex, 0); - - expect_string(__wrap__merror, formatted_msg, - "(6631): The event could not be added to the 'directories' hash table. Target: 'c:\\windows'."); - } - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); - assert_int_equal(w_evt->mask, 0x123456); - assert_int_equal(w_evt->scan_directory, 2); -} - -void test_whodata_callback_4663_new_files_added(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=72623859790382856, .Count=1, .Type=EvtVarTypeFileTime }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\windows"), !w_evt->path) - fail(); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - w_evt->scan_directory = 1; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.directories); - expect_string(__wrap_OSHash_Get, key, "c:\\windows"); - will_return(__wrap_OSHash_Get, NULL); - - // Inside whodata_hash_add - { - expect_value(__wrap_OSHash_Add_ex, self, syscheck.wdata.directories); - expect_string(__wrap_OSHash_Add_ex, key, "c:\\windows"); - will_return(__wrap_OSHash_Add_ex, 2); - } - - expect_string(__wrap__mdebug2, formatted_msg, - "(6244): New files have been detected in the 'c:\\windows' directory and will be scanned."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); - assert_int_equal(w_evt->mask, 0x123456); - assert_int_equal(w_evt->scan_directory, 1); -} - -void test_whodata_callback_4663_wrong_time_type(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=0, .Count=0, .Type=EvtVarTypeNull }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\windows"), !w_evt->path) - fail(); - - w_evt->scan_directory = 1; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - expect_string(__wrap__mwarn, formatted_msg, "(6932): Invalid parameter type (0) for 'event_time'."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); - assert_int_equal(w_evt->mask, 0x123456); - assert_int_equal(w_evt->scan_directory, 2); -} - -void test_whodata_callback_4663_abort_scan(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=133022717170000000, .Count=1, .Type=EvtVarTypeFileTime }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - whodata_directory w_dir; - - if(w_evt->path = strdup("c:\\windows"), !w_evt->path) - fail(); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - w_evt->scan_directory = 1; - - memset(&w_dir, 0, sizeof(whodata_directory)); - w_dir.QuadPart = 133022717170000000; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.directories); - expect_string(__wrap_OSHash_Get, key, "c:\\windows"); - will_return(__wrap_OSHash_Get, &w_dir); - - expect_string(__wrap__mdebug2, formatted_msg, "(6241): The 'c:\\windows' directory has been scanned. It does not need to be scanned again."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); - assert_int_equal(w_evt->mask, 0x123456); - assert_int_equal(w_evt->scan_directory, 3); -} - -void test_whodata_callback_4663_directory_will_be_scanned(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4663, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - { .Int64Val=133022717170000000, .Count=1, .Type=EvtVarTypeFileTime }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - whodata_directory w_dir; - - if(w_evt->path = strdup("c:\\windows"), !w_evt->path) - fail(); - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - w_evt->scan_directory = 1; - - memset(&w_dir, 0, sizeof(whodata_directory)); - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Get, key, "1193046"); - will_return(__wrap_OSHash_Get, w_evt); - - expect_value(__wrap_OSHash_Get, self, syscheck.wdata.directories); - expect_string(__wrap_OSHash_Get, key, "c:\\windows"); - will_return(__wrap_OSHash_Get, &w_dir); - - expect_string(__wrap__mdebug2, formatted_msg, "(6244): New files have been detected in the 'c:\\windows' directory and will be scanned."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); - assert_int_equal(w_evt->mask, 0x123456); - assert_int_equal(w_evt->scan_directory, 1); - assert_int_not_equal(w_dir.QuadPart, 0); -} - -void test_whodata_callback_4658_no_event_recovered(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4658, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, NULL); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4658_file_event(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4658, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\a\\path"), !w_evt->path) - fail(); - - w_evt->scan_directory = 0; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, w_evt); - - expect_string(__wrap_fim_whodata_event, w_evt->path, "c:\\a\\path"); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4658_directory_delete_event(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4658, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\a\\path"), !w_evt->path) - fail(); - - w_evt->scan_directory = 1; - w_evt->mask = 0x10000; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, w_evt); - - expect_string(__wrap_fim_whodata_event, w_evt->path, "c:\\a\\path"); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4658_directory_new_file_detected(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4658, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\a\\path"), !w_evt->path) - fail(); - - w_evt->scan_directory = 1; - w_evt->mask = 0x2; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, w_evt); - - expect_string(__wrap_fim_whodata_event, w_evt->path, "c:\\a\\path"); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4658_directory_scan_for_new_files(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4658, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\a\\path"), !w_evt->path) - fail(); - - w_evt->scan_directory = 1; - w_evt->mask = 0x4; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, w_evt); - - expect_string(__wrap_fim_whodata_event, w_evt->path, "c:\\a\\path"); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4658_directory_no_new_files(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4658, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\a\\path"), !w_evt->path) - fail(); - - w_evt->scan_directory = 1; - w_evt->mask = 0x0; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, w_evt); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6245): The 'c:\\a\\path' directory has not been scanned because no new files have been detected. Mask: '0'"); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_4658_scan_aborted(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=4658, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - whodata_evt *w_evt = *state; - - if(w_evt->path = strdup("c:\\a\\path"), !w_evt->path) - fail(); - - w_evt->scan_directory = 2; - w_evt->mask = 0x0; - - successful_whodata_event_render(event, raw_data); - - expect_value(__wrap_OSHash_Delete_ex, self, syscheck.wdata.fd); - expect_string(__wrap_OSHash_Delete_ex, key, "1193046"); - will_return(__wrap_OSHash_Delete_ex, w_evt); - - expect_string(__wrap__mdebug1, formatted_msg, - "(6232): Scanning of the 'c:\\a\\path' directory is aborted because something has gone wrong."); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 0); -} - -void test_whodata_callback_unexpected_event_id(void **state) { - EVT_SUBSCRIBE_NOTIFY_ACTION action = EvtSubscribeActionDeliver; - EVT_HANDLE event = NULL; - EVT_VARIANT raw_data[] = { - { .UInt16Val=1234, .Count=1, .Type=EvtVarTypeUInt16 }, - { .StringVal=L"user_name", .Count=1, .Type=EvtVarTypeString }, - { .StringVal=WCS_TEST_PATH, .Count=1, .Type=EvtVarTypeString }, - { .StringVal=L"process_name", .Count=1, .Type=EvtVarTypeString }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int64Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt64 }, - { .Int32Val=0x123456, .Count=1, .Type=EvtVarTypeHexInt32 }, - { .StringVal=L"S-8-15", .Count=1, .Type=EvtVarTypeSid }, - }; - unsigned long result; - - successful_whodata_event_render(event, raw_data); - - expect_string(__wrap__merror, formatted_msg, FIM_ERROR_WHODATA_EVENTID); - - result = whodata_callback(action, NULL, event); - assert_int_equal(result, 1); -} - -/********************************************************************************************/ -void test_check_object_sacl_open_process_error(void **state) { - int ret; - - will_return(wrap_GetCurrentProcess, (HANDLE)NULL); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)NULL); - will_return(wrap_OpenProcessToken, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6648): OpenProcessToken() failed. Error '5'."); - - ret = check_object_sacl("C:\\a\\path", 0); - - assert_int_equal(ret, 2); -} - -void test_check_object_sacl_unable_to_set_privilege(void **state) { - int ret; - - will_return(wrap_GetCurrentProcess, (HANDLE)123456); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 0); - will_return(wrap_LookupPrivilegeValue, 0); - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, - "(6647): Could not find the 'SeSecurityPrivilege' privilege. Error: 5"); - } - - will_return(wrap_GetLastError, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, "(6659): The privilege could not be activated. Error: '5'."); - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = check_object_sacl("C:\\a\\path", 0); - - assert_int_equal(ret, 2); -} - -void test_check_object_sacl_unable_to_retrieve_security_info(void **state) { - int ret; - - will_return(wrap_GetCurrentProcess, (HANDLE)123456); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, NULL); - will_return(wrap_GetNamedSecurityInfo, ERROR_FILE_NOT_FOUND); - - expect_string(__wrap__merror, formatted_msg, "(6650): GetNamedSecurityInfo() failed. Error '2'"); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = check_object_sacl("C:\\a\\path", 0); - - assert_int_equal(ret, 2); -} - -void test_check_object_sacl_invalid_sacl(void **state) { - ACL acl; - int ret; - - will_return(wrap_GetCurrentProcess, (HANDLE)123456); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // is_valid_sacl - { - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &acl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = check_object_sacl("C:\\a\\path", 0); - - assert_int_equal(ret, 1); -} - -void test_check_object_sacl_valid_sacl(void **state) { - ACL acl; - int ret; - - will_return(wrap_GetCurrentProcess, (HANDLE)123456); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "C:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACCESS_ALLOWED_ACE ace; - - everyone_sid = NULL; - ev_sid_size = 1; - - // Set the ACL and ACE data - ace.Header.AceFlags = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG; - ace.Mask = FILE_WRITE_DATA | FILE_APPEND_DATA | WRITE_DAC | FILE_WRITE_ATTRIBUTES | DELETE; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &ace); - will_return(wrap_GetAce, 1); - - will_return(wrap_EqualSid, 1); - } - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - - ret = check_object_sacl("C:\\a\\path", 0); - - assert_int_equal(ret, 0); -} - -/* run_whodata_scan */ - -void test_run_whodata_scan_invalid_arch(void **state) { - int ret; -/* whodata_check_arch() */ -{ - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, NULL); - will_return(wrap_RegOpenKeyEx, ERROR_ACCESS_DENIED); - - expect_string(__wrap__merror, formatted_msg, - "(1758): Unable to open registry key: 'System\\CurrentControlSet\\Control\\Session Manager\\Environment'."); -} - ret = run_whodata_scan(); - assert_int_equal(ret, 1); -} - -void test_run_whodata_scan_no_audit_policies(void **state) { - int ret; - -/* Inside whodata_check_arch */ -{ - HKEY key; - const BYTE data[64] = "ARM64"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - -} - -/* Inside set_policies */ -{ - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - expect_string(__wrap_remove, filename, "tmp\\backup-policies"); - will_return(__wrap_remove, 1); - - expect_any(__wrap__merror, formatted_msg); -} - - expect_string(__wrap__merror, formatted_msg, - "(6916): Local audit policies could not be configured."); - - ret = run_whodata_scan(); - assert_int_equal(ret, 1); -} - -void test_run_whodata_scan_no_auto_audit_policies(void **state) { - int ret; - -/* Inside whodata_check_arch */ -{ - HKEY key; - const BYTE data[64] = "ARM64"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - -} - -/* Inside set_policies */ -{ - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - expect_string(__wrap_remove, filename, "tmp\\backup-policies"); - will_return(__wrap_remove, 0); - - int i; - int retries = 5; - char error_msgs[retries + 1][OS_SIZE_1024]; - - for (i = 0; i <= retries; i++) { - expect_wm_exec("auditpol /backup /file:\"tmp\\backup-policies\"", retries+i, NULL, NULL, 1, 0); - snprintf(error_msgs[i], sizeof(error_msgs[i]), "(6955): Auditpol command failed, attempt number: %d", i + 1); - expect_string(__wrap__merror, formatted_msg, error_msgs[i]); - } - - expect_string(__wrap__merror, formatted_msg, - "(6915): Audit policies could not be auto-configured due to the Windows version. Check if they are correct for whodata mode."); - -} - expect_string(__wrap__merror, formatted_msg, "(6916): Local audit policies could not be configured."); - - ret = run_whodata_scan(); - assert_int_equal(ret, 1); -} - -void test_run_whodata_scan_error_event_channel(void **state) { - int ret; - -/* Inside whodata_check_arch */ -{ - HKEY key; - const BYTE data[64] = "ARM64"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - -} - -/* Inside set_policies */ -{ - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap_wm_exec, command, "auditpol /backup /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap_wfopen, path, "tmp\\backup-policies"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1234); - - expect_string(__wrap_wfopen, path, "tmp\\new-policies"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE*)2345); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, "some policies"); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, "some policies"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, NULL); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,File System,{0CCE921D-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,Handle Manipulation,{0CCE9223-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(__wrap_fclose, _File, (FILE*)2345); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_wm_exec, command, "auditpol /restore /file:\"tmp\\new-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_value(__wrap_fclose, _File, (FILE*)1234); - will_return(__wrap_fclose, 0); -} - - DWORD fields_number = 9; - EVT_HANDLE event; - - expect_value(wrap_EvtCreateRenderContext, ValuePathsCount, fields_number); - expect_value(wrap_EvtCreateRenderContext, ValuePaths, event_fields); - expect_value(wrap_EvtCreateRenderContext, Flags, EvtRenderContextValues); - will_return(wrap_EvtCreateRenderContext, event); - - wchar_t *query = L"Event[ System[band(Keywords, 9007199254740992)] and " - "( ( ( EventData/Data[@Name='ObjectType'] = 'File' ) and " - "( ( System/EventID = 4656 or System/EventID = 4663 ) and " - "( EventData[band(Data[@Name='AccessMask'], 327938‬)] ) ) ) or " - "System/EventID = 4658 or System/EventID = 4660 ) ]"; - - expect_value(wrap_EvtSubscribe, Session, NULL); - expect_value(wrap_EvtSubscribe, SignalEvent, NULL); - expect_string(wrap_EvtSubscribe, ChannelPath, L"Security"); - expect_string(wrap_EvtSubscribe, Query, query); - expect_value(wrap_EvtSubscribe, Bookmark, NULL); - expect_value(wrap_EvtSubscribe, Context, NULL); - expect_value(wrap_EvtSubscribe, Callback, (EVT_SUBSCRIBE_CALLBACK)whodata_callback); - expect_value(wrap_EvtSubscribe, Flags, EvtSubscribeToFutureEvents); - - will_return(wrap_EvtSubscribe, NULL); - - expect_string(__wrap__merror, formatted_msg, "(6621): Event Channel subscription could not be made. Whodata scan is disabled."); - - ret = run_whodata_scan(); - assert_int_equal(ret, 1); -} - -void test_run_whodata_scan_success(void **state) { - int ret; - -/* Inside whodata_check_arch */ -{ - HKEY key; - const BYTE data[64] = "ARM64"; - - expect_value(wrap_RegOpenKeyEx, hKey, HKEY_LOCAL_MACHINE); - expect_string(wrap_RegOpenKeyEx, lpSubKey, - "System\\CurrentControlSet\\Control\\Session Manager\\Environment"); - expect_value(wrap_RegOpenKeyEx, ulOptions, 0); - expect_value(wrap_RegOpenKeyEx, samDesired, KEY_READ); - will_return(wrap_RegOpenKeyEx, &key); - will_return(wrap_RegOpenKeyEx, ERROR_SUCCESS); - - expect_string(wrap_RegQueryValueEx, lpValueName, "PROCESSOR_ARCHITECTURE"); - expect_value(wrap_RegQueryValueEx, lpReserved, NULL); - expect_value(wrap_RegQueryValueEx, lpType, NULL); - will_return(wrap_RegQueryValueEx, data); - will_return(wrap_RegQueryValueEx, ERROR_SUCCESS); - -} - -/* Inside set_policies */ -{ - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap_wm_exec, command, "auditpol /backup /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap_wfopen, path, "tmp\\backup-policies"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1234); - - expect_string(__wrap_wfopen, path, "tmp\\new-policies"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE*)2345); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, "some policies"); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, "some policies"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, NULL); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,File System,{0CCE921D-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,Handle Manipulation,{0CCE9223-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(__wrap_fclose, _File, (FILE*)2345); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_wm_exec, command, "auditpol /restore /file:\"tmp\\new-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_value(__wrap_fclose, _File, (FILE*)1234); - will_return(__wrap_fclose, 0); -} - - DWORD fields_number = 9; - EVT_HANDLE event; - - expect_value(wrap_EvtCreateRenderContext, ValuePathsCount, fields_number); - expect_value(wrap_EvtCreateRenderContext, ValuePaths, event_fields); - expect_value(wrap_EvtCreateRenderContext, Flags, EvtRenderContextValues); - will_return(wrap_EvtCreateRenderContext, event); - - wchar_t *query = L"Event[ System[band(Keywords, 9007199254740992)] and " - "( ( ( EventData/Data[@Name='ObjectType'] = 'File' ) and " - "( ( System/EventID = 4656 or System/EventID = 4663 ) and " - "( EventData[band(Data[@Name='AccessMask'], 327938‬)] ) ) ) or " - "System/EventID = 4658 or System/EventID = 4660 ) ]"; - - expect_value(wrap_EvtSubscribe, Session, NULL); - expect_value(wrap_EvtSubscribe, SignalEvent, NULL); - expect_string(wrap_EvtSubscribe, ChannelPath, L"Security"); - expect_string(wrap_EvtSubscribe, Query, query); - expect_value(wrap_EvtSubscribe, Bookmark, NULL); - expect_value(wrap_EvtSubscribe, Context, NULL); - expect_value(wrap_EvtSubscribe, Callback, (EVT_SUBSCRIBE_CALLBACK)whodata_callback); - expect_value(wrap_EvtSubscribe, Flags, EvtSubscribeToFutureEvents); - - will_return(wrap_EvtSubscribe, 1); - - expect_string(__wrap__minfo, formatted_msg, "(6019): File integrity monitoring real-time Whodata engine started."); - - ret = run_whodata_scan(); - assert_int_equal(ret, 0); -} - -void test_set_subscription_query(void **state) { - wchar_t output[OS_MAXSTR]; - wchar_t *expected_output = L"Event[ System[band(Keywords, 9007199254740992)] and " - "( ( ( EventData/Data[@Name='ObjectType'] = 'File' ) and " - "( ( System/EventID = 4656 or System/EventID = 4663 ) and " - "( EventData[band(Data[@Name='AccessMask'], 327938‬)] ) ) ) or " - "System/EventID = 4658 or System/EventID = 4660 ) ]"; - - set_subscription_query(output); - - assert_memory_equal(output, expected_output, wcslen(expected_output)); -} - -void test_set_policies_unable_to_remove_backup_file(void **state) { - int ret; - - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap_remove, filename, "tmp\\backup-policies"); - will_return(__wrap_remove, -1); - errno = EACCES; - - expect_string(__wrap__merror, formatted_msg, - "(6660): 'tmp\\backup-policies' could not be removed: 'Permission denied' (13)."); - - ret = set_policies(); - - assert_int_equal(ret, 1); -} - -void test_set_policies_fail_getting_policies(void **state) { - int ret; - - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 1); - - int i; - int retries = 5; - char error_msgs[retries+1][OS_SIZE_1024]; - - for (i = 0; i <= retries; i++) { - expect_wm_exec("auditpol /backup /file:\"tmp\\backup-policies\"", retries+i, NULL, NULL, 1, 0); - snprintf(error_msgs[i], sizeof(error_msgs[i]), "(6955): Auditpol command failed, attempt number: %d", i + 1); - expect_string(__wrap__merror, formatted_msg, error_msgs[i]); - } - - expect_string(__wrap__merror, formatted_msg, - "(6915): Audit policies could not be auto-configured due to the Windows version. Check if they are correct for whodata mode."); - - ret = set_policies(); - - assert_int_equal(ret, 2); -} - -void test_set_policies_unable_to_open_backup_file(void **state) { - int ret; - - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap_wm_exec, command, "auditpol /backup /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap_wfopen, path, "tmp\\backup-policies"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - errno = EACCES; - - expect_string(__wrap__merror, formatted_msg, - "(6661): 'tmp\\backup-policies' could not be opened: 'Permission denied' (13)."); - - ret = set_policies(); - - assert_int_equal(ret, 1); -} - -void test_set_policies_unable_to_open_new_file(void **state) { - int ret; - - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap_wm_exec, command, "auditpol /backup /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap_wfopen, path, "tmp\\backup-policies"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1234); - - expect_string(__wrap_wfopen, path, "tmp\\new-policies"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, NULL); - errno = EACCES; - - expect_string(__wrap__merror, formatted_msg, - "(6661): 'tmp\\new-policies' could not be opened: 'Permission denied' (13)."); - - expect_value(__wrap_fclose, _File, (FILE*)1234); - will_return(__wrap_fclose, 0); - - ret = set_policies(); - - assert_int_equal(ret, 1); -} - -void test_set_policies_unable_to_restore_policies(void **state) { - int ret; - - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap_wm_exec, command, "auditpol /backup /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap_wfopen, path, "tmp\\backup-policies"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1234); - - expect_string(__wrap_wfopen, path, "tmp\\new-policies"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE*)2345); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, "some policies"); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, "some policies"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, NULL); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,File System,{0CCE921D-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,Handle Manipulation,{0CCE9223-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(__wrap_fclose, _File, (FILE*)2345); - will_return(__wrap_fclose, 0); - - int i; - int retries = 5; - char error_msgs[retries+1][OS_SIZE_1024]; - - for (i = 0; i <= retries; i++) { - expect_wm_exec("auditpol /restore /file:\"tmp\\new-policies\"", retries+i, NULL, NULL, 1, 0); - snprintf(error_msgs[i], sizeof(error_msgs[i]), "(6955): Auditpol command failed, attempt number: %d", i + 1); - expect_string(__wrap__merror, formatted_msg, error_msgs[i]); - } - - expect_string(__wrap__merror, formatted_msg, - "(6915): Audit policies could not be auto-configured due to the Windows version. Check if they are correct for whodata mode."); - - expect_value(__wrap_fclose, _File, (FILE*)1234); - will_return(__wrap_fclose, 0); - - ret = set_policies(); - - assert_int_equal(ret, 2); -} - -void test_set_policies_success(void **state) { - int ret; - - expect_string(__wrap_IsFile, file, "tmp\\backup-policies"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap_wm_exec, command, "auditpol /backup /file:\"tmp\\backup-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap_wfopen, path, "tmp\\backup-policies"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1234); - - expect_string(__wrap_wfopen, path, "tmp\\new-policies"); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, (FILE*)2345); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, "some policies"); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, "some policies"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fgets, __stream, (FILE*)1234); - will_return(wrap_fgets, NULL); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,File System,{0CCE921D-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(wrap_fprintf, __stream, 2345); - expect_string(wrap_fprintf, formatted_msg, ",System,Handle Manipulation,{0CCE9223-69AE-11D9-BED3-505054503030},,,1\n"); - will_return(wrap_fprintf, 0); - - expect_value(__wrap_fclose, _File, (FILE*)2345); - will_return(__wrap_fclose, 0); - - expect_string(__wrap_wm_exec, command, "auditpol /restore /file:\"tmp\\new-policies\""); - expect_value(__wrap_wm_exec, secs, 5); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_value(__wrap_fclose, _File, (FILE*)1234); - will_return(__wrap_fclose, 0); - - ret = set_policies(); - - assert_int_equal(ret, 0); -} - -void test_state_checker_no_files_to_check(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - OSList_CleanNodes(syscheck.directories); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - ret = state_checker(input); - - assert_int_equal(ret, 0); -} - -void test_state_checker_file_not_whodata(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - // Leverage Free_Syscheck not free the wdata struct - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status &= ~WD_CHECK_WHODATA; - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - ret = state_checker(input); - - assert_int_equal(ret, 0); -} - -void test_state_checker_file_does_not_exist(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - SYSTEMTIME st; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - memset(&st, 0, sizeof(SYSTEMTIME)); - st.wYear = 2020; - st.wMonth = 3; - st.wDay = 3; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - expect_string(__wrap_check_path_type, dir, "c:\\a\\path"); - will_return(__wrap_check_path_type, 0); - - expect_string(__wrap__mdebug2, formatted_msg, - "(6022): 'c:\\a\\path' has been deleted. It will not be monitored in real-time Whodata mode."); - - will_return(wrap_GetSystemTime, &st); - - ret = state_checker(input); - - assert_int_equal(ret, 0); - assert_memory_equal(&((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.last_check, &st, sizeof(SYSTEMTIME)); - assert_int_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.object_type, WD_STATUS_UNK_TYPE); - assert_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status & WD_STATUS_EXISTS); -} - -void test_state_checker_file_with_invalid_sacl(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - ACL acl; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - acl.AceCount = 1; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - expect_string(__wrap_check_path_type, dir, "c:\\a\\path"); - will_return(__wrap_check_path_type, 1); - - // Inside check_object_sacl - { - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "c:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // is_valid_sacl - { - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &acl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - } - - expect_string(__wrap__minfo, formatted_msg, - "(6021): The SACL of 'c:\\a\\path' has been modified and it is not valid for the real-time Whodata mode. Whodata will not be available for this file."); - - // Inside notify_SACL_change - { - expect_string(__wrap_SendMSG, message, - "ossec: Audit: The SACL of 'c:\\a\\path' has been modified and can no longer be scanned in whodata mode."); - expect_string(__wrap_SendMSG, locmsg, "syscheck"); - expect_value(__wrap_SendMSG, loc, LOCALFILE_MQ); - will_return(__wrap_SendMSG, 0); // Return value is discarded - } - - ret = state_checker(input); - - assert_int_equal(ret, 0); - assert_int_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.object_type, WD_STATUS_FILE_TYPE); - assert_non_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status & WD_STATUS_EXISTS); - assert_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->options & WHODATA_ACTIVE); -} - -void test_state_checker_file_with_valid_sacl(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - SYSTEMTIME st; - ACL acl; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - memset(&st, 0, sizeof(SYSTEMTIME)); - st.wYear = 2020; - st.wMonth = 3; - st.wDay = 3; - - acl.AceCount = 1; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - expect_string(__wrap_check_path_type, dir, "c:\\a\\path"); - will_return(__wrap_check_path_type, 1); - - // Inside check_object_sacl - { - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "c:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, (PSECURITY_DESCRIPTOR)2345); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - ACCESS_ALLOWED_ACE ace; - - everyone_sid = NULL; - ev_sid_size = 1; - - // Set the ACL and ACE data - ace.Header.AceFlags = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | SUCCESSFUL_ACCESS_ACE_FLAG; - ace.Mask = FILE_WRITE_DATA | FILE_APPEND_DATA | WRITE_DAC | FILE_WRITE_ATTRIBUTES | DELETE; - - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &ace); - will_return(wrap_GetAce, 1); - - will_return(wrap_EqualSid, 1); - } - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - } - - will_return(wrap_GetSystemTime, &st); - - ret = state_checker(input); - - assert_int_equal(ret, 0); - assert_memory_equal(&((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.last_check, &st, sizeof(SYSTEMTIME)); - assert_int_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.object_type, WD_STATUS_FILE_TYPE); - assert_non_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status & WD_STATUS_EXISTS); - assert_non_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->options & WHODATA_ACTIVE); -} - -void test_state_checker_dir_readded_error(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - char debug_msg[OS_MAXSTR]; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status &= ~WD_STATUS_EXISTS; - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - expect_string(__wrap_check_path_type, dir, "c:\\a\\path"); - will_return(__wrap_check_path_type, 2); - - expect_string(__wrap__minfo, formatted_msg, - "(6020): 'c:\\a\\path' has been re-added. It will be monitored in real-time Whodata mode."); - - // Inside set_winsacl - { - snprintf(debug_msg, OS_MAXSTR, FIM_SACL_CONFIGURE, ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->path); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 0); - - will_return(wrap_GetLastError, (unsigned int) 500); - expect_string(__wrap__merror, formatted_msg, "(6648): OpenProcessToken() failed. Error '500'."); - } - - expect_string(__wrap__merror, formatted_msg, - "(6619): Unable to add directory to whodata real time monitoring: 'c:\\a\\path'. It will be monitored in Realtime"); - - ret = state_checker(input); - - assert_int_equal(ret, 0); - assert_int_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.object_type, WD_STATUS_DIR_TYPE); - assert_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status & WD_STATUS_EXISTS); - assert_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->options & WHODATA_ACTIVE); -} - -void test_state_checker_dir_readded_succesful(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - ACL acl; - ACL_SIZE_INFORMATION old_sacl_info = {.AceCount = 1}; - SYSTEM_AUDIT_ACE ace; - SECURITY_DESCRIPTOR security_descriptor; - SID_IDENTIFIER_AUTHORITY world_auth = {SECURITY_WORLD_SID_AUTHORITY}; - SYSTEMTIME st; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - acl.AceCount = 1; - - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status &= ~WD_STATUS_EXISTS; - ((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.object_type = WD_STATUS_UNK_TYPE; - - memset(&st, 0, sizeof(SYSTEMTIME)); - st.wYear = 2020; - st.wMonth = 3; - st.wDay = 3; - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - expect_string(__wrap_check_path_type, dir, "c:\\a\\path"); - will_return(__wrap_check_path_type, 2); - - expect_string(__wrap__minfo, formatted_msg, - "(6020): 'c:\\a\\path' has been re-added. It will be monitored in real-time Whodata mode."); - - // Inside set_winsacl - { - ev_sid_size = 1; - - expect_string(__wrap__mdebug2, formatted_msg, "(6266): The SACL of 'c:\\a\\path' will be configured."); - - will_return(wrap_GetCurrentProcess, (HANDLE)4321); - expect_value(wrap_OpenProcessToken, DesiredAccess, TOKEN_ADJUST_PRIVILEGES); - will_return(wrap_OpenProcessToken, (HANDLE)123456); - will_return(wrap_OpenProcessToken, 1); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6268): The 'SeSecurityPrivilege' privilege has been added."); - } - - // GetNamedSecurity - expect_string(wrap_GetNamedSecurityInfo, pObjectName, "c:\\a\\path"); - expect_value(wrap_GetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_GetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - will_return(wrap_GetNamedSecurityInfo, &acl); - will_return(wrap_GetNamedSecurityInfo, &security_descriptor); - will_return(wrap_GetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside is_valid_sacl - { - expect_memory(wrap_AllocateAndInitializeSid, pIdentifierAuthority, &world_auth, 6); - expect_value(wrap_AllocateAndInitializeSid, nSubAuthorityCount, 1); - will_return(wrap_AllocateAndInitializeSid, 1); - - will_return(wrap_GetAce, &acl); - will_return(wrap_GetAce, 0); - - will_return(wrap_GetLastError, (unsigned int) 700); - - expect_string(__wrap__merror, formatted_msg, "(6633): Could not extract the ACE information. Error: '700'."); - } - - expect_string(__wrap__mdebug2, formatted_msg, "(6263): Setting up SACL for 'c:\\a\\path'"); - - will_return(wrap_GetAclInformation, &old_sacl_info); - will_return(wrap_GetAclInformation, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, 1234); - - expect_value(wrap_InitializeAcl, pAcl, 1234); - expect_value(wrap_InitializeAcl, nAclLength, 9); - expect_value(wrap_InitializeAcl, dwAclRevision, ACL_REVISION); - will_return(wrap_InitializeAcl, 1); - - will_return(wrap_GetAce, &old_sacl_info); - will_return(wrap_GetAce, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_value(wrap_win_alloc, size, 9); - will_return(wrap_win_alloc, &ace); - - will_return(wrap_CopySid, 1); - - expect_value(wrap_AddAce, pAcl, 1234); - will_return(wrap_AddAce, 1); - - expect_string(wrap_SetNamedSecurityInfo, pObjectName, "c:\\a\\path"); - expect_value(wrap_SetNamedSecurityInfo, ObjectType, SE_FILE_OBJECT); - expect_value(wrap_SetNamedSecurityInfo, SecurityInfo, SACL_SECURITY_INFORMATION); - expect_value(wrap_SetNamedSecurityInfo, psidOwner, NULL); - expect_value(wrap_SetNamedSecurityInfo, psidGroup, NULL); - expect_value(wrap_SetNamedSecurityInfo, pDacl, NULL); - expect_value(wrap_SetNamedSecurityInfo, pSacl, 1234); - will_return(wrap_SetNamedSecurityInfo, ERROR_SUCCESS); - - // Inside set_privilege - { - expect_string(wrap_LookupPrivilegeValue, lpName, "SeSecurityPrivilege"); - will_return(wrap_LookupPrivilegeValue, 234567); - will_return(wrap_LookupPrivilegeValue, 1); - - expect_value(wrap_AdjustTokenPrivileges, TokenHandle, (HANDLE)123456); - expect_value(wrap_AdjustTokenPrivileges, DisableAllPrivileges, 0); - will_return(wrap_AdjustTokenPrivileges, 1); - - expect_string(__wrap__mdebug2, formatted_msg, "(6269): The 'SeSecurityPrivilege' privilege has been removed."); - } - - expect_value(wrap_CloseHandle, hObject, (HANDLE)123456); - will_return(wrap_CloseHandle, 0); - } - - will_return(wrap_GetSystemTime, &st); - - ret = state_checker(input); - - assert_int_equal(ret, 0); - assert_memory_equal(&((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.last_check, &st, sizeof(SYSTEMTIME)); - assert_int_equal(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.object_type, WD_STATUS_DIR_TYPE); - assert_non_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->dirs_status.status & WD_STATUS_EXISTS); - assert_non_null(((directory_t *)OSList_GetDataFromIndex(syscheck.directories, 0))->options & WHODATA_ACTIVE); -} - -void test_state_checker_not_match_policy(void **state) { - policy_info *pol_data = *state; - int ret; - void *input = NULL; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - OSList_CleanNodes(syscheck.directories); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - pol_data->paudit_policy[0].AuditingInformation = POLICY_AUDIT_EVENT_FAILURE; - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_string(__wrap__mwarn, formatted_msg, FIM_WHODATA_POLICY_CHANGE_CHECKER); - - ret = state_checker(input); - - pol_data->paudit_policy[0].AuditingInformation = POLICY_AUDIT_EVENT_SUCCESS; - - assert_int_equal(ret, 0); -} - -void test_state_checker_dirs_cleanup_no_nodes(void ** state) { - policy_info *pol_data = *state; - int ret; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - ret = state_checker(NULL); - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.wdata.directories->elements, 0); -} - -void test_state_checker_dirs_cleanup_single_non_stale_node(void ** state) { - policy_info *pol_data = *state; - int ret; - whodata_directory * w_dir; - FILETIME current_time; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - if (w_dir = calloc(1, sizeof(whodata_directory)), !w_dir) - fail(); - - GetSystemTimeAsFileTime(¤t_time); - - w_dir->LowPart = current_time.dwLowDateTime; - w_dir->HighPart = current_time.dwHighDateTime; - - if (__real_OSHash_Add(syscheck.wdata.directories, "C:\\some\\path", w_dir) != 2) - fail(); - - ret = state_checker(NULL); - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.wdata.directories->elements, 1); - assert_non_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path")); -} - -void test_state_checker_dirs_cleanup_single_stale_node(void ** state) { - policy_info *pol_data = *state; - int ret; - whodata_directory * w_dir; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - if (w_dir = calloc(1, sizeof(whodata_directory)), !w_dir) - fail(); - - w_dir->LowPart = 0; - w_dir->HighPart = 0; - - if (__real_OSHash_Add(syscheck.wdata.directories, "C:\\some\\path", w_dir) != 2) - fail(); - - expect_value(__wrap_OSHash_Delete, self, syscheck.wdata.directories); - expect_string(__wrap_OSHash_Delete, key, "C:\\some\\path"); - will_return(__wrap_OSHash_Delete, w_dir); - - ret = state_checker(NULL); - - __real_OSHash_Delete(syscheck.wdata.directories, "C:\\some\\path"); - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.wdata.directories->elements, 0); - assert_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path")); -} - -void test_state_checker_dirs_cleanup_multiple_nodes_none_stale(void ** state) { - policy_info *pol_data = *state; - int ret; - FILETIME current_time; - int i; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - for (i = 0; i < 3; i++) { - char key[OS_SIZE_256]; - whodata_directory * w_dir; - - if (w_dir = calloc(1, sizeof(whodata_directory)), !w_dir) - fail(); - - GetSystemTimeAsFileTime(¤t_time); - - w_dir->LowPart = current_time.dwLowDateTime; - w_dir->HighPart = current_time.dwHighDateTime; - - snprintf(key, OS_SIZE_256, "C:\\some\\path-%d", i); - - if (__real_OSHash_Add(syscheck.wdata.directories, key, w_dir) != 2) - fail(); - } - - ret = state_checker(NULL); - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.wdata.directories->elements, 3); - assert_non_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-0")); - assert_non_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-1")); - assert_non_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-2")); -} - -void test_state_checker_dirs_cleanup_multiple_nodes_some_stale(void ** state) { - policy_info *pol_data = *state; - int ret; - FILETIME current_time; - int i; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - for (i = 0; i < 3; i++) { - char key[OS_SIZE_256]; - whodata_directory * w_dir; - - snprintf(key, OS_SIZE_256, "C:\\some\\path-%d", i); - - if (w_dir = calloc(1, sizeof(whodata_directory)), !w_dir) - fail(); - - if (i % 2 == 0) { - w_dir->LowPart = 0; - w_dir->HighPart = 0; - - expect_value(__wrap_OSHash_Delete, self, syscheck.wdata.directories); - expect_any(__wrap_OSHash_Delete, key); - will_return(__wrap_OSHash_Delete, w_dir); - } else { - GetSystemTimeAsFileTime(¤t_time); - - w_dir->LowPart = current_time.dwLowDateTime; - w_dir->HighPart = current_time.dwHighDateTime; - - } - - if (__real_OSHash_Add(syscheck.wdata.directories, key, w_dir) != 2) - fail(); - - } - - ret = state_checker(NULL); - - __real_OSHash_Delete(syscheck.wdata.directories, "C:\\some\\path-0"); - __real_OSHash_Delete(syscheck.wdata.directories, "C:\\some\\path-2"); - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.wdata.directories->elements, 1); - assert_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-0")); - assert_non_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-1")); - assert_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-2")); -} - -void test_state_checker_dirs_cleanup_multiple_nodes_all_stale(void ** state) { - policy_info *pol_data = *state; - int ret; - int i; - char debug_msg1[OS_SIZE_1024]; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - - snprintf(debug_msg1, OS_SIZE_1024, FIM_WHODATA_CHECKTHREAD, 300); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg1); - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_STATE_CHECKER); - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 0); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - expect_value(__wrap_atomic_int_get, atomic, &whodata_end); - will_return(__wrap_atomic_int_get, 1); - - expect_value(wrap_Sleep, dwMilliseconds, WDATA_DEFAULT_INTERVAL_SCAN * 1000); - - for (i = 0; i < 3; i++) { - char key[OS_SIZE_256]; - whodata_directory * w_dir; - - if (w_dir = calloc(1, sizeof(whodata_directory)), !w_dir) - fail(); - - w_dir->LowPart = 0; - w_dir->HighPart = 0; - - snprintf(key, OS_SIZE_256, "C:\\some\\path-%d", i); - - expect_value(__wrap_OSHash_Delete, self, syscheck.wdata.directories); - expect_any(__wrap_OSHash_Delete, key); - will_return(__wrap_OSHash_Delete, w_dir); - - if (__real_OSHash_Add(syscheck.wdata.directories, key, w_dir) != 2) - fail(); - } - ret = state_checker(NULL); - - __real_OSHash_Delete(syscheck.wdata.directories, "C:\\some\\path-0"); - __real_OSHash_Delete(syscheck.wdata.directories, "C:\\some\\path-1"); - __real_OSHash_Delete(syscheck.wdata.directories, "C:\\some\\path-2"); - - assert_int_equal(ret, 0); - assert_int_equal(syscheck.wdata.directories->elements, 0); - assert_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-0")); - assert_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-1")); - assert_null(__real_OSHash_Get(syscheck.wdata.directories, "C:\\some\\path-2")); -} - -void test_whodata_audit_start_fail_to_create_directories_hash_table(void **state) { - int ret; - - expect_function_call(__wrap_OSHash_Create); - will_return(__wrap_OSHash_Create, NULL); - - ret = whodata_audit_start(); - - assert_int_equal(ret, 1); - assert_null(syscheck.wdata.directories); -} - -void test_whodata_audit_start_fail_to_create_fd_hash_table(void **state) { - int ret; - - expect_function_calls(__wrap_OSHash_Create, 2); - will_return(__wrap_OSHash_Create, 1234); - will_return(__wrap_OSHash_Create, NULL); - - ret = whodata_audit_start(); - - assert_int_equal(ret, 1); - assert_ptr_equal(syscheck.wdata.directories, 1234); - assert_null(syscheck.wdata.fd); -} - -void test_whodata_audit_start_success(void **state) { - wchar_t *str = L"C:"; - wchar_t *volume_name = L"\\\\?\\Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}\\"; - int ret; - - expect_function_calls(__wrap_OSHash_Create, 2); - will_return(__wrap_OSHash_Create, 1234); - will_return(__wrap_OSHash_Create, 2345); - - expect_function_call(__wrap_OSHash_SetFreeDataPointer); - will_return(__wrap_OSHash_SetFreeDataPointer, 0); - - expect_string(__wrap__minfo, formatted_msg, FIM_WHODATA_VOLUMES); - - // Inside get_volume_names - { - will_return(wrap_FindFirstVolumeW, volume_name); - will_return(wrap_FindFirstVolumeW, (HANDLE)123456); - - expect_string(wrap_QueryDosDeviceW, lpDeviceName, L"Volume{6B29FC40-CA47-1067-B31D-00DD010662DA}"); - will_return(wrap_QueryDosDeviceW, wcslen(str)); - will_return(wrap_QueryDosDeviceW, str); - will_return(wrap_QueryDosDeviceW, wcslen(str)); - - // Inside get_drive_names - { - wchar_t *volume_paths = L"A\0C\0\\Some\\path\0"; - - expect_memory(wrap_GetVolumePathNamesForVolumeNameW, lpszVolumeName, volume_name, wcslen(volume_name)); - - will_return(wrap_GetVolumePathNamesForVolumeNameW, 16); - will_return(wrap_GetVolumePathNamesForVolumeNameW, volume_paths); - will_return(wrap_GetVolumePathNamesForVolumeNameW, 1); - - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point 'A'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point 'C'"); - expect_string(__wrap__mdebug1, formatted_msg, "(6303): Device 'C\\' associated with the mounting point '\\Some\\path'"); - } - - expect_value(wrap_FindNextVolumeW, hFindVolume, (HANDLE)123456); - will_return(wrap_FindNextVolumeW, L""); - will_return(wrap_FindNextVolumeW, 0); - - will_return(wrap_GetLastError, ERROR_NO_MORE_FILES); - - expect_value(wrap_FindVolumeClose, hFindVolume, (HANDLE)123456); - will_return(wrap_FindVolumeClose, 1); - } - - ret = whodata_audit_start(); - - assert_int_equal(ret, 0); - assert_ptr_equal(syscheck.wdata.directories, 1234); - assert_ptr_equal(syscheck.wdata.fd, 2345); -} - -void test_policy_check_match(void **state) { - policy_info *pol_data = *state; - int ret; - char debug_msg2[OS_SIZE_1024]; - char debug_msg3[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg3, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "File System", guid_FileSystem); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg3); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - ret = policy_check(); - - assert_int_equal(ret, 0); -} - -void test_policy_check_not_match(void **state) { - policy_info *pol_data = *state; - int ret; - char debug_msg2[OS_SIZE_1024]; - char debug_msg4[OS_SIZE_1024]; - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - snprintf(debug_msg4, OS_SIZE_1024, FIM_WHODATA_SUCCESS_POLICY, "Handle Manipulation", guid_Handle); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg4); - - pol_data->paudit_policy[0].AuditingInformation = POLICY_AUDIT_EVENT_FAILURE; - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - ret = policy_check(); - - pol_data->paudit_policy[0].AuditingInformation = POLICY_AUDIT_EVENT_SUCCESS; - - assert_int_equal(ret, 1); -} - -void test_policy_check_LsaOpenPolicy_fail(void **state) { - policy_info *pol_data = *state; - int ret; - - expect_policy_check_match_call((NTSTATUS)1, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - ret = policy_check(); - - assert_int_equal(ret, -1); -} - -void test_policy_check_LsaQueryInformationPolicy_fail(void **state) { - policy_info *pol_data = *state; - int ret; - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)1, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - ret = policy_check(); - - assert_int_equal(ret, -1); -} - -void test_policy_check_AuditLookupCategoryGuidFromCategoryId_fail(void **state) { - policy_info *pol_data = *state; - int ret; - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, FALSE, - 2, TRUE, - pol_data->paudit_policy, TRUE); - - ret = policy_check(); - - assert_int_equal(ret, -1); -} - -void test_policy_check_AuditEnumerateSubCategories_fail(void **state) { - policy_info *pol_data = *state; - int ret; - char debug_msg2[OS_SIZE_1024]; - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, FALSE, - pol_data->paudit_policy, TRUE); - - ret = policy_check(); - - assert_int_equal(ret, -1); -} - -void test_policy_check_AuditQuerySystemPolicy_fail(void **state) { - policy_info *pol_data = *state; - int ret; - char debug_msg2[OS_SIZE_1024]; - - expect_string(__wrap__mdebug2, formatted_msg, FIM_WHODATA_POLICY_OPENED); - snprintf(debug_msg2, OS_SIZE_1024, FIM_WHODATA_OBJECT_ACCESS, guid_ObjectAccess); - expect_string(__wrap__mdebug2, formatted_msg, debug_msg2); - - expect_policy_check_match_call((NTSTATUS)0, - pol_data->audit_event_info, (NTSTATUS)0, - pol_data->category_guid, TRUE, - 2, TRUE, - pol_data->paudit_policy, FALSE); - - ret = policy_check(); - - assert_int_equal(ret, -1); -} - -void test_win_whodata_release_resources(void **state) { - will_return_count(__wrap_os_random, 12345, 2); - syscheck.wdata.fd = __real_OSHash_Create(); - - expect_function_call_any(__wrap_pthread_rwlock_wrlock); - expect_function_call_any(__wrap_pthread_rwlock_unlock); - expect_function_call_any(__wrap_pthread_rwlock_rdlock); - expect_function_call_any(__wrap_pthread_mutex_lock); - expect_function_call_any(__wrap_pthread_mutex_unlock); - - will_return(wrap_EvtClose, 0); - - win_whodata_release_resources(&syscheck.wdata); - -} - -/**************************************************************************/ -int main(void) { - int ret; - const struct CMUnitTest tests[] = { - /* set_winsacl */ - cmocka_unit_test(test_set_winsacl_failed_opening), - cmocka_unit_test(test_set_winsacl_failed_privileges), - cmocka_unit_test(test_set_winsacl_failed_security_descriptor), - cmocka_unit_test(test_set_winsacl_no_need_to_configure_acl), - cmocka_unit_test(test_set_winsacl_unable_to_get_acl_info), - cmocka_unit_test(test_set_winsacl_fail_to_alloc_new_sacl), - cmocka_unit_test(test_set_winsacl_fail_to_initialize_new_sacl), - cmocka_unit_test(test_set_winsacl_fail_getting_ace_from_old_sacl), - cmocka_unit_test(test_set_winsacl_fail_adding_old_ace_into_new_sacl), - cmocka_unit_test(test_set_winsacl_fail_to_alloc_new_ace), - cmocka_unit_test(test_set_winsacl_fail_to_copy_sid), - cmocka_unit_test(test_set_winsacl_fail_to_add_ace), - cmocka_unit_test(test_set_winsacl_fail_to_set_security_info), - cmocka_unit_test(test_set_winsacl_success), - /* set_privilege */ - cmocka_unit_test(test_set_privilege_lookup_error), - cmocka_unit_test(test_set_privilege_adjust_token_error), - cmocka_unit_test(test_set_privilege_elevate_privilege), - cmocka_unit_test(test_set_privilege_reduce_privilege), - /* w_update_sacl */ - cmocka_unit_test(test_w_update_sacl_AllocateAndInitializeSid_error), - cmocka_unit_test(test_w_update_sacl_OpenProcessToken_error), - cmocka_unit_test(test_w_update_sacl_add_privilege_error), - cmocka_unit_test(test_w_update_sacl_GetNamedSecurityInfo_error), - cmocka_unit_test(test_w_update_sacl_GetAclInformation_error), - cmocka_unit_test(test_w_update_sacl_alloc_new_sacl_error), - cmocka_unit_test(test_w_update_sacl_InitializeAcl_error), - cmocka_unit_test(test_w_update_sacl_alloc_ace_error), - cmocka_unit_test(test_w_update_sacl_CopySid_error), - cmocka_unit_test(test_w_update_sacl_old_sacl_GetAce_error), - cmocka_unit_test(test_w_update_sacl_old_sacl_AddAce_error), - cmocka_unit_test(test_w_update_sacl_new_sacl_AddAce_error), - cmocka_unit_test(test_w_update_sacl_SetNamedSecurityInfo_error), - cmocka_unit_test(test_w_update_sacl_remove_privilege_error), - cmocka_unit_test(test_w_update_sacl_success), - /* whodata_check_arch */ - cmocka_unit_test(test_whodata_check_arch_open_registry_key_error), - cmocka_unit_test(test_whodata_check_arch_query_key_value_error), - cmocka_unit_test(test_whodata_check_arch_not_supported_arch), - cmocka_unit_test(test_whodata_check_arch_x86), - cmocka_unit_test(test_whodata_check_arch_amd64), - cmocka_unit_test(test_whodata_check_arch_ia64), - cmocka_unit_test(test_whodata_check_arch_arm64), - /* get_whodata_path */ - cmocka_unit_test(test_get_whodata_path_error_determining_buffer_size), - cmocka_unit_test(test_get_whodata_path_error_copying_buffer), - cmocka_unit_test_teardown(test_get_whodata_path_success, teardown_memblock), - /* is_valid_sacl */ - cmocka_unit_test(test_is_valid_sacl_sid_error), - cmocka_unit_test(test_is_valid_sacl_sacl_not_found), - cmocka_unit_test(test_is_valid_sacl_ace_not_found), - cmocka_unit_test(test_is_valid_sacl_not_valid), - cmocka_unit_test(test_is_valid_sacl_valid), - /* replace_device_path */ - cmocka_unit_test_setup_teardown(test_replace_device_path_invalid_path, setup_replace_device_path, teardown_replace_device_path), - cmocka_unit_test_setup_teardown(test_replace_device_path_empty_wdata_device, setup_replace_device_path, teardown_replace_device_path), - cmocka_unit_test_setup_teardown(test_replace_device_path_device_not_found, setup_replace_device_path, teardown_replace_device_path), - cmocka_unit_test_setup_teardown(test_replace_device_path_device_found, setup_replace_device_path, teardown_replace_device_path), - /* get_drive_names */ - cmocka_unit_test(test_get_drive_names_access_denied_error), - cmocka_unit_test(test_get_drive_names_more_data_error), - cmocka_unit_test_teardown(test_get_drive_names_success, teardown_wdata_device), - /* get_volume_names */ - cmocka_unit_test(test_get_volume_names_unable_to_find_first_volume), - cmocka_unit_test(test_get_volume_names_bad_path), - cmocka_unit_test(test_get_volume_names_no_dos_device), - cmocka_unit_test(test_get_volume_names_error_on_next_volume), - cmocka_unit_test(test_get_volume_names_no_more_files), - /* notify_SACL_change */ - cmocka_unit_test(test_notify_SACL_change), - /* whodata_hash_add */ - // TODO: Should we add tests for NULL input parameter? - cmocka_unit_test(test_whodata_hash_add_unable_to_add), - cmocka_unit_test(test_whodata_hash_add_duplicate_entry), - cmocka_unit_test(test_whodata_hash_add_success), - /* restore_sacls */ - cmocka_unit_test(test_restore_sacls_openprocesstoken_failed), - cmocka_unit_test(test_restore_sacls_set_privilege_failed), - cmocka_unit_test_setup_teardown(test_restore_sacls_securityNameInfo_failed, setup_restore_sacls, teardown_restore_sacls), - cmocka_unit_test_setup_teardown(test_restore_sacls_deleteAce_failed, setup_restore_sacls, teardown_restore_sacls), - cmocka_unit_test_setup_teardown(test_restore_sacls_SetNamedSecurityInfo_failed, setup_restore_sacls, teardown_restore_sacls), - cmocka_unit_test_setup_teardown(test_restore_sacls_success, setup_restore_sacls, teardown_restore_sacls), - /* restore_audit_policies */ - cmocka_unit_test(test_restore_audit_policies_backup_not_found), - cmocka_unit_test(test_restore_audit_policies_command_failed), - cmocka_unit_test(test_restore_audit_policies_command2_failed), - cmocka_unit_test(test_restore_audit_policies_command3_failed), - cmocka_unit_test(test_restore_audit_policies_success), - /* audit_restore */ - cmocka_unit_test_setup_teardown(test_audit_restore, setup_restore_sacls, teardown_restore_sacls), - /* whodata_event_render */ - cmocka_unit_test(test_whodata_event_render_fail_to_render_event), - cmocka_unit_test(test_whodata_event_render_wrong_property_count), - cmocka_unit_test_teardown(test_whodata_event_render_success, teardown_memblock), - /* whodata_get_event_id */ - cmocka_unit_test(test_whodata_get_event_id_null_raw_data), - cmocka_unit_test(test_whodata_get_event_id_null_event_id), - cmocka_unit_test(test_whodata_get_event_id_wrong_event_type), - cmocka_unit_test(test_whodata_get_event_id_success), - /* whodata_get_handle_id */ - cmocka_unit_test(test_whodata_get_handle_id_null_raw_data), - cmocka_unit_test(test_whodata_get_handle_id_null_handle_id), - cmocka_unit_test(test_whodata_get_handle_id_64bit_handle_success), - cmocka_unit_test(test_whodata_get_handle_id_32bit_handle_wrong_type), - cmocka_unit_test(test_whodata_get_handle_id_32bit_success), - cmocka_unit_test(test_whodata_get_handle_id_32bit_hex_success), - /* whodata_get_access_mask */ - cmocka_unit_test(test_whodata_get_access_mask_null_raw_data), - cmocka_unit_test(test_whodata_get_access_mask_null_mask), - cmocka_unit_test(test_whodata_get_access_mask_wrong_type), - cmocka_unit_test(test_whodata_get_access_mask_success), - /* whodata_event_parse */ - cmocka_unit_test(test_whodata_event_parse_null_raw_data), - cmocka_unit_test(test_whodata_event_parse_null_event_data), - cmocka_unit_test(test_whodata_event_parse_wrong_path_type), - cmocka_unit_test(test_whodata_event_parse_fail_to_get_path), - cmocka_unit_test(test_whodata_event_parse_filter_path), - cmocka_unit_test(test_whodata_event_parse_wrong_types), - cmocka_unit_test(test_whodata_event_parse_32bit_process_id), - cmocka_unit_test(test_whodata_event_parse_32bit_hex_process_id), - cmocka_unit_test(test_whodata_event_parse_64bit_process_id), - /* check_object_sacl */ - cmocka_unit_test(test_check_object_sacl_open_process_error), - cmocka_unit_test(test_check_object_sacl_unable_to_set_privilege), - cmocka_unit_test(test_check_object_sacl_unable_to_retrieve_security_info), - cmocka_unit_test(test_check_object_sacl_invalid_sacl), - cmocka_unit_test(test_check_object_sacl_valid_sacl), - /* run_whodata_scan */ - cmocka_unit_test(test_run_whodata_scan_invalid_arch), - cmocka_unit_test(test_run_whodata_scan_no_audit_policies), - cmocka_unit_test(test_run_whodata_scan_no_auto_audit_policies), - cmocka_unit_test(test_run_whodata_scan_error_event_channel), - cmocka_unit_test(test_run_whodata_scan_success), - /* set_subscription_query */ - cmocka_unit_test(test_set_subscription_query), - /* set_policies */ - cmocka_unit_test_teardown(test_set_policies_unable_to_remove_backup_file, teardown_reset_errno), - cmocka_unit_test(test_set_policies_fail_getting_policies), - cmocka_unit_test_teardown(test_set_policies_unable_to_open_backup_file, teardown_reset_errno), - cmocka_unit_test_teardown(test_set_policies_unable_to_open_new_file, teardown_reset_errno), - cmocka_unit_test(test_set_policies_unable_to_restore_policies), - cmocka_unit_test(test_set_policies_success), - /* whodata_audit_start */ - cmocka_unit_test_teardown(test_whodata_audit_start_fail_to_create_directories_hash_table, teardown_whodata_audit_start), - cmocka_unit_test_teardown(test_whodata_audit_start_fail_to_create_fd_hash_table, teardown_whodata_audit_start), - cmocka_unit_test_teardown(test_whodata_audit_start_success, teardown_whodata_audit_start), - /* policy_check */ - cmocka_unit_test_setup_teardown(test_policy_check_match, setup_policy_check, teardown_policy_check), - cmocka_unit_test_setup_teardown(test_policy_check_not_match, setup_policy_check, teardown_policy_check), - cmocka_unit_test_setup_teardown(test_policy_check_LsaOpenPolicy_fail, setup_policy_check, teardown_policy_check), - cmocka_unit_test_setup_teardown(test_policy_check_LsaQueryInformationPolicy_fail, setup_policy_check, teardown_policy_check), - cmocka_unit_test_setup_teardown(test_policy_check_AuditLookupCategoryGuidFromCategoryId_fail, setup_policy_check, teardown_policy_check), - cmocka_unit_test_setup_teardown(test_policy_check_AuditEnumerateSubCategories_fail, setup_policy_check, teardown_policy_check), - cmocka_unit_test_setup_teardown(test_policy_check_AuditQuerySystemPolicy_fail, setup_policy_check, teardown_policy_check), - /* win_whodata_release_resources */ - cmocka_unit_test(test_win_whodata_release_resources), - }; - const struct CMUnitTest whodata_callback_tests[] = { - /* whodata_callback */ - cmocka_unit_test(test_whodata_callback_fail_to_render_event), - cmocka_unit_test(test_whodata_callback_fail_to_get_event_id), - cmocka_unit_test(test_whodata_callback_fail_to_get_handle_id), - cmocka_unit_test(test_whodata_callback_4656_fail_to_parse_event), - cmocka_unit_test(test_whodata_callback_4656_fail_to_get_access_mask), - cmocka_unit_test(test_whodata_callback_4656_non_monitored_directory), - cmocka_unit_test_teardown(test_whodata_callback_4656_non_whodata_directory, teardown_whodata_callback_restore_globals), - cmocka_unit_test_teardown(test_whodata_callback_4656_path_above_recursion_level, teardown_whodata_callback_restore_globals), - cmocka_unit_test(test_whodata_callback_4656_fail_to_add_event_to_hashmap), - cmocka_unit_test(test_whodata_callback_4656_duplicate_handle_id_fail_to_delete), - cmocka_unit_test(test_whodata_callback_4656_duplicate_handle_id_fail_to_readd), - cmocka_unit_test(test_whodata_callback_4656_success), - cmocka_unit_test(test_whodata_callback_4719_success), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_fail_to_get_mask, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_no_permissions, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test(test_whodata_callback_4663_fail_to_recover_event), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_event_is_on_file, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_event_is_not_rename_or_copy, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_non_monitored_directory, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_fail_to_add_new_directory, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_new_files_added, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_wrong_time_type, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_abort_scan, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4663_directory_will_be_scanned, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test(test_whodata_callback_4658_no_event_recovered), - cmocka_unit_test_setup_teardown(test_whodata_callback_4658_file_event, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4658_directory_delete_event, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4658_directory_new_file_detected, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4658_directory_scan_for_new_files, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4658_directory_no_new_files, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test_setup_teardown(test_whodata_callback_4658_scan_aborted, setup_win_whodata_evt, teardown_win_whodata_evt), - cmocka_unit_test(test_whodata_callback_unexpected_event_id), - }; - const struct CMUnitTest state_checker_tests[] = { - /* state_checker */ - cmocka_unit_test_teardown(test_state_checker_no_files_to_check, teardown_state_checker_restore_globals), - cmocka_unit_test_teardown(test_state_checker_file_not_whodata, teardown_state_checker_restore_globals), - cmocka_unit_test_teardown(test_state_checker_file_does_not_exist, teardown_state_checker_restore_globals), - cmocka_unit_test_teardown(test_state_checker_file_with_invalid_sacl, teardown_state_checker_restore_globals), - cmocka_unit_test_teardown(test_state_checker_file_with_valid_sacl, teardown_state_checker_restore_globals), - cmocka_unit_test_teardown(test_state_checker_dir_readded_error, teardown_state_checker_restore_globals), - cmocka_unit_test_teardown(test_state_checker_dir_readded_succesful, teardown_state_checker_restore_globals), - cmocka_unit_test_teardown(test_state_checker_not_match_policy, teardown_state_checker_restore_globals), - }; - // The following group of tests are also executed on state_checker, - // though they only test the cleanup part of syscheck.wdata.directories logic. - // The context for these tests are different than the ones on the rest of the function, it might be a good idea to - // move this into its own thread. - const struct CMUnitTest wdata_directories_cleanup_tests[] = { - cmocka_unit_test(test_state_checker_dirs_cleanup_no_nodes), - cmocka_unit_test_teardown(test_state_checker_dirs_cleanup_single_non_stale_node, teardown_clean_directories_hash), - cmocka_unit_test_teardown(test_state_checker_dirs_cleanup_single_stale_node, teardown_clean_directories_hash), - cmocka_unit_test_teardown(test_state_checker_dirs_cleanup_multiple_nodes_none_stale, teardown_clean_directories_hash), - cmocka_unit_test_teardown(test_state_checker_dirs_cleanup_multiple_nodes_some_stale, teardown_clean_directories_hash), - cmocka_unit_test_teardown(test_state_checker_dirs_cleanup_multiple_nodes_all_stale, teardown_clean_directories_hash), - }; - - - ret = cmocka_run_group_tests(whodata_callback_tests, setup_whodata_callback_group, teardown_whodata_callback_group); - ret += cmocka_run_group_tests(state_checker_tests, setup_state_checker, teardown_state_checker); - ret += cmocka_run_group_tests(wdata_directories_cleanup_tests, setup_wdata_dirs_cleanup, teardown_state_checker); - ret += cmocka_run_group_tests(tests, test_group_setup, test_group_teardown); - - return ret; -} diff --git a/src/unit_tests/wazuh_db/CMakeLists.txt b/src/unit_tests/wazuh_db/CMakeLists.txt deleted file mode 100644 index 9caa21df4d5..00000000000 --- a/src/unit_tests/wazuh_db/CMakeLists.txt +++ /dev/null @@ -1,234 +0,0 @@ - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -list(APPEND wdb_tests_names "test_wdb_integrity") -list(APPEND wdb_tests_flags "-Wl,--wrap,_mdebug1 -Wl,--wrap,wdb_stmt_cache -Wl,--wrap,sqlite3_step -Wl,--wrap,sqlite3_errmsg \ - -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,EVP_DigestInit_ex -Wl,--wrap,EVP_DigestUpdate -Wl,--wrap,_DigestFinal_ex \ - -Wl,--wrap,sqlite3_bind_int64 -Wl,--wrap,sqlite3_column_text -Wl,--wrap,_mdebug2 -Wl,--wrap,wdb_exec_stmt \ - -Wl,--wrap,time -Wl,--wrap,_mwarn -Wl,--wrap,_merror -Wl,--wrap,wdb_init_stmt_in_cache -Wl,--wrap,wdb_begin2 ${DEBUG_OP_WRAPPERS} \ - -Wl,--wrap,router_provider_send") - -# Add server specific tests to the list -list(APPEND wdb_tests_names "test_wdb_fim") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_begin2 \ - -Wl,--wrap,wdb_stmt_cache -Wl,--wrap,sqlite3_bind_text \ - -Wl,--wrap,sqlite3_bind_int64 -Wl,--wrap,sqlite3_step -Wl,--wrap,wdb_step -Wl,--wrap,sqlite3_bind_int \ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_parser") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_scan_info_get -Wl,--wrap,wdb_fim_update_date_entry -Wl,--wrap,wdb_fim_clean_old_entries \ - -Wl,--wrap,wdb_scan_info_update -Wl,--wrap,wdb_scan_info_fim_checks_control -Wl,--wrap,wdb_syscheck_load \ - -Wl,--wrap,wdb_fim_delete -Wl,--wrap,wdb_syscheck_save -Wl,--wrap,wdb_syscheck_save2 \ - -Wl,--wrap,wdbi_query_checksum -Wl,--wrap,wdbi_query_clear -Wl,--wrap,wdb_stmt_cache \ - -Wl,--wrap,sqlite3_changes -Wl,--wrap,sqlite3_bind_int -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,sqlite3_last_insert_rowid \ - -Wl,--wrap,sqlite3_step -Wl,--wrap,wdb_step -Wl,--wrap,wdb_open_agent2 -Wl,--wrap,wdb_leave \ - -Wl,--wrap,sqlite3_errmsg -Wl,--wrap,wdb_open_global \ - -Wl,--wrap,wdb_global_agent_exists -Wl,--wrap,wdb_sca_find \ - -Wl,--wrap,cJSON_PrintUnformatted \ - -Wl,--wrap,wdb_agents_get_sys_osinfo -Wl,--wrap,wdb_osinfo_save \ - -Wl,--wrap,wdb_agents_get_packages -Wl,--wrap,wdb_agents_get_hotfixes -Wl,--wrap,close -Wl,--wrap,getpid \ - -Wl,--wrap,wdb_package_save -Wl,--wrap,wdb_hotfix_save -Wl,--wrap,wdb_package_update -Wl,--wrap,wdb_package_delete \ - -Wl,--wrap,wdb_hotfix_delete -Wl,--wrap,time -Wl,--wrap,wdbi_update_attempt -Wl,--wrap,wdbi_update_completion \ - -Wl,--wrap,sqlite3_reset -Wl,--wrap,sqlite3_prepare_v2 \ - -Wl,--wrap,sqlite3_clear_bindings -Wl,--wrap,wdb_get_cache_stmt -Wl,--wrap,sqlite3_column_text \ - -Wl,--wrap,sqlite3_column_int -Wl,--wrap,sqlite3_column_double -Wl,--wrap,sqlite3_bind_null -Wl,--wrap,sqlite3_bind_int64\ - -Wl,--wrap,sqlite3_bind_double -Wl,--wrap,wdb_upsert_dbsync -Wl,--wrap,wdb_delete_dbsync \ - -Wl,--wrap,wdb_get_config -Wl,--wrap,wdb_get_internal_config -Wl,--wrap,wdb_finalize_all_statements \ - -Wl,--wrap,wdb_global_create_backup -Wl,--wrap,wdb_commit2 -Wl,--wrap,wdb_vacuum -Wl,--wrap,wdb_get_db_state \ - -Wl,--wrap,wdb_update_last_vacuum_data -Wl,--wrap,wdb_get_db_free_pages_percentage \ - -Wl,--wrap,w_is_file -Wl,--wrap,wdb_close\ - -Wl,--wrap,wdb_pool_leave ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_global_parser") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_open_global -Wl,--wrap,wdb_leave -Wl,--wrap,wdb_exec -Wl,--wrap,sqlite3_errmsg \ - -Wl,--wrap,wdb_global_insert_agent -Wl,--wrap,wdb_global_update_agent_name -Wl,--wrap,wdb_global_update_agent_version \ - -Wl,--wrap,wdb_global_get_agent_labels -Wl,--wrap,wdb_global_del_agent_labels -Wl,--wrap,wdb_global_set_agent_label \ - -Wl,--wrap,wdb_global_update_agent_keepalive -Wl,--wrap,wdb_global_update_agent_connection_status -Wl,--wrap,wdb_global_update_agent_status_code \ - -Wl,--wrap,wdb_global_delete_agent -Wl,--wrap,wdb_global_select_agent_name -Wl,--wrap,wdb_global_select_agent_group \ - -Wl,--wrap,wdb_global_delete_agent_belong -Wl,--wrap,wdb_global_find_agent -Wl,--wrap,wdb_global_find_group \ - -Wl,--wrap,wdb_global_insert_agent_group -Wl,--wrap,wdb_global_insert_agent_belong -Wl,--wrap,wdb_global_delete_group_belong \ - -Wl,--wrap,wdb_global_delete_group -Wl,--wrap,wdb_global_select_groups \ - -Wl,--wrap,wdb_global_sync_agent_info_get -Wl,--wrap,wdb_global_sync_agent_info_set \ - -Wl,--wrap,wdb_global_get_all_agents -Wl,--wrap,wdb_global_get_agent_info -Wl,--wrap,wdb_global_reset_agents_connection \ - -Wl,--wrap,wdb_global_get_agents_by_connection_status -Wl,--wrap,wdb_global_get_agents_to_disconnect \ - -Wl,--wrap,sqlite3_step -Wl,--wrap,wdb_global_get_groups_integrity -Wl,--wrap,wdb_global_get_backups \ - -Wl,--wrap,wdb_global_restore_backup -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock \ - -Wl,--wrap,wdb_global_select_group_belong -Wl,--wrap,wdb_global_set_agent_groups -Wl,--wrap,wdb_global_sync_agent_groups_get \ - -Wl,--wrap,wdb_global_get_group_agents -Wl,--wrap,w_inc_queries_total -Wl,--wrap,w_inc_global -Wl,--wrap,gettimeofday \ - -Wl,--wrap,w_inc_global_sql -Wl,--wrap,w_inc_global_sql_time -Wl,--wrap,w_inc_global_vacuum -Wl,--wrap,w_inc_global_vacuum_time \ - -Wl,--wrap,w_inc_global_get_fragmentation -Wl,--wrap,w_inc_global_get_fragmentation_time \ - -Wl,--wrap,w_inc_global_agent_insert_agent -Wl,--wrap,w_inc_global_agent_insert_agent_time -Wl,--wrap,w_inc_global_agent_update_agent_name \ - -Wl,--wrap,w_inc_global_agent_update_agent_name_time -Wl,--wrap,w_inc_global_agent_update_agent_data -Wl,--wrap,w_inc_global_agent_update_agent_data_time \ - -Wl,--wrap,w_inc_global_labels_get_labels -Wl,--wrap,w_inc_global_labels_get_labels_time -Wl,--wrap,w_inc_global_agent_update_keepalive \ - -Wl,--wrap,w_inc_global_agent_update_keepalive_time \ - -Wl,--wrap,w_inc_global_agent_update_connection_status -Wl,--wrap,w_inc_global_agent_update_connection_status_time \ - -Wl,--wrap,w_inc_global_agent_update_status_code -Wl,--wrap,w_inc_global_agent_update_status_code_time \ - -Wl,--wrap,w_inc_global_agent_delete_agent -Wl,--wrap,w_inc_global_agent_delete_agent_time -Wl,--wrap,w_inc_global_agent_select_agent_name \ - -Wl,--wrap,w_inc_global_agent_select_agent_name_time -Wl,--wrap,w_inc_global_agent_select_agent_group \ - -Wl,--wrap,w_inc_global_agent_select_agent_group_time -Wl,--wrap,w_inc_global_agent_find_agent -Wl,--wrap,w_inc_global_agent_find_agent_time \ - -Wl,--wrap,w_inc_global_group_find_group -Wl,--wrap,w_inc_global_group_find_group_time -Wl,--wrap,w_inc_global_group_insert_agent_group \ - -Wl,--wrap,w_inc_global_group_insert_agent_group_time -Wl,--wrap,w_inc_global_belongs_select_group_belong \ - -Wl,--wrap,w_inc_global_belongs_select_group_belong_time -Wl,--wrap,w_inc_global_belongs_get_group_agent \ - -Wl,--wrap,w_inc_global_belongs_get_group_agent_time -Wl,--wrap,w_inc_global_group_delete_group -Wl,--wrap,w_inc_global_group_delete_group_time \ - -Wl,--wrap,w_inc_global_group_select_groups -Wl,--wrap,w_inc_global_group_select_groups_time -Wl,--wrap,w_inc_global_agent_sync_agent_info_get \ - -Wl,--wrap,w_inc_global_agent_sync_agent_info_get_time -Wl,--wrap,w_inc_global_agent_sync_agent_info_set \ - -Wl,--wrap,w_inc_global_agent_sync_agent_info_set_time -Wl,--wrap,w_inc_global_agent_set_agent_groups -Wl,--wrap,w_inc_global_agent_set_agent_groups_time \ - -Wl,--wrap,w_inc_global_agent_sync_agent_groups_get -Wl,--wrap,w_inc_global_agent_sync_agent_groups_get_time \ - -Wl,--wrap,w_inc_global_agent_get_groups_integrity -Wl,--wrap,w_inc_global_agent_get_groups_integrity_time -Wl,--wrap,w_inc_global_agent_disconnect_agents \ - -Wl,--wrap,w_inc_global_agent_disconnect_agents_time -Wl,--wrap,w_inc_global_agent_get_all_agents -Wl,--wrap,w_inc_global_agent_get_all_agents_time \ - -Wl,--wrap,w_inc_global_agent_get_agent_info -Wl,--wrap,w_inc_global_agent_get_agent_info_time -Wl,--wrap,w_inc_global_agent_reset_agents_connection \ - -Wl,--wrap,w_inc_global_agent_reset_agents_connection_time -Wl,--wrap,w_inc_global_agent_get_agents_by_connection_status \ - -Wl,--wrap,w_inc_global_agent_get_agents_by_connection_status_time -Wl,--wrap,w_inc_global_backup -Wl,--wrap,w_inc_global_backup_time \ - -Wl,--wrap,wdb_commit2 -Wl,--wrap,wdb_vacuum -Wl,--wrap,wdb_get_db_state -Wl,--wrap,wdb_finalize_all_statements \ - -Wl,--wrap,wdb_update_last_vacuum_data -Wl,--wrap,wdb_get_db_free_pages_percentage -Wl,--wrap,wdb_global_get_distinct_agent_groups \ - -Wl,--wrap,w_inc_global_agent_get_distinct_groups -Wl,--wrap,w_inc_global_agent_get_distinct_groups_time \ - -Wl,--wrap,w_is_file -Wl,--wrap,wdb_close -Wl,--wrap,w_inc_global_open_time -Wl,--wrap,wdb_pool_leave \ - -Wl,--wrap,w_inc_global_agent_recalculate_agent_group_hashes \ -Wl,--wrap,w_inc_global_agent_recalculate_agent_group_hashes_time \ - -Wl,--wrap,wdb_global_recalculate_all_agent_groups_hash -Wl,--wrap,wdb_global_get_all_agents_context ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_global") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_exec -Wl,--wrap,sqlite3_errmsg -Wl,--wrap,wdb_begin2 -Wl,--wrap,wdb_stmt_cache -Wl,--wrap,sqlite3_bind_int \ - -Wl,--wrap,wdb_exec_stmt -Wl,--wrap,wdb_exec_stmt_sized -Wl,--wrap,wdb_step -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,wfopen \ - -Wl,--wrap,sqlite3_bind_parameter_index -Wl,--wrap,cJSON_Delete -Wl,--wrap,cJSON_CreateArray -Wl,--wrap,sqlite3_step -Wl,--wrap,sqlite3_column_int \ - -Wl,--wrap,wdb_init_stmt_in_cache -Wl,--wrap,wdb_get_global_group_hash -Wl,--wrap,wdb_commit2 -Wl,--wrap,wdb_finalize_all_statements \ - -Wl,--wrap,sqlite3_prepare_v2 -Wl,--wrap,w_get_timestamp -Wl,--wrap,wdb_exec_stmt_silent -Wl,--wrap,w_compress_gzfile \ - -Wl,--wrap,sqlite3_finalize -Wl,--wrap,popen -Wl,--wrap,unlink -Wl,--wrap,getpid -Wl,--wrap,opendir -Wl,--wrap,closedir -Wl,--wrap,readdir \ - -Wl,--wrap,stat -Wl,--wrap,w_uncompress_gzfile -Wl,--wrap,wdb_leave -Wl,--wrap,wdb_close -Wl,--wrap,rename -Wl,--wrap,time \ - -Wl,--wrap,wdb_exec_stmt_single_column -Wl,--wrap,w_is_single_node ${DEBUG_OP_WRAPPERS} ${STDIO_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_agents") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_init_stmt_in_cache -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,wdb_exec_stmt_silent -Wl,--wrap,sqlite3_step \ - -Wl,--wrap,wdb_exec_stmt -Wl,--wrap,_mdebug1 -Wl,--wrap,_merror -Wl,--wrap,sqlite3_errmsg -Wl,--wrap,cJSON_Delete \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_CreateArray -Wl,--wrap,cJSON_CreateString -Wl,--wrap,cJSON_AddItemToObject \ - -Wl,--wrap,cJSON_AddItemToArray -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_GetObjectItem -Wl,--wrap,wdb_exec_stmt_sized \ - -Wl,--wrap,wdb_exec_stmt_send -Wl,--wrap,wdbi_check_sync_status -Wl,--wrap,sqlite3_bind_double") - - -list(APPEND wdb_tests_names "test_wdb_global_helpers") -list(APPEND wdb_tests_flags "-Wl,--wrap,strerror \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_CreateArray -Wl,--wrap,cJSON_CreateString -Wl,--wrap,cJSON_Parse \ - -Wl,--wrap,cJSON_AddItemToObject -Wl,--wrap,cJSON_AddItemToArray -Wl,--wrap,cJSON_AddNumberToObject \ - -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_PrintUnformatted -Wl,--wrap,cJSON_GetObjectItem \ - -Wl,--wrap,cJSON_Delete -Wl,--wrap,time -Wl,--wrap,fopen -Wl,--wrap,popen -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap=fgetc\ - -Wl,--wrap,fclose -Wl,--wrap,cJSON_AddArrayToObject -Wl,--wrap,remove -Wl,--wrap,opendir -Wl,--wrap,readdir -Wl,--wrap,closedir \ - -Wl,--wrap,wdbc_query_ex -Wl,--wrap,wdbc_parse_result -Wl,--wrap,wdbc_query_parse_json -Wl,--wrap,wdbc_query_parse \ - -Wl,--wrap,wdb_create_profile -Wl,--wrap,Privsep_GetUser -Wl,--wrap,Privsep_GetGroup -Wl,--wrap,chown \ - -Wl,--wrap,chmod -Wl,--wrap,IsDir -Wl,--wrap,fgets -Wl,--wrap,fflush -Wl,--wrap,fseek -Wl,--wrap,get_node_name \ - -Wl,--wrap,rbtree_insert -Wl,--wrap,wfopen \ - -Wl,--wrap,stat -Wl,--wrap,fgetpos ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_agents_helpers") -list(APPEND wdb_tests_flags "-Wl,--wrap,strerror \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,cJSON_CreateArray -Wl,--wrap,cJSON_CreateString -Wl,--wrap,cJSON_Parse \ - -Wl,--wrap,cJSON_AddItemToObject -Wl,--wrap,cJSON_AddItemToArray -Wl,--wrap,cJSON_AddNumberToObject \ - -Wl,--wrap,cJSON_AddStringToObject -Wl,--wrap,cJSON_PrintUnformatted -Wl,--wrap,cJSON_GetObjectItem \ - -Wl,--wrap,cJSON_ParseWithOpts -Wl,--wrap,cJSON_Delete -Wl,--wrap,wdbc_query_ex -Wl,--wrap,wdbc_parse_result \ - -Wl,--wrap,cJSON_AddItemToArray -Wl,--wrap,cJSON_Duplicate -Wl,--wrap,wdbc_query_parse_json -Wl,--wrap,wdbc_query_parse \ - -Wl,--wrap,cJSON_AddBoolToObject -Wl,--wrap,cJSON_CreateNumber ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb") -list(APPEND wdb_tests_flags "-Wl,--wrap,_mdebug2 -Wl,--wrap,_mdebug1 -Wl,--wrap,_merror -Wl,--wrap,strerror -Wl,--wrap,pthread_mutex_lock -Wl,--wrap,time_diff \ - -Wl,--wrap,pthread_mutex_unlock -Wl,--wrap,OSHash_Get -Wl,--wrap,OSHash_Create -Wl,--wrap,OSHash_Delete_ex \ - -Wl,--wrap,OSHash_Add_ex -Wl,--wrap,sqlite3_open_v2 -Wl,--wrap,sqlite3_close_v2 -Wl,--wrap,sqlite3_step -Wl,--wrap,wdb_step \ - -Wl,--wrap,sqlite3_column_count -Wl,--wrap,sqlite3_column_type -Wl,--wrap,sqlite3_column_name -Wl,--wrap,sqlite3_column_double \ - -Wl,--wrap,sqlite3_column_text -Wl,--wrap,sqlite3_prepare_v2 -Wl,--wrap,sqlite3_finalize -Wl,--wrap,sqlite3_reset \ - -Wl,--wrap,sqlite3_clear_bindings -Wl,--wrap,sqlite3_errmsg -Wl,--wrap,sqlite3_sql -Wl,--wrap,OS_SendSecureTCP \ - -Wl,--wrap,gettimeofday -Wl,--wrap,w_inc_global_rollback -Wl,--wrap,w_inc_global_rollback_time \ - -Wl,--wrap,OS_SetSendTimeout -Wl,--wrap,time -Wl,--wrap,sqlite3_column_int -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,rwlock_lock_write \ - -Wl,--wrap,rwlock_lock_read -Wl,--wrap,rwlock_unlock -Wl,--wrap,wdb_pool_get -Wl,--wrap,wdb_pool_get_or_create \ - -Wl,--wrap,wdb_pool_leave -Wl,--wrap,wdb_pool_keys -Wl,--wrap,wdb_pool_clean -Wl,--wrap,getuid -Wl,--wrap,chmod \ - -Wl,--wrap,stat -Wl,--wrap,sqlite3_exec -Wl,--wrap,sqlite3_free ${HASH_OP_WRAPPERS} ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_upgrade") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_count_tables_with_name \ - -Wl,--wrap,wdb_sql_exec -Wl,--wrap,wdb_metadata_get_entry -Wl,--wrap,fopen -Wl,--wrap,popen -Wl,--wrap,fread -Wl,--wrap,fwrite -Wl,--wrap,fclose \ - -Wl,--wrap,remove -Wl,--wrap,opendir -Wl,--wrap,readdir -Wl,--wrap,closedir -Wl,--wrap,fflush -Wl,--wrap,fseek -Wl,--wrap,fgets \ - -Wl,--wrap,wdb_init -Wl,--wrap,wdb_close -Wl,--wrap,wdb_create_global -Wl,--wrap,wdb_pool_append -Wl,--wrap,chmod -Wl,--wrap,stat \ - -Wl,--wrap,unlink -Wl,--wrap,getpid -Wl,--wrap,time -Wl,--wrap,sqlite3_open_v2 -Wl,--wrap,sqlite3_errmsg -Wl,--wrap,sqlite3_close_v2 \ - -Wl,--wrap,sqlite3_prepare_v2 -Wl,--wrap,sqlite3_step -Wl,--wrap,sqlite3_column_int -Wl,--wrap,sqlite3_finalize -Wl,--wrap,fgetpos \ - -Wl,--wrap,fgetc -Wl,--wrap,wdb_global_create_backup -Wl,--wrap,wdb_global_get_most_recent_backup -Wl,--wrap,wdb_global_restore_backup \ - -Wl,--wrap,wdb_global_adjust_v4 -Wl,--wrap,wfopen ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_metadata") -list(APPEND wdb_tests_flags "-Wl,--wrap,sqlite3_prepare_v2 -Wl,--wrap,sqlite3_errmsg \ - -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,sqlite3_step -Wl,--wrap,sqlite3_finalize -Wl,--wrap,sqlite3_column_int \ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_task_parser") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_task_insert_task -Wl,--wrap,wdb_task_get_upgrade_task_status -Wl,--wrap,wdb_task_update_upgrade_task_status -Wl,--wrap,wdb_task_get_upgrade_task_by_agent_id \ - -Wl,--wrap,wdb_task_cancel_upgrade_tasks -Wl,--wrap,wdb_task_set_timeout_status -Wl,--wrap,wdb_task_delete_old_entries -Wl,--wrap,wdb_open_tasks \ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_rootcheck") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_stmt_cache -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,sqlite3_bind_int \ - -Wl,--wrap,sqlite3_last_insert_rowid -Wl,--wrap,wdb_step -Wl,--wrap,sqlite3_changes -Wl,--wrap,sqlite3_step \ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_syscollector") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_begin2 -Wl,--wrap,_mdebug1 -Wl,--wrap,wdb_stmt_cache -Wl,--wrap,sqlite3_bind_text \ - -Wl,--wrap,sqlite3_bind_int -Wl,--wrap,sqlite3_bind_int64 -Wl,--wrap,sqlite3_step -Wl,--wrap,wdb_step -Wl,--wrap,sqlite3_errmsg \ - -Wl,--wrap,sqlite3_column_text -Wl,--wrap,sqlite3_column_int -Wl,--wrap,sqlite3_bind_double \ - -Wl,--wrap,sqlite3_bind_null -Wl,--wrap,cJSON_GetStringValue -Wl,--wrap,cJSON_GetObjectItem -Wl,--wrap,cJSON_Parse \ - -Wl,--wrap,cJSON_Delete -Wl,--wrap,cJSON_IsNumber -Wl,--wrap,cJSON_IsString -Wl,--wrap,wdb_agents_get_sys_osinfo \ - -Wl,--wrap,wdbi_remove_by_pk \ - ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_task") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_begin2 -Wl,--wrap,wdb_stmt_cache -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,sqlite3_bind_int \ - -Wl,--wrap,wdb_step -Wl,--wrap,sqlite3_column_int -Wl,--wrap,time -Wl,--wrap,sqlite3_errmsg\ - -Wl,--wrap,sqlite3_column_text -Wl,--wrap,sqlite3_step ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wdb_delta_event") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_get_cache_stmt -Wl,--wrap,wdb_step -Wl,--wrap,sqlite3_bind_int -Wl,--wrap,sqlite3_bind_int64 \ - -Wl,--wrap,sqlite3_bind_text -Wl,--wrap,sqlite3_step -Wl,--wrap,sqlite3_bind_double -Wl,--wrap,sqlite3_changes \ - -Wl,--wrap,sqlite3_bind_null -Wl,--wrap,sqlite3_errmsg ${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wazuh_db-config") -list(APPEND wdb_tests_flags "${DEBUG_OP_WRAPPERS}") - -list(APPEND wdb_tests_names "test_wazuh_db_state") -list(APPEND wdb_tests_flags "") - -list(APPEND wdb_tests_names "test_wdb_com") -list(APPEND wdb_tests_flags "-Wl,--wrap,wdb_create_state_json -Wl,--wrap,wdb_get_config -Wl,--wrap,wdb_get_internal_config") - -list(APPEND wdb_tests_names "test_wdb_pool") -list(APPEND wdb_tests_flags "-Wl,--wrap,pthread_mutex_lock -Wl,--wrap,pthread_mutex_unlock") - -list(APPEND wdb_tests_names "test_create_agent_db") -list(APPEND wdb_tests_flags "-Wl,--wrap,wfopen,--wrap,fopen,--wrap,fclose,--wrap,fflush,--wrap,fgets,--wrap,fgetpos,--wrap,fopen,--wrap,fread,--wrap,fseek,--wrap,fwrite,--wrap,remove,--wrap,fgetc,--wrap,chmod,--wrap,stat,--wrap,OS_MoveFile,--wrap,popen ${DEBUG_OP_WRAPPERS}") - -# Add extra compiling flags -add_compile_options(-Wall) -link_directories(${SRC_FOLDER}/build/shared_modules/router) - -# Wazuh-DB objects -FILE(GLOB wazuh_db_objects ${SRC_FOLDER}/wazuh_db/*.o) -list(REMOVE_ITEM wazuh_db_objects ${SRC_FOLDER}/wazuh_db/main.o ${SRC_FOLDER}/wazuh_db/wdb_shared.o) - -# Compilig tests -list(LENGTH wdb_tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET wdb_tests_names ${counter} test_name) - list(GET wdb_tests_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c ${wazuh_db_objects}) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - ${TEST_DEPS} - router - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_db/test_create_agent_db.c b/src/unit_tests/wazuh_db/test_create_agent_db.c deleted file mode 100644 index a3bb680b2ae..00000000000 --- a/src/unit_tests/wazuh_db/test_create_agent_db.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * May 2, 2024. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" - -int setup(__attribute__((unused)) void ** state) { - test_mode = 1; - return 0; -} - -int teardown(__attribute__((unused)) void ** state) { - test_mode = 0; - return 0; -} - -void test_wdb_create_agent_db2_ok(void ** state) { - expect_wfopen(WDB2_DIR "/" WDB_PROF_NAME, "r", (void *)1); - expect_wfopen(WDB2_DIR "/000.db.new", "w", (void *)2); - expect_fread("", 0); - expect_fclose((void *)1, 0); - expect_fclose((void *)2, 0); - expect_string(__wrap_chmod, path, WDB2_DIR "/000.db.new"); - will_return(__wrap_chmod, 0); - expect_string(__wrap_OS_MoveFile, src, WDB2_DIR "/000.db.new"); - expect_string(__wrap_OS_MoveFile, dst, WDB2_DIR "/000.db"); - will_return(__wrap_OS_MoveFile, 0); - - int result = wdb_create_agent_db2("000"); - assert_int_equal(result, 0); -} - -void test_wdb_create_agent_db2_wfopen_error(void ** state) { - expect_wfopen(WDB2_DIR "/" WDB_PROF_NAME, "r", (void *)1); - expect_wfopen(WDB2_DIR "/000.db.new", "w", NULL); - expect_string(__wrap__merror, formatted_msg, "Couldn't create database 'queue/db/000.db': Success (0)"); - expect_fclose((void *)1, 0); - - errno = 0; - int result = wdb_create_agent_db2("000"); - assert_int_equal(result, -1); -} - -void test_wdb_create_agent_db2_fwrite_error(void ** state) { - expect_wfopen(WDB2_DIR "/" WDB_PROF_NAME, "r", (void *)1); - expect_wfopen(WDB2_DIR "/000.db.new", "w", (void *)2); - expect_fread("Hello", 5); - will_return(__wrap_fwrite, 0); - expect_fclose((void *)1, 0); - expect_fclose((void *)2, 0); - - int result = wdb_create_agent_db2("000"); - assert_int_equal(result, -1); -} - -void test_wdb_create_agent_db2_fclose_error(void ** state) { - expect_wfopen(WDB2_DIR "/" WDB_PROF_NAME, "r", (void *)1); - expect_wfopen(WDB2_DIR "/000.db.new", "w", (void *)2); - expect_fread("", 0); - expect_fclose((void *)1, 0); - expect_fclose((void *)2, -1); - expect_string(__wrap__merror, formatted_msg, "Couldn't create file queue/db/000.db.new completely"); - - int result = wdb_create_agent_db2("000"); - assert_int_equal(result, -1); -} - -void test_wdb_create_agent_db2_chmod_error(void ** state) { - expect_wfopen(WDB2_DIR "/" WDB_PROF_NAME, "r", (void *)1); - expect_wfopen(WDB2_DIR "/000.db.new", "w", (void *)2); - expect_fread("", 0); - expect_fclose((void *)1, 0); - expect_fclose((void *)2, 0); - expect_string(__wrap_chmod, path, WDB2_DIR "/000.db.new"); - will_return(__wrap_chmod, -1); - expect_string(__wrap__merror, formatted_msg, "(1127): Could not chmod object 'queue/db/000.db.new' due to [(0)-(Success)]."); - - errno = 0; - int result = wdb_create_agent_db2("000"); - assert_int_equal(result, -1); -} - -void test_wdb_create_agent_db2_rename_error(void ** state) { - expect_wfopen(WDB2_DIR "/" WDB_PROF_NAME, "r", (void *)1); - expect_wfopen(WDB2_DIR "/000.db.new", "w", (void *)2); - expect_fread("", 0); - expect_fclose((void *)1, 0); - expect_fclose((void *)2, 0); - expect_string(__wrap_chmod, path, WDB2_DIR "/000.db.new"); - will_return(__wrap_chmod, 0); - expect_string(__wrap_OS_MoveFile, src, WDB2_DIR "/000.db.new"); - expect_string(__wrap_OS_MoveFile, dst, WDB2_DIR "/000.db"); - will_return(__wrap_OS_MoveFile, -1); - - expect_string(__wrap__merror, formatted_msg, "(1124): Could not rename file 'queue/db/000.db.new' to 'queue/db/000.db' due to [(0)-(Success)]."); - - errno = 0; - int result = wdb_create_agent_db2("000"); - assert_int_equal(result, -1); -} - -int main() { - test_mode = 1; - - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_wdb_create_agent_db2_ok), - cmocka_unit_test(test_wdb_create_agent_db2_wfopen_error), - cmocka_unit_test(test_wdb_create_agent_db2_fwrite_error), - cmocka_unit_test(test_wdb_create_agent_db2_fclose_error), - cmocka_unit_test(test_wdb_create_agent_db2_chmod_error), - cmocka_unit_test(test_wdb_create_agent_db2_rename_error), - }; - - return cmocka_run_group_tests(tests, setup, teardown); -} diff --git a/src/unit_tests/wazuh_db/test_wazuh_db-config.c b/src/unit_tests/wazuh_db/test_wazuh_db-config.c deleted file mode 100644 index ac92e91dfde..00000000000 --- a/src/unit_tests/wazuh_db/test_wazuh_db-config.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../config/wazuh_db-config.h" -#include "../../wazuh_db/wdb.h" - -/* setup/teardown */ - -int wazuh_db_setup() { - wdb_init_conf(); - - return OS_SUCCESS; -} - -int wazuh_db_teardown() { - wdb_free_conf(); - - return OS_SUCCESS; -} - -/* Read_WazuhDB tests */ - -void test_Read_WazuhDB_element_NULL(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - - nodes = calloc(2, sizeof(xml_node*)); - nodes[0] = calloc(1, sizeof(xml_node)); - nodes[0]->element = NULL; - - expect_string(__wrap__merror, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - int ret = Read_WazuhDB(&xml, nodes); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); -} - -void test_Read_WazuhDB_element_invalid(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1230): Invalid element in the configuration: 'invalid'."); - - int ret = Read_WazuhDB(&xml, nodes); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_attribute_NULL(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1233): Invalid attribute '' in the configuration: 'backup'."); - - int ret = Read_WazuhDB(&xml, nodes); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_attribute_invalid(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1233): Invalid attribute 'invalid' in the configuration: 'backup'."); - - int ret = Read_WazuhDB(&xml, nodes); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_attribute_value_invalid(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'database': value."); - - int ret = Read_WazuhDB(&xml, nodes); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_content_NULL(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - int ret = Read_WazuhDB(&xml, nodes); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_valid_config(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "yes" - "120w" - "1" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - int ret = Read_WazuhDB(&xml, nodes); - - assert_int_equal(ret, OS_SUCCESS); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->enabled, 1); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->interval, 72576000); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->max_files, 1); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -/* Read_WazuhDB_Backup tests */ - -void test_Read_WazuhDB_Backup_element_NULL(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_element_invalid(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1230): Invalid element in the configuration: 'invalid'."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_content_NULL(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1234): Invalid NULL content for element: invalid."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_enabled_empty_value(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'enabled': ."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_enabled_invalid_value(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "123" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'enabled': 123."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_interval_invalid_value(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "yes" - "invalid" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'interval': invalid."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_maxfiles_invalid_string(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "yes" - "1d" - "invalid" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'max_files': invalid."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_maxfiles_invalid_value(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "yes" - "1d" - "0" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - expect_string(__wrap__merror, formatted_msg, "(1235): Invalid value for element 'max_files': 0."); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_INVALID); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_valid_config(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "yes" - "1d" - "3" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_SUCCESS); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->enabled, 1); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->interval, 86400); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->max_files, 3); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -void test_Read_WazuhDB_Backup_valid_config2(void **state) -{ - XML_NODE nodes = NULL; - OS_XML xml; - char *test_config = - "" - "no" - "12h" - "10" - ""; - - OS_ReadXMLString(test_config, &xml); - nodes = OS_GetElementsbyNode(&xml, NULL); - - int ret = Read_WazuhDB_Backup(&xml, nodes[0], WDB_GLOBAL_BACKUP); - assert_int_equal(ret, OS_SUCCESS); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->enabled, 0); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->interval, 43200); - assert_int_equal(wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->max_files, 10); - - OS_ClearNode(nodes); - OS_ClearXML(&xml); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Tests Read_WazuhDB - cmocka_unit_test(test_Read_WazuhDB_element_NULL), - cmocka_unit_test(test_Read_WazuhDB_element_invalid), - cmocka_unit_test(test_Read_WazuhDB_attribute_NULL), - cmocka_unit_test(test_Read_WazuhDB_attribute_invalid), - cmocka_unit_test(test_Read_WazuhDB_attribute_value_invalid), - cmocka_unit_test(test_Read_WazuhDB_valid_config), - // Tests Read_WazuhDB_Backup - cmocka_unit_test(test_Read_WazuhDB_Backup_element_NULL), - cmocka_unit_test(test_Read_WazuhDB_Backup_element_invalid), - cmocka_unit_test(test_Read_WazuhDB_Backup_content_NULL), - cmocka_unit_test(test_Read_WazuhDB_Backup_enabled_empty_value), - cmocka_unit_test(test_Read_WazuhDB_Backup_enabled_invalid_value), - cmocka_unit_test(test_Read_WazuhDB_Backup_interval_invalid_value), - cmocka_unit_test(test_Read_WazuhDB_Backup_maxfiles_invalid_string), - cmocka_unit_test(test_Read_WazuhDB_Backup_maxfiles_invalid_value), - cmocka_unit_test(test_Read_WazuhDB_Backup_valid_config), - cmocka_unit_test(test_Read_WazuhDB_Backup_valid_config2), - }; - - return cmocka_run_group_tests(tests, wazuh_db_setup, wazuh_db_teardown); -} diff --git a/src/unit_tests/wazuh_db/test_wazuh_db_state.c b/src/unit_tests/wazuh_db/test_wazuh_db_state.c deleted file mode 100644 index 179922cdf18..00000000000 --- a/src/unit_tests/wazuh_db/test_wazuh_db_state.c +++ /dev/null @@ -1,741 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../wazuh_db/wdb_state.h" - -extern wdb_state_t wdb_state; - -/* setup/teardown */ - -static int test_setup(void ** state) { - wdb_state.uptime = 123456789; - wdb_state.queries_total = 856; - wdb_state.queries_breakdown.wazuhdb_queries = 212; - wdb_state.queries_breakdown.wazuhdb_breakdown.remove_queries = 212; - wdb_state.queries_breakdown.wazuhdb_breakdown.remove_time.tv_sec = 0; - wdb_state.queries_breakdown.wazuhdb_breakdown.remove_time.tv_usec = 132156; - wdb_state.queries_breakdown.agent_queries = 365; - wdb_state.queries_breakdown.agent_breakdown.sql_queries = 70; - wdb_state.queries_breakdown.agent_breakdown.remove_queries = 2; - wdb_state.queries_breakdown.agent_breakdown.begin_queries = 36; - wdb_state.queries_breakdown.agent_breakdown.commit_queries = 2; - wdb_state.queries_breakdown.agent_breakdown.close_queries = 36; - wdb_state.queries_breakdown.agent_breakdown.vacuum_queries = 8; - wdb_state.queries_breakdown.agent_breakdown.get_fragmentation_queries = 9; - wdb_state.queries_breakdown.agent_breakdown.syscheck.syscheck_queries = 0; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_file_queries = 6; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_queries = 10; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_key_queries = 11; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_value_queries = 12; - wdb_state.queries_breakdown.agent_breakdown.rootcheck.rootcheck_queries = 8; - wdb_state.queries_breakdown.agent_breakdown.sca.sca_queries = 2; - wdb_state.queries_breakdown.agent_breakdown.ciscat.ciscat_queries = 75; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_processes_queries = 2; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_packages_queries = 2; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_hotfixes_queries = 9; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_ports_queries = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_protocol_queries = 1; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_address_queries = 4; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_iface_queries = 3; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_hwinfo_queries = 5; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_osinfo_queries = 10; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.process_queries = 9; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.package_queries = 2; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.hotfix_queries = 10; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.port_queries = 16; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netproto_queries = 4; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netaddr_queries = 5; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netinfo_queries = 12; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.hardware_queries = 8; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.osinfo_queries = 1; - wdb_state.queries_breakdown.agent_breakdown.sync.dbsync_queries = 5; - wdb_state.queries_breakdown.agent_breakdown.open_calls_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.open_calls_time.tv_usec = 123456; - wdb_state.queries_breakdown.agent_breakdown.sql_time.tv_sec = 1; - wdb_state.queries_breakdown.agent_breakdown.sql_time.tv_usec = 546332; - wdb_state.queries_breakdown.agent_breakdown.remove_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.remove_time.tv_usec = 351518; - wdb_state.queries_breakdown.agent_breakdown.begin_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.begin_time.tv_usec = 313548; - wdb_state.queries_breakdown.agent_breakdown.commit_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.commit_time.tv_usec = 122313; - wdb_state.queries_breakdown.agent_breakdown.close_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.close_time.tv_usec = 156312; - wdb_state.queries_breakdown.agent_breakdown.vacuum_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.vacuum_time.tv_usec = 15555; - wdb_state.queries_breakdown.agent_breakdown.get_fragmentation_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.get_fragmentation_time.tv_usec = 16666; - wdb_state.queries_breakdown.agent_breakdown.syscheck.syscheck_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscheck.syscheck_time.tv_usec = 641231; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_file_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_file_time.tv_usec = 35121; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_time.tv_usec = 221548; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_key_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_key_time.tv_usec = 222548; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_value_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscheck.fim_registry_value_time.tv_usec = 223548; - wdb_state.queries_breakdown.agent_breakdown.rootcheck.rootcheck_time.tv_sec = 1; - wdb_state.queries_breakdown.agent_breakdown.rootcheck.rootcheck_time.tv_usec = 146684; - wdb_state.queries_breakdown.agent_breakdown.sca.sca_time.tv_sec = 2; - wdb_state.queries_breakdown.agent_breakdown.sca.sca_time.tv_usec = 351940; - wdb_state.queries_breakdown.agent_breakdown.ciscat.ciscat_time.tv_sec = 1; - wdb_state.queries_breakdown.agent_breakdown.ciscat.ciscat_time.tv_usec = 896460; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_processes_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_processes_time.tv_usec = 356110; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_packages_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_packages_time.tv_usec = 321850; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_hotfixes_time.tv_sec = 1; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_hotfixes_time.tv_usec = 513218; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_ports_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_ports_time.tv_usec= 894321; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_protocol_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_protocol_time.tv_usec= 123218; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_address_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_address_time.tv_usec = 984318; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_iface_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_network_iface_time.tv_usec = 781354; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_hwinfo_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_hwinfo_time.tv_usec = 843633; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_osinfo_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.syscollector_osinfo_time.tv_usec= 123548; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.process_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.process_time.tv_usec = 145158; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.package_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.package_time.tv_usec = 231548; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.hotfix_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.hotfix_time.tv_usec = 512180; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.port_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.port_time.tv_usec = 716460; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netproto_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netproto_time.tv_usec = 123950; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netaddr_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netaddr_time.tv_usec = 515120; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netinfo_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.netinfo_time.tv_usec = 651230; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.hardware_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.hardware_time.tv_usec = 156120; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.osinfo_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.syscollector.deprecated.osinfo_time.tv_usec = 153215; - wdb_state.queries_breakdown.agent_breakdown.sync.dbsync_time.tv_sec = 0; - wdb_state.queries_breakdown.agent_breakdown.sync.dbsync_time.tv_usec = 2315; - wdb_state.queries_breakdown.global_queries = 227; - wdb_state.queries_breakdown.global_breakdown.sql_queries = 8; - wdb_state.queries_breakdown.global_breakdown.backup_queries = 6; - wdb_state.queries_breakdown.global_breakdown.vacuum_queries = 3; - wdb_state.queries_breakdown.global_breakdown.get_fragmentation_queries = 5; - wdb_state.queries_breakdown.global_breakdown.agent.insert_agent_queries = 0; - wdb_state.queries_breakdown.global_breakdown.agent.update_agent_data_queries = 16; - wdb_state.queries_breakdown.global_breakdown.agent.update_agent_name_queries = 30; - wdb_state.queries_breakdown.global_breakdown.agent.update_keepalive_queries = 12; - wdb_state.queries_breakdown.global_breakdown.agent.update_connection_status_queries = 0; - wdb_state.queries_breakdown.global_breakdown.agent.reset_agents_connection_queries = 0; - wdb_state.queries_breakdown.global_breakdown.agent.delete_agent_queries = 20; - wdb_state.queries_breakdown.global_breakdown.agent.select_agent_name_queries = 1; - wdb_state.queries_breakdown.global_breakdown.agent.select_agent_group_queries = 0; - wdb_state.queries_breakdown.global_breakdown.agent.find_agent_queries = 1; - wdb_state.queries_breakdown.global_breakdown.agent.get_agent_info_queries = 2; - wdb_state.queries_breakdown.global_breakdown.agent.get_all_agents_queries = 1; - wdb_state.queries_breakdown.global_breakdown.agent.get_agents_by_connection_status_queries = 0; - wdb_state.queries_breakdown.global_breakdown.agent.disconnect_agents_queries = 2; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_info_get_queries = 1; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_info_set_queries = 2; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_groups_get_queries = 0; - wdb_state.queries_breakdown.global_breakdown.agent.set_agent_groups_queries = 5; - wdb_state.queries_breakdown.global_breakdown.agent.get_groups_integrity_queries = 2; - wdb_state.queries_breakdown.global_breakdown.group.insert_agent_group_queries = 0; - wdb_state.queries_breakdown.global_breakdown.group.delete_group_queries = 1; - wdb_state.queries_breakdown.global_breakdown.group.select_groups_queries = 84; - wdb_state.queries_breakdown.global_breakdown.group.find_group_queries = 10; - wdb_state.queries_breakdown.global_breakdown.belongs.select_group_belong_queries = 10; - wdb_state.queries_breakdown.global_breakdown.belongs.get_group_agent_queries = 0; - wdb_state.queries_breakdown.global_breakdown.labels.get_labels_queries = 1; - wdb_state.queries_breakdown.global_breakdown.open_calls_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.open_calls_time.tv_usec = 123456; - wdb_state.queries_breakdown.global_breakdown.sql_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.sql_time.tv_usec = 1523; - wdb_state.queries_breakdown.global_breakdown.backup_time.tv_sec = 1; - wdb_state.queries_breakdown.global_breakdown.backup_time.tv_usec = 145452; - wdb_state.queries_breakdown.global_breakdown.vacuum_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.vacuum_time.tv_usec = 11111; - wdb_state.queries_breakdown.global_breakdown.get_fragmentation_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.get_fragmentation_time.tv_usec = 22222; - wdb_state.queries_breakdown.global_breakdown.agent.insert_agent_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.insert_agent_time.tv_usec = 580960; - wdb_state.queries_breakdown.global_breakdown.agent.update_agent_data_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.update_agent_data_time.tv_usec = 10020; - wdb_state.queries_breakdown.global_breakdown.agent.update_agent_name_time.tv_sec = 2; - wdb_state.queries_breakdown.global_breakdown.agent.update_agent_name_time.tv_usec = 125048; - wdb_state.queries_breakdown.global_breakdown.agent.update_keepalive_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.update_keepalive_time.tv_usec = 12358; - wdb_state.queries_breakdown.global_breakdown.agent.update_connection_status_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.update_connection_status_time.tv_usec = 148903; - wdb_state.queries_breakdown.global_breakdown.agent.reset_agents_connection_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.reset_agents_connection_time.tv_usec = 100020; - wdb_state.queries_breakdown.global_breakdown.agent.delete_agent_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.delete_agent_time.tv_usec = 1202; - wdb_state.queries_breakdown.global_breakdown.agent.select_agent_name_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.select_agent_name_time.tv_usec = 14258; - wdb_state.queries_breakdown.global_breakdown.agent.select_agent_group_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.select_agent_group_time.tv_usec = 152300; - wdb_state.queries_breakdown.global_breakdown.agent.find_agent_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.find_agent_time.tv_usec = 78120; - wdb_state.queries_breakdown.global_breakdown.agent.get_agent_info_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.get_agent_info_time.tv_usec = 152358; - wdb_state.queries_breakdown.global_breakdown.agent.get_all_agents_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.get_all_agents_time.tv_usec = 25101; - wdb_state.queries_breakdown.global_breakdown.agent.get_agents_by_connection_status_time.tv_sec = 1; - wdb_state.queries_breakdown.global_breakdown.agent.get_agents_by_connection_status_time.tv_usec = 2000; - wdb_state.queries_breakdown.global_breakdown.agent.disconnect_agents_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.disconnect_agents_time.tv_usec= 412480; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_info_get_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_info_get_time.tv_usec = 548906; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_info_set_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_info_set_time.tv_usec = 81230; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_groups_get_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.sync_agent_groups_get_time.tv_usec = 8460; - wdb_state.queries_breakdown.global_breakdown.agent.set_agent_groups_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.set_agent_groups_time.tv_usec = 61500; - wdb_state.queries_breakdown.global_breakdown.agent.get_groups_integrity_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.agent.get_groups_integrity_time.tv_usec = 1200; - wdb_state.queries_breakdown.global_breakdown.group.insert_agent_group_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.group.insert_agent_group_time.tv_usec = 10230; - wdb_state.queries_breakdown.global_breakdown.group.delete_group_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.group.delete_group_time.tv_usec = 92200; - wdb_state.queries_breakdown.global_breakdown.group.select_groups_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.group.select_groups_time.tv_usec = 10560; - wdb_state.queries_breakdown.global_breakdown.group.find_group_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.group.find_group_time.tv_usec = 510; - wdb_state.queries_breakdown.global_breakdown.belongs.select_group_belong_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.belongs.select_group_belong_time.tv_usec = 25600; - wdb_state.queries_breakdown.global_breakdown.belongs.get_group_agent_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.belongs.get_group_agent_time.tv_usec = 12500; - wdb_state.queries_breakdown.global_breakdown.labels.get_labels_time.tv_sec = 0; - wdb_state.queries_breakdown.global_breakdown.labels.get_labels_time.tv_usec = 120025; - wdb_state.queries_breakdown.task_queries = 45; - wdb_state.queries_breakdown.task_breakdown.sql_queries = 1; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_queries = 20; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_custom_queries = 2; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_get_status_queries = 10; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_update_status_queries = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_result_queries = 2; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_cancel_tasks_queries = 4; - wdb_state.queries_breakdown.task_breakdown.tasks.set_timeout_queries = 3; - wdb_state.queries_breakdown.task_breakdown.tasks.delete_old_queries = 2; - wdb_state.queries_breakdown.task_breakdown.sql_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.sql_time.tv_usec = 56300; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_time.tv_usec = 10230; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_custom_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_custom_time.tv_usec = 52120; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_get_status_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_get_status_time.tv_usec = 156322; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_update_status_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_update_status_time.tv_usec = 123548; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_result_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_result_time.tv_usec = 12356; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_cancel_tasks_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.upgrade_cancel_tasks_time.tv_usec = 10256; - wdb_state.queries_breakdown.task_breakdown.tasks.set_timeout_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.set_timeout_time.tv_usec = 23002; - wdb_state.queries_breakdown.task_breakdown.tasks.delete_old_time.tv_sec = 0; - wdb_state.queries_breakdown.task_breakdown.tasks.delete_old_time.tv_usec = 12000; - wdb_state.queries_breakdown.mitre_queries = 2; - wdb_state.queries_breakdown.mitre_breakdown.sql_queries = 2; - wdb_state.queries_breakdown.mitre_breakdown.sql_time.tv_sec = 0; - wdb_state.queries_breakdown.mitre_breakdown.sql_time.tv_usec = 15202; - - return 0; -} - -static int test_teardown(void ** state) { - cJSON* json = *state; - cJSON_Delete(json); - return 0; -} - -/* Tests */ - -void test_wazuhdb_create_state_json(void ** state) { - - cJSON* state_json = wdb_create_state_json(); - - *state = (void *)state_json; - - assert_non_null(state_json); - - assert_int_equal(cJSON_GetObjectItem(state_json, "uptime")->valueint, 123456789); - - assert_non_null(cJSON_GetObjectItem(state_json, "metrics")); - cJSON* metrics = cJSON_GetObjectItem(state_json, "metrics"); - - assert_non_null(cJSON_GetObjectItem(metrics, "queries")); - cJSON* queries = cJSON_GetObjectItem(metrics, "queries"); - - assert_non_null(cJSON_GetObjectItem(queries, "received")); - assert_int_equal(cJSON_GetObjectItem(queries, "received")->valueint, 856); - - cJSON* received_breakdown = cJSON_GetObjectItem(queries, "received_breakdown"); - - assert_non_null(cJSON_GetObjectItem(received_breakdown, "agent")); - assert_int_equal(cJSON_GetObjectItem(received_breakdown, "agent")->valueint, 365); - - cJSON* agent_queries_breakdown = cJSON_GetObjectItem(received_breakdown, "agent_breakdown"); - - cJSON* agent_queries_db = cJSON_GetObjectItem(agent_queries_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(agent_queries_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(agent_queries_db, "sql")->valueint, 70); - assert_non_null(cJSON_GetObjectItem(agent_queries_db, "remove")); - assert_int_equal(cJSON_GetObjectItem(agent_queries_db, "remove")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(agent_queries_db, "begin")); - assert_int_equal(cJSON_GetObjectItem(agent_queries_db, "begin")->valueint, 36); - assert_non_null(cJSON_GetObjectItem(agent_queries_db, "commit")); - assert_int_equal(cJSON_GetObjectItem(agent_queries_db, "commit")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(agent_queries_db, "close")); - assert_int_equal(cJSON_GetObjectItem(agent_queries_db, "close")->valueint, 36); - assert_non_null(cJSON_GetObjectItem(agent_queries_db, "vacuum")); - assert_int_equal(cJSON_GetObjectItem(agent_queries_db, "vacuum")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(agent_queries_db, "get_fragmentation")); - assert_int_equal(cJSON_GetObjectItem(agent_queries_db, "get_fragmentation")->valueint, 9); - - cJSON* agent_queries_tables = cJSON_GetObjectItem(agent_queries_breakdown, "tables"); - - cJSON* agent_syscheck_queries = cJSON_GetObjectItem(agent_queries_tables, "syscheck"); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_queries, "syscheck")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_queries, "syscheck")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_queries, "fim_file")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_queries, "fim_file")->valueint, 6); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_queries, "fim_registry")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_queries, "fim_registry")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_queries, "fim_registry_key")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_queries, "fim_registry_key")->valueint, 11); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_queries, "fim_registry_value")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_queries, "fim_registry_value")->valueint, 12); - - cJSON* agent_rootcheck_queries = cJSON_GetObjectItem(agent_queries_tables, "rootcheck"); - assert_non_null(cJSON_GetObjectItem(agent_rootcheck_queries, "rootcheck")); - assert_int_equal(cJSON_GetObjectItem(agent_rootcheck_queries, "rootcheck")->valueint, 8); - - cJSON* agent_sca_queries = cJSON_GetObjectItem(agent_queries_tables, "sca"); - assert_non_null(cJSON_GetObjectItem(agent_sca_queries, "sca")); - assert_int_equal(cJSON_GetObjectItem(agent_sca_queries, "sca")->valueint, 2); - - cJSON* agent_ciscat_queries = cJSON_GetObjectItem(agent_queries_tables, "ciscat"); - assert_non_null(cJSON_GetObjectItem(agent_ciscat_queries, "ciscat")); - assert_int_equal(cJSON_GetObjectItem(agent_ciscat_queries, "ciscat")->valueint, 75); - - cJSON* agent_syscollector_queries = cJSON_GetObjectItem(agent_queries_tables, "syscollector"); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_processes")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_processes")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_packages")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_packages")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_hotfixes")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_hotfixes")->valueint, 9); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_ports")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_ports")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_network_protocol")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_network_protocol")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_network_address")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_network_address")->valueint, 4); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_network_iface")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_network_iface")->valueint, 3); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_hwinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_hwinfo")->valueint, 5); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_osinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries, "syscollector_osinfo")->valueint, 10); - - cJSON* agent_syscollector_queries_deprecated = cJSON_GetObjectItem(agent_syscollector_queries, "deprecated"); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "process")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "process")->valueint, 9); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "package")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "package")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "hotfix")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "hotfix")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "port")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "port")->valueint, 16); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "netproto")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "netproto")->valueint, 4); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "netaddr")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "netaddr")->valueint, 5); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "netinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "netinfo")->valueint, 12); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "hardware")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "hardware")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "osinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_queries_deprecated, "osinfo")->valueint, 1); - - cJSON* agent_sync_queries = cJSON_GetObjectItem(agent_queries_tables, "sync"); - assert_non_null(cJSON_GetObjectItem(agent_sync_queries, "dbsync")); - assert_int_equal(cJSON_GetObjectItem(agent_sync_queries, "dbsync")->valueint, 5); - - assert_non_null(cJSON_GetObjectItem(received_breakdown, "global")); - assert_int_equal(cJSON_GetObjectItem(received_breakdown, "global")->valueint, 227); - - cJSON* global_queries_breakdown = cJSON_GetObjectItem(received_breakdown, "global_breakdown"); - - cJSON* global_queries_db = cJSON_GetObjectItem(global_queries_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(global_queries_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(global_queries_db, "sql")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(global_queries_db, "backup")); - assert_int_equal(cJSON_GetObjectItem(global_queries_db, "backup")->valueint, 6); - assert_non_null(cJSON_GetObjectItem(global_queries_db, "vacuum")); - assert_int_equal(cJSON_GetObjectItem(global_queries_db, "vacuum")->valueint, 3); - assert_non_null(cJSON_GetObjectItem(global_queries_db, "get_fragmentation")); - assert_int_equal(cJSON_GetObjectItem(global_queries_db, "get_fragmentation")->valueint, 5); - - cJSON* global_queries_tables = cJSON_GetObjectItem(global_queries_breakdown, "tables"); - - cJSON* global_agent_queries_breakdown = cJSON_GetObjectItem(global_queries_tables, "agent"); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "insert-agent")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "insert-agent")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-agent-data")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-agent-data")->valueint, 16); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-agent-name")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-agent-name")->valueint, 30); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-keepalive")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-keepalive")->valueint, 12); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-connection-status")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "update-connection-status")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "reset-agents-connection")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "reset-agents-connection")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "delete-agent")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "delete-agent")->valueint, 20); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "select-agent-name")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "select-agent-name")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "select-agent-group")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "select-agent-group")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "find-agent")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "find-agent")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-agent-info")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-agent-info")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-all-agents")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-all-agents")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-agents-by-connection-status")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-agents-by-connection-status")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "disconnect-agents")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "disconnect-agents")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "sync-agent-info-get")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "sync-agent-info-get")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "sync-agent-info-set")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "sync-agent-info-set")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "sync-agent-groups-get")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "sync-agent-groups-get")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "set-agent-groups")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "set-agent-groups")->valueint, 5); - assert_non_null(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-groups-integrity")); - assert_int_equal(cJSON_GetObjectItem(global_agent_queries_breakdown, "get-groups-integrity")->valueint, 2); - - cJSON* global_group_queries_breakdown = cJSON_GetObjectItem(global_queries_tables, "group"); - assert_non_null(cJSON_GetObjectItem(global_group_queries_breakdown, "insert-agent-group")); - assert_int_equal(cJSON_GetObjectItem(global_group_queries_breakdown, "insert-agent-group")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(global_group_queries_breakdown, "delete-group")); - assert_int_equal(cJSON_GetObjectItem(global_group_queries_breakdown, "delete-group")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(global_group_queries_breakdown, "select-groups")); - assert_int_equal(cJSON_GetObjectItem(global_group_queries_breakdown, "select-groups")->valueint, 84); - assert_non_null(cJSON_GetObjectItem(global_group_queries_breakdown, "find-group")); - assert_int_equal(cJSON_GetObjectItem(global_group_queries_breakdown, "find-group")->valueint, 10); - - cJSON* global_belongs_queries_breakdown = cJSON_GetObjectItem(global_queries_tables, "belongs"); - assert_non_null(cJSON_GetObjectItem(global_belongs_queries_breakdown, "select-group-belong")); - assert_int_equal(cJSON_GetObjectItem(global_belongs_queries_breakdown, "select-group-belong")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(global_belongs_queries_breakdown, "get-group-agents")); - assert_int_equal(cJSON_GetObjectItem(global_belongs_queries_breakdown, "get-group-agents")->valueint, 0); - - cJSON* global_labels_queries_breakdown = cJSON_GetObjectItem(global_queries_tables, "labels"); - assert_non_null(cJSON_GetObjectItem(global_labels_queries_breakdown, "get-labels")); - assert_int_equal(cJSON_GetObjectItem(global_labels_queries_breakdown, "get-labels")->valueint, 1); - - assert_non_null(cJSON_GetObjectItem(received_breakdown, "mitre")); - assert_int_equal(cJSON_GetObjectItem(received_breakdown, "mitre")->valueint, 2); - - cJSON* mitre_queries_breakdown = cJSON_GetObjectItem(received_breakdown, "mitre_breakdown"); - - cJSON* mitre_queries_db = cJSON_GetObjectItem(mitre_queries_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(mitre_queries_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(mitre_queries_db, "sql")->valueint, 2); - - assert_non_null(cJSON_GetObjectItem(received_breakdown, "task")); - assert_int_equal(cJSON_GetObjectItem(received_breakdown, "task")->valueint, 45); - - cJSON* task_queries_breakdown = cJSON_GetObjectItem(received_breakdown, "task_breakdown"); - - cJSON* task_queries_db = cJSON_GetObjectItem(task_queries_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(task_queries_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(task_queries_db, "sql")->valueint, 1); - - cJSON* task_queries_tables = cJSON_GetObjectItem(task_queries_breakdown, "tables"); - - cJSON* task_tasks_queries_breakdown = cJSON_GetObjectItem(task_queries_tables, "tasks"); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade")->valueint, 20); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_custom")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_custom")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_get_status")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_get_status")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_update_status")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_update_status")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_result")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_result")->valueint, 2); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_cancel_tasks")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "upgrade_cancel_tasks")->valueint, 4); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "set_timeout")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "set_timeout")->valueint, 3); - assert_non_null(cJSON_GetObjectItem(task_tasks_queries_breakdown, "delete_old")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_queries_breakdown, "delete_old")->valueint, 2); - - assert_non_null(cJSON_GetObjectItem(received_breakdown, "wazuhdb")); - assert_int_equal(cJSON_GetObjectItem(received_breakdown, "wazuhdb")->valueint, 212); - - cJSON* wazuhdb_queries_breakdown = cJSON_GetObjectItem(received_breakdown, "wazuhdb_breakdown"); - - cJSON* wazuhdb_queries_db = cJSON_GetObjectItem(wazuhdb_queries_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(wazuhdb_queries_db, "remove")); - assert_int_equal(cJSON_GetObjectItem(wazuhdb_queries_db, "remove")->valueint, 212); - - assert_non_null(cJSON_GetObjectItem(metrics, "time")); - cJSON* time = cJSON_GetObjectItem(metrics, "time"); - - assert_non_null(cJSON_GetObjectItem(time, "execution")); - assert_int_equal(cJSON_GetObjectItem(time, "execution")->valueint, 26227); - - cJSON* execution_breakdown = cJSON_GetObjectItem(time, "execution_breakdown"); - - assert_non_null(cJSON_GetObjectItem(execution_breakdown, "agent")); - assert_int_equal(cJSON_GetObjectItem(execution_breakdown, "agent")->valueint, 18533); - - cJSON* agent_time_breakdown = cJSON_GetObjectItem(execution_breakdown, "agent_breakdown"); - - cJSON* agent_time_db = cJSON_GetObjectItem(agent_time_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "open")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "open")->valueint, 123); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "sql")->valueint, 1546); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "remove")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "remove")->valueint, 351); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "begin")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "begin")->valueint, 313); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "commit")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "commit")->valueint, 122); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "close")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "close")->valueint, 156); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "vacuum")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "vacuum")->valueint, 15); - assert_non_null(cJSON_GetObjectItem(agent_time_db, "get_fragmentation")); - assert_int_equal(cJSON_GetObjectItem(agent_time_db, "get_fragmentation")->valueint, 16); - - cJSON* agent_time_tables = cJSON_GetObjectItem(agent_time_breakdown, "tables"); - - cJSON* agent_syscheck_time = cJSON_GetObjectItem(agent_time_tables, "syscheck"); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_time, "syscheck")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_time, "syscheck")->valueint, 641); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_time, "fim_file")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_time, "fim_file")->valueint, 35); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_time, "fim_registry")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_time, "fim_registry")->valueint, 221); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_time, "fim_registry_key")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_time, "fim_registry_value")->valueint, 223); - assert_non_null(cJSON_GetObjectItem(agent_syscheck_time, "fim_registry_key")); - assert_int_equal(cJSON_GetObjectItem(agent_syscheck_time, "fim_registry_value")->valueint, 223); - - cJSON* agent_rootcheck_time = cJSON_GetObjectItem(agent_time_tables, "rootcheck"); - assert_non_null(cJSON_GetObjectItem(agent_rootcheck_time, "rootcheck")); - assert_int_equal(cJSON_GetObjectItem(agent_rootcheck_time, "rootcheck")->valueint, 1146); - - cJSON* agent_sca_time = cJSON_GetObjectItem(agent_time_tables, "sca"); - assert_non_null(cJSON_GetObjectItem(agent_sca_time, "sca")); - assert_int_equal(cJSON_GetObjectItem(agent_sca_time, "sca")->valueint, 2351); - - cJSON* agent_ciscat_time = cJSON_GetObjectItem(agent_time_tables, "ciscat"); - assert_non_null(cJSON_GetObjectItem(agent_ciscat_time, "ciscat")); - assert_int_equal(cJSON_GetObjectItem(agent_ciscat_time, "ciscat")->valueint, 1896); - - cJSON* agent_syscollector_time = cJSON_GetObjectItem(agent_time_tables, "syscollector"); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_processes")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_processes")->valueint, 356); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_packages")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_packages")->valueint, 321); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_hotfixes")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_hotfixes")->valueint, 1513); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_ports")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_ports")->valueint, 894); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_network_protocol")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_network_protocol")->valueint, 123); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_network_address")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_network_address")->valueint, 984); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_network_iface")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_network_iface")->valueint, 781); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_hwinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_hwinfo")->valueint, 843); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_osinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time, "syscollector_osinfo")->valueint, 123); - - cJSON* agent_syscollector_time_deprecated = cJSON_GetObjectItem(agent_syscollector_time, "deprecated"); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "process")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "process")->valueint, 145); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "package")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "package")->valueint, 231); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "hotfix")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "hotfix")->valueint, 512); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "port")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "port")->valueint, 716); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "netproto")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "netproto")->valueint, 123); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "netaddr")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "netaddr")->valueint, 515); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "netinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "netinfo")->valueint, 651); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "hardware")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "hardware")->valueint, 156); - assert_non_null(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "osinfo")); - assert_int_equal(cJSON_GetObjectItem(agent_syscollector_time_deprecated, "osinfo")->valueint, 153); - - cJSON* agent_sync_time = cJSON_GetObjectItem(agent_time_tables, "sync"); - assert_non_null(cJSON_GetObjectItem(agent_sync_time, "dbsync")); - assert_int_equal(cJSON_GetObjectItem(agent_sync_time, "dbsync")->valueint, 2); - - assert_non_null(cJSON_GetObjectItem(execution_breakdown, "global")); - assert_int_equal(cJSON_GetObjectItem(execution_breakdown, "global")->valueint, 7091); - - cJSON* global_time_breakdown = cJSON_GetObjectItem(execution_breakdown, "global_breakdown"); - - cJSON* global_time_db = cJSON_GetObjectItem(global_time_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(global_time_db, "open")); - assert_int_equal(cJSON_GetObjectItem(global_time_db, "open")->valueint, 123); - assert_non_null(cJSON_GetObjectItem(global_time_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(global_time_db, "sql")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(global_time_db, "backup")); - assert_int_equal(cJSON_GetObjectItem(global_time_db, "backup")->valueint, 1145); - assert_non_null(cJSON_GetObjectItem(global_time_db, "vacuum")); - assert_int_equal(cJSON_GetObjectItem(global_time_db, "vacuum")->valueint, 11); - assert_non_null(cJSON_GetObjectItem(global_time_db, "get_fragmentation")); - assert_int_equal(cJSON_GetObjectItem(global_time_db, "get_fragmentation")->valueint, 22); - - cJSON* global_time_tables = cJSON_GetObjectItem(global_time_breakdown, "tables"); - - cJSON* global_agent_time_breakdown = cJSON_GetObjectItem(global_time_tables, "agent"); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "insert-agent")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "insert-agent")->valueint, 580); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "update-agent-data")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "update-agent-data")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "update-agent-name")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "update-agent-name")->valueint, 2125); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "update-keepalive")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "update-keepalive")->valueint, 12); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "update-connection-status")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "update-connection-status")->valueint, 148); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "reset-agents-connection")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "reset-agents-connection")->valueint, 100); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "delete-agent")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "delete-agent")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "select-agent-name")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "select-agent-name")->valueint, 14); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "select-agent-group")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "select-agent-group")->valueint, 152); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "find-agent")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "find-agent")->valueint, 78); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "get-agent-info")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "get-agent-info")->valueint, 152); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "get-all-agents")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "get-all-agents")->valueint, 25); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "get-agents-by-connection-status")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "get-agents-by-connection-status")->valueint, 1002); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "disconnect-agents")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "disconnect-agents")->valueint, 412); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "sync-agent-info-get")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "sync-agent-info-get")->valueint, 548); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "sync-agent-info-set")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "sync-agent-info-set")->valueint, 81); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "sync-agent-groups-get")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "sync-agent-groups-get")->valueint, 8); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "set-agent-groups")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "set-agent-groups")->valueint, 61); - assert_non_null(cJSON_GetObjectItem(global_agent_time_breakdown, "get-groups-integrity")); - assert_int_equal(cJSON_GetObjectItem(global_agent_time_breakdown, "get-groups-integrity")->valueint, 1); - - cJSON* global_group_time_breakdown = cJSON_GetObjectItem(global_time_tables, "group"); - assert_non_null(cJSON_GetObjectItem(global_group_time_breakdown, "insert-agent-group")); - assert_int_equal(cJSON_GetObjectItem(global_group_time_breakdown, "insert-agent-group")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(global_group_time_breakdown, "delete-group")); - assert_int_equal(cJSON_GetObjectItem(global_group_time_breakdown, "delete-group")->valueint, 92); - assert_non_null(cJSON_GetObjectItem(global_group_time_breakdown, "select-groups")); - assert_int_equal(cJSON_GetObjectItem(global_group_time_breakdown, "select-groups")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(global_group_time_breakdown, "find-group")); - assert_int_equal(cJSON_GetObjectItem(global_group_time_breakdown, "find-group")->valueint, 0); - - cJSON* global_belongs_time_breakdown = cJSON_GetObjectItem(global_time_tables, "belongs"); - assert_non_null(cJSON_GetObjectItem(global_belongs_time_breakdown, "select-group-belong")); - assert_int_equal(cJSON_GetObjectItem(global_belongs_time_breakdown, "select-group-belong")->valueint, 25); - assert_non_null(cJSON_GetObjectItem(global_belongs_time_breakdown, "get-group-agents")); - assert_int_equal(cJSON_GetObjectItem(global_belongs_time_breakdown, "get-group-agents")->valueint, 12); - - cJSON* global_labels_time_breakdown = cJSON_GetObjectItem(global_time_tables, "labels"); - assert_non_null(cJSON_GetObjectItem(global_labels_time_breakdown, "get-labels")); - assert_int_equal(cJSON_GetObjectItem(global_labels_time_breakdown, "get-labels")->valueint, 120); - - assert_non_null(cJSON_GetObjectItem(execution_breakdown, "mitre")); - assert_int_equal(cJSON_GetObjectItem(execution_breakdown, "mitre")->valueint, 15); - - cJSON* mitre_time_breakdown = cJSON_GetObjectItem(execution_breakdown, "mitre_breakdown"); - - cJSON* mitre_time_db = cJSON_GetObjectItem(mitre_time_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(mitre_time_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(mitre_time_db, "sql")->valueint, 15); - - assert_non_null(cJSON_GetObjectItem(execution_breakdown, "task")); - assert_int_equal(cJSON_GetObjectItem(execution_breakdown, "task")->valueint, 456); - - cJSON* task_time_breakdown = cJSON_GetObjectItem(execution_breakdown, "task_breakdown"); - - cJSON* task_time_db = cJSON_GetObjectItem(task_time_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(task_time_db, "sql")); - assert_int_equal(cJSON_GetObjectItem(task_time_db, "sql")->valueint, 56); - - cJSON* task_time_tables = cJSON_GetObjectItem(task_time_breakdown, "tables"); - - cJSON* task_tasks_time_breakdown = cJSON_GetObjectItem(task_time_tables, "tasks"); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_custom")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_custom")->valueint, 52); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_get_status")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_get_status")->valueint, 156); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_update_status")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_update_status")->valueint, 123); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_result")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_result")->valueint, 12); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_cancel_tasks")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "upgrade_cancel_tasks")->valueint, 10); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "set_timeout")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "set_timeout")->valueint, 23); - assert_non_null(cJSON_GetObjectItem(task_tasks_time_breakdown, "delete_old")); - assert_int_equal(cJSON_GetObjectItem(task_tasks_time_breakdown, "delete_old")->valueint, 12); - - assert_non_null(cJSON_GetObjectItem(execution_breakdown, "wazuhdb")); - assert_int_equal(cJSON_GetObjectItem(execution_breakdown, "wazuhdb")->valueint, 132); - - cJSON* wazuhdb_time_breakdown = cJSON_GetObjectItem(execution_breakdown, "wazuhdb_breakdown"); - - cJSON* wazuhdb_time_db = cJSON_GetObjectItem(wazuhdb_time_breakdown, "db"); - assert_non_null(cJSON_GetObjectItem(wazuhdb_time_db, "remove")); - assert_int_equal(cJSON_GetObjectItem(wazuhdb_time_db, "remove")->valueint, 132); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test wdb_create_state_json - cmocka_unit_test_setup_teardown(test_wazuhdb_create_state_json, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb.c b/src/unit_tests/wazuh_db/test_wdb.c deleted file mode 100644 index 11c4e0c9d75..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb.c +++ /dev/null @@ -1,3239 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * March, 2021. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "wazuhdb_op.h" -#include "hash_op.h" - -#include "../wrappers/common.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/libc/string_wrappers.h" -#include "../wrappers/posix/pthread_wrappers.h" -#include "../wrappers/posix/time_wrappers.h" -#include "../wrappers/posix/stat_wrappers.h" -#include "../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/wazuh/shared/hash_op_wrappers.h" - -int wdb_execute_non_select_query(wdb_t * wdb, const char *query); -int wdb_select_from_temp_table(wdb_t * wdb); -int wdb_get_last_vacuum_data(wdb_t * wdb, int *last_vacuum_time, int *last_vacuum_value); -int wdb_execute_single_int_select_query(wdb_t * wdb, const char *query, int *value); - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -int __wrap_getuid(void) { - return mock(); -} - -/* setup/teardown */ - -int setup_wdb(void **state) { - - test_mode = 1; - - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("000",init_data->wdb->id); - os_calloc(256,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - init_data->wdb->stmt[0] = (sqlite3_stmt*)1; - *state = init_data; - return 0; -} - -int teardown_wdb(void **state) { - test_mode = 0; - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - -int wazuh_db_config_setup() { - wdb_init_conf(); - - return OS_SUCCESS; -} - -int wazuh_db_config_teardown() { - wdb_free_conf(); - - return OS_SUCCESS; -} - -/* Tests wdb_open_global */ - -void test_wdb_open_tasks_pool_success_wdb_in_pool_db_open(void **state) -{ - wdb_t *ret = NULL; - - wdb_t *node = wdb_init(WDB_TASK_NAME); - node->db = (sqlite3 *)1; - - expect_string(__wrap_wdb_pool_get_or_create, name, WDB_TASK_NAME); - will_return(__wrap_wdb_pool_get_or_create, node); - - ret = wdb_open_tasks(); - - assert_string_equal(ret->id, WDB_TASK_NAME); - assert_non_null(ret->db); - wdb_destroy(ret); -} - -void test_wdb_open_tasks_pool_success_wdb_in_pool_db_null(void **state) -{ - wdb_t *ret = NULL; - - wdb_t *node = wdb_init(WDB_TASK_NAME); - sqlite3 *db = (sqlite3 *)1; - - expect_string(__wrap_wdb_pool_get_or_create, name, WDB_TASK_NAME); - will_return(__wrap_wdb_pool_get_or_create, node); - - expect_string(__wrap_sqlite3_open_v2, filename, "queue/tasks/tasks.db"); - will_return(__wrap_sqlite3_open_v2, db); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, OS_SUCCESS); - - ret = wdb_open_tasks(); - - assert_string_equal(ret->id, WDB_TASK_NAME); - assert_non_null(ret->db); - wdb_destroy(ret); -} - -void test_wdb_open_tasks_create_error(void **state) -{ - wdb_t *ret = NULL; - wdb_t *node = wdb_init(WDB_TASK_NAME); - - expect_string(__wrap_wdb_pool_get_or_create, name, WDB_TASK_NAME); - will_return(__wrap_wdb_pool_get_or_create, node); - - expect_string(__wrap_sqlite3_open_v2, filename, "queue/tasks/tasks.db"); - will_return(__wrap_sqlite3_open_v2, NULL); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Tasks database not found, creating."); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_pool_leave); - - expect_string(__wrap_sqlite3_open_v2, filename, "queue/tasks/tasks.db"); - will_return(__wrap_sqlite3_open_v2, NULL); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); - will_return(__wrap_sqlite3_open_v2, OS_INVALID); - - will_return(__wrap_sqlite3_errmsg, "out of memory"); - expect_string(__wrap__mdebug1, formatted_msg, "Couldn't create SQLite database 'queue/tasks/tasks.db': out of memory"); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - - expect_string(__wrap__merror, formatted_msg, "Couldn't create SQLite database 'queue/tasks/tasks.db'"); - - ret = wdb_open_tasks(); - - assert_null(ret); - wdb_destroy(node); -} - -void test_wdb_open_tasks_retry_open_error(void **state) -{ - wdb_t *ret = NULL; - wdb_t *node = wdb_init(WDB_TASK_NAME); - sqlite3 *db = (sqlite3 *)1; - - expect_string(__wrap_wdb_pool_get_or_create, name, WDB_TASK_NAME); - will_return(__wrap_wdb_pool_get_or_create, node); - - expect_string(__wrap_sqlite3_open_v2, filename, "queue/tasks/tasks.db"); - will_return(__wrap_sqlite3_open_v2, NULL); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Tasks database not found, creating."); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - - // wdb_create_file ok - expect_string(__wrap_sqlite3_open_v2, filename, "queue/tasks/tasks.db"); - will_return(__wrap_sqlite3_open_v2, db); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); - will_return(__wrap_sqlite3_open_v2, OS_SUCCESS); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - will_return(__wrap_getuid, 1); - expect_string(__wrap__mdebug1, formatted_msg, "Ignoring chown when creating file from SQL."); - expect_string(__wrap_chmod, path, "queue/tasks/tasks.db"); - will_return(__wrap_chmod, 0); - - expect_string(__wrap_sqlite3_open_v2, filename, "queue/tasks/tasks.db"); - will_return(__wrap_sqlite3_open_v2, NULL); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, OS_INVALID); - - - will_return(__wrap_sqlite3_errmsg, "out of memory"); - expect_string(__wrap__merror, formatted_msg, "Can't open SQLite database 'queue/tasks/tasks.db': out of memory"); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_open_tasks(); - - assert_null(ret); - wdb_destroy(node); -} - -void test_wdb_open_global_pool_success_wdb_in_pool_db_open(void **state) -{ - wdb_t *ret = NULL; - - wdb_t *node = wdb_init(WDB_GLOB_NAME); - node->db = (sqlite3 *)1; - - expect_string(__wrap_wdb_pool_get_or_create, name, WDB_GLOB_NAME); - will_return(__wrap_wdb_pool_get_or_create, node); - - ret = wdb_open_global(); - - assert_string_equal(ret->id, WDB_GLOB_NAME); - assert_non_null(ret->db); - wdb_destroy(ret); -} - -void test_wdb_open_global_create_error(void **state) -{ - wdb_t *ret = NULL; - wdb_t *node = wdb_init(WDB_GLOB_NAME); - - expect_string(__wrap_wdb_pool_get_or_create, name, WDB_GLOB_NAME); - will_return(__wrap_wdb_pool_get_or_create, node); - - expect_string(__wrap_sqlite3_open_v2, filename, "queue/db/global.db"); - will_return(__wrap_sqlite3_open_v2, NULL); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Global database not found, creating."); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_pool_leave); - - expect_string(__wrap_sqlite3_open_v2, filename, "queue/db/global.db"); - will_return(__wrap_sqlite3_open_v2, NULL); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); - will_return(__wrap_sqlite3_open_v2, OS_INVALID); - - will_return(__wrap_sqlite3_errmsg, "out of memory"); - expect_string(__wrap__mdebug1, formatted_msg, "Couldn't create SQLite database 'queue/db/global.db': out of memory"); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - - expect_string(__wrap__merror, formatted_msg, "Couldn't create SQLite database 'queue/db/global.db'"); - - ret = wdb_open_global(); - - assert_null(ret); - wdb_destroy(node); -} - -/* Tests wdb_exec_row_stmt_multi_column */ - -void test_wdb_exec_row_stmt_multi_column_one_int(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const char* json_str = "COLUMN"; - double json_value = 10; - - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_INTEGER); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, json_str); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, json_value); - - int status = 0; - cJSON* result = wdb_exec_row_stmt_multi_column(*data->wdb->stmt, &status); - - assert_int_equal(status, SQLITE_ROW); - assert_non_null(result); - assert_string_equal(result->child->string, json_str); - assert_int_equal(result->child->valuedouble, json_value); - - cJSON_Delete(result); -} - -void test_wdb_exec_row_stmt_multi_column_multiple_int(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const int columns = 10; - char json_strs[columns][OS_SIZE_256]; - for (int column=0; column < columns; column++){ - snprintf(json_strs[column], OS_SIZE_256, "COLUMN%d",column); - } - - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, columns); - for (int column=0; column < columns; column++){ - expect_value(__wrap_sqlite3_column_type, i, column); - will_return(__wrap_sqlite3_column_type, SQLITE_INTEGER); - expect_value(__wrap_sqlite3_column_name, N, column); - will_return(__wrap_sqlite3_column_name, json_strs[column]); - expect_value(__wrap_sqlite3_column_double, iCol, column); - will_return(__wrap_sqlite3_column_double, column); - } - - int status = 0; - cJSON* result = wdb_exec_row_stmt_multi_column(*data->wdb->stmt, &status); - - assert_int_equal(status, SQLITE_ROW); - assert_non_null(result); - cJSON* json_column = NULL; - int column = 0; - cJSON_ArrayForEach(json_column, result) { - assert_string_equal(json_column->string, json_strs[column]); - assert_int_equal(json_column->valuedouble, column); - column++; - } - - cJSON_Delete(result); -} - -void test_wdb_exec_row_stmt_multi_column_one_text(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const char* json_str = "COLUMN"; - const char* json_value = "VALUE"; - - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, json_str); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, json_value); - - int status = 0; - cJSON* result = wdb_exec_row_stmt_multi_column(*data->wdb->stmt, &status); - assert_int_equal(status, SQLITE_ROW); - assert_non_null(result); - assert_string_equal(result->child->string, json_str); - assert_string_equal(result->child->valuestring, json_value); - - cJSON_Delete(result); -} - -void test_wdb_exec_row_stmt_multi_column_done(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_sqlite3_step_call(SQLITE_DONE); - - int status = 0; - cJSON* result = wdb_exec_row_stmt_multi_column(*data->wdb->stmt, &status); - - assert_null(result); - assert_int_equal(status, SQLITE_DONE); - assert_null(result); -} - -void test_wdb_exec_row_stmt_multi_column_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_sqlite3_step_call(SQLITE_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "SQL statement execution failed"); - - int status = 0; - cJSON* result = wdb_exec_row_stmt_multi_column(*data->wdb->stmt, &status); - assert_int_equal(status, SQLITE_ERROR); - assert_null(result); -} - -/* Tests wdb_exec_stmt_sized */ - -void test_wdb_exec_stmt_sized_success_single_column_string(void **state){ - test_struct_t *data = (test_struct_t *)*state; - char col_text[4][16] = { 0 }; - int status = SQLITE_ERROR; - - for (int i = 0; i < 4; ++i) { - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - snprintf(col_text[i], 16, "COL_TEXT_%d", i); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, col_text[i]); - } - - expect_sqlite3_step_call(SQLITE_DONE); - - cJSON* result = wdb_exec_stmt_sized(*data->wdb->stmt, WDB_MAX_RESPONSE_SIZE, &status, STMT_SINGLE_COLUMN); - char* ret_str = cJSON_PrintUnformatted(result); - - assert_string_equal("[\"COL_TEXT_0\",\"COL_TEXT_1\",\"COL_TEXT_2\",\"COL_TEXT_3\"]", ret_str); - assert_int_equal(status, SQLITE_DONE); - cJSON_Delete(result); - free(ret_str); -} - -void test_wdb_exec_stmt_sized_success_single_column_value(void **state){ - test_struct_t *data = (test_struct_t *)*state; - int status = SQLITE_ERROR; - - for (int i = 0; i < 4; ++i) { - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_INTEGER); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, i + 1); - } - - expect_sqlite3_step_call(SQLITE_DONE); - - cJSON* result = wdb_exec_stmt_sized(*data->wdb->stmt, WDB_MAX_RESPONSE_SIZE, &status, STMT_SINGLE_COLUMN); - char* ret_str = cJSON_PrintUnformatted(result); - - assert_string_equal("[1,2,3,4]", ret_str); - assert_int_equal(status, SQLITE_DONE); - cJSON_Delete(result); - free(ret_str); -} - -void test_wdb_exec_stmt_sized_success_multi_column(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const char* json_str = "COLUMN"; - double json_value = 10; - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_ROW); - expect_sqlite3_step_call(SQLITE_DONE); - will_return_count(__wrap_sqlite3_column_count, 1, -1); - expect_any(__wrap_sqlite3_column_type, i); - will_return_count(__wrap_sqlite3_column_type, SQLITE_INTEGER,-1); - expect_any(__wrap_sqlite3_column_name, N); - will_return_count(__wrap_sqlite3_column_name, json_str, -1); - expect_any(__wrap_sqlite3_column_double, iCol); - will_return_count(__wrap_sqlite3_column_double, json_value, -1); - - int status = 0; - cJSON* result = wdb_exec_stmt_sized(*data->wdb->stmt, WDB_MAX_RESPONSE_SIZE, &status, STMT_MULTI_COLUMN); - - assert_int_equal(status, SQLITE_DONE); - assert_non_null(result); - assert_string_equal(result->child->child->string, json_str); - assert_int_equal(result->child->child->valuedouble, json_value); - - cJSON_Delete(result); -} - -void test_wdb_exec_stmt_sized_success_limited(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const char* json_str = "COLUMN"; - double json_value = 10; - const int rows = 20; - const int max_size = 282; - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_count(SQLITE_ROW, rows); - will_return_count(__wrap_sqlite3_column_count, 1, -1); - expect_any_count(__wrap_sqlite3_column_type, i, -1); - will_return_count(__wrap_sqlite3_column_type, SQLITE_INTEGER, -1); - expect_any_count(__wrap_sqlite3_column_name, N, -1); - will_return_count(__wrap_sqlite3_column_name, json_str, -1); - expect_any_count(__wrap_sqlite3_column_double, iCol, -1); - will_return_count(__wrap_sqlite3_column_double, json_value, -1); - - int status = 0; - cJSON* result = wdb_exec_stmt_sized(*data->wdb->stmt, max_size, &status, STMT_MULTI_COLUMN); - - assert_int_equal(status, SQLITE_ROW); - assert_non_null(result); - assert_int_equal(cJSON_GetArraySize(result), rows-1); - - cJSON_Delete(result); -} - -void test_wdb_exec_stmt_sized_invalid_statement(void **state) { - expect_string(__wrap__mdebug1, formatted_msg, "Invalid SQL statement."); - - int status = 0; - cJSON* result = wdb_exec_stmt_sized(NULL, WDB_MAX_RESPONSE_SIZE, &status, STMT_MULTI_COLUMN); - - assert_int_equal(status, SQLITE_ERROR); - assert_null(result); -} - -void test_wdb_exec_stmt_sized_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "SQL statement execution failed"); - - int status = 0; - cJSON* result = wdb_exec_stmt_sized(*data->wdb->stmt, WDB_MAX_RESPONSE_SIZE, &status, STMT_MULTI_COLUMN); - - assert_int_equal(status, SQLITE_ERROR); - assert_null(result); - - cJSON_Delete(result); -} - -/* Tests wdb_exec_stmt */ - -void test_wdb_exec_stmt_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - const char* json_str = "COLUMN"; - double json_value = 10; - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_ROW); - expect_sqlite3_step_call(SQLITE_DONE); - will_return_count(__wrap_sqlite3_column_count, 1, -1); - expect_any(__wrap_sqlite3_column_type, i); - will_return_count(__wrap_sqlite3_column_type, SQLITE_INTEGER,-1); - expect_any(__wrap_sqlite3_column_name, N); - will_return_count(__wrap_sqlite3_column_name, json_str, -1); - expect_any(__wrap_sqlite3_column_double, iCol); - will_return_count(__wrap_sqlite3_column_double, json_value, -1); - - cJSON* result = wdb_exec_stmt(*data->wdb->stmt); - - assert_non_null(result); - assert_string_equal(result->child->child->string, json_str); - assert_int_equal(result->child->child->valuedouble, json_value); - - cJSON_Delete(result); -} - -void test_wdb_exec_stmt_invalid_statement(void **state) { - expect_string(__wrap__mdebug1, formatted_msg, "Invalid SQL statement."); - - cJSON* result = wdb_exec_stmt(NULL); - - assert_null(result); -} - -void test_wdb_exec_stmt_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "SQL statement execution failed"); - - cJSON* result = wdb_exec_stmt(*data->wdb->stmt); - assert_null(result); - - cJSON_Delete(result); -} - -/* Tests wdb_exec_stmt_silent */ - -void test_wdb_exec_stmt_silent_success_sqlite_done(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_sqlite3_step_call(SQLITE_DONE); - - int result = wdb_exec_stmt_silent(*data->wdb->stmt); - - assert_int_equal(result, OS_SUCCESS); -} - -void test_wdb_exec_stmt_silent_success_sqlite_row(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_sqlite3_step_call(SQLITE_ROW); - - int result = wdb_exec_stmt_silent(*data->wdb->stmt); - - assert_int_equal(result, OS_SUCCESS); -} - -void test_wdb_exec_stmt_silent_invalid(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_sqlite3_step_call(SQLITE_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "SQL statement execution failed"); - - int result = wdb_exec_stmt_silent(*data->wdb->stmt); - - assert_int_equal(result, OS_INVALID); -} - -/* Tests wdb_exec_stmt_send */ - -void test_wdb_exec_stmt_send_single_row_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int peer = 1234; - const char* json_str = "COLUMN"; - double json_value = 10; - cJSON* j_query_result = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_query_result, json_str, json_value); - char* str_query_result = cJSON_PrintUnformatted(j_query_result); - char* command_result = NULL; - os_calloc(OS_MAXSTR, sizeof(char), command_result); - - will_return(__wrap_OS_SetSendTimeout, 0); - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_any(__wrap_sqlite3_column_type, i); - will_return(__wrap_sqlite3_column_type, SQLITE_INTEGER); - expect_any(__wrap_sqlite3_column_name, N); - will_return(__wrap_sqlite3_column_name, json_str); - expect_any(__wrap_sqlite3_column_double, iCol); - will_return(__wrap_sqlite3_column_double, json_value); - expect_sqlite3_step_call(SQLITE_DONE); - - os_snprintf(command_result, OS_MAXSTR, "due %s", str_query_result); - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(command_result)); - expect_string(__wrap_OS_SendSecureTCP, msg, command_result); - will_return(__wrap_OS_SendSecureTCP, 0); - - int result = wdb_exec_stmt_send(*data->wdb->stmt, peer); - - assert_int_equal(result, OS_SUCCESS); - - cJSON_Delete(j_query_result); - os_free(str_query_result); - os_free(command_result); -} - -void test_wdb_exec_stmt_send_multiple_rows_success(void **state) { - int ROWS_RESPONSE = 100; - test_struct_t *data = (test_struct_t *)*state; - int peer = 1234; - const char* json_str = "COLUMN"; - double json_value = 10; - cJSON* j_query_result = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_query_result, json_str, json_value); - char* str_query_result = cJSON_PrintUnformatted(j_query_result); - char* command_result = NULL; - os_calloc(OS_MAXSTR, sizeof(char), command_result); - - will_return(__wrap_OS_SetSendTimeout, 0); - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_count(SQLITE_ROW, ROWS_RESPONSE); - will_return_count(__wrap_sqlite3_column_count, 1, ROWS_RESPONSE); - expect_any_count(__wrap_sqlite3_column_type, i, ROWS_RESPONSE); - will_return_count(__wrap_sqlite3_column_type, SQLITE_INTEGER, ROWS_RESPONSE); - expect_any_count(__wrap_sqlite3_column_name, N, ROWS_RESPONSE); - will_return_count(__wrap_sqlite3_column_name, json_str, ROWS_RESPONSE); - expect_any_count(__wrap_sqlite3_column_double, iCol, ROWS_RESPONSE); - will_return_count(__wrap_sqlite3_column_double, json_value, ROWS_RESPONSE); - expect_sqlite3_step_call(SQLITE_DONE); - - os_snprintf(command_result, OS_MAXSTR, "due %s", str_query_result); - expect_value_count(__wrap_OS_SendSecureTCP, sock, peer, ROWS_RESPONSE); - expect_value_count(__wrap_OS_SendSecureTCP, size, strlen(command_result), ROWS_RESPONSE); - expect_string_count(__wrap_OS_SendSecureTCP, msg, command_result, ROWS_RESPONSE); - will_return_count(__wrap_OS_SendSecureTCP, 0, ROWS_RESPONSE); - - int result = wdb_exec_stmt_send(*data->wdb->stmt, peer); - - assert_int_equal(result, OS_SUCCESS); - - cJSON_Delete(j_query_result); - os_free(str_query_result); - os_free(command_result); -} - -void test_wdb_exec_stmt_send_no_rows_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int peer = 1234; - - will_return(__wrap_OS_SetSendTimeout, 0); - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_DONE); - - int result = wdb_exec_stmt_send(*data->wdb->stmt, peer); - - assert_int_equal(result, OS_SUCCESS); -} - -void test_wdb_exec_stmt_send_row_size_limit_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int peer = 1234; - const char* json_str = "COLUMN"; - char* json_value = NULL; - os_calloc(OS_MAXSTR, sizeof(char), json_value); - memset(json_value,'A',OS_MAXSTR-1); - cJSON* j_query_result = cJSON_CreateObject(); - cJSON_AddStringToObject(j_query_result, json_str, json_value); - char* str_query_result = cJSON_PrintUnformatted(j_query_result); - - will_return(__wrap_OS_SetSendTimeout, 0); - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_any(__wrap_sqlite3_column_type, i); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_any(__wrap_sqlite3_column_name, N); - will_return(__wrap_sqlite3_column_name, json_str); - expect_any(__wrap_sqlite3_column_text, iCol); - will_return(__wrap_sqlite3_column_text, json_value); - - will_return(__wrap_sqlite3_sql, "STATEMENT"); - expect_string(__wrap__merror, formatted_msg, "SQL row response for statement STATEMENT is too big to be sent"); - - int result = wdb_exec_stmt_send(*data->wdb->stmt, peer); - - assert_int_equal(result, OS_SIZELIM); - - cJSON_Delete(j_query_result); - os_free(str_query_result); - os_free(json_value); -} - -void test_wdb_exec_stmt_send_socket_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int peer = 1234; - const char* json_str = "COLUMN"; - double json_value = 10; - cJSON* j_query_result = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_query_result, json_str, json_value); - char* str_query_result = cJSON_PrintUnformatted(j_query_result); - char* command_result = NULL; - os_calloc(OS_MAXSTR, sizeof(char), command_result); - - will_return(__wrap_OS_SetSendTimeout, 0); - - //Calling wdb_exec_row_stmt - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_any(__wrap_sqlite3_column_type, i); - will_return(__wrap_sqlite3_column_type, SQLITE_INTEGER); - expect_any(__wrap_sqlite3_column_name, N); - will_return(__wrap_sqlite3_column_name, json_str); - expect_any(__wrap_sqlite3_column_double, iCol); - will_return(__wrap_sqlite3_column_double, json_value); - - os_snprintf(command_result, OS_MAXSTR, "due %s", str_query_result); - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(command_result)); - expect_string(__wrap_OS_SendSecureTCP, msg, command_result); - will_return(__wrap_OS_SendSecureTCP, -1); - - will_return(__wrap_strerror, "error"); - expect_string(__wrap__merror, formatted_msg, "Socket 1234 error: error (0)"); - - int result = wdb_exec_stmt_send(*data->wdb->stmt, peer); - - assert_int_equal(result, OS_SOCKTERR); - - cJSON_Delete(j_query_result); - os_free(str_query_result); - os_free(command_result); -} - -void test_wdb_exec_stmt_send_timeout_set_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int peer = 1234; - - will_return(__wrap_OS_SetSendTimeout, -1); - - will_return(__wrap_strerror, "error"); - expect_string(__wrap__merror, formatted_msg, "Socket 1234 error setting timeout: error (0)"); - - int result = wdb_exec_stmt_send(*data->wdb->stmt, peer); - - assert_int_equal(result, OS_SOCKTERR); -} - -void test_wdb_exec_stmt_send_statement_invalid(void **state) { - int peer = 1234; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid SQL statement."); - - int result = wdb_exec_stmt_send(NULL, peer); - - assert_int_equal(result, OS_INVALID); -} - -/* Tests wdb_init_stmt_in_cache */ - -void test_wdb_init_stmt_in_cache_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return_always(__wrap_time, 0); - - // wdb_begin2 - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_stmt_cache - will_return(__wrap_sqlite3_reset, SQLITE_OK); - will_return(__wrap_sqlite3_clear_bindings, SQLITE_OK); - - sqlite3_stmt* result = wdb_init_stmt_in_cache(data->wdb, WDB_STMT_FIM_LOAD); - - assert_non_null(result); -} - -void test_wdb_init_stmt_in_cache_invalid_transaction(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - // wdb_begin2 - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - sqlite3_stmt* result = wdb_init_stmt_in_cache(data->wdb, 0); - - assert_null(result); -} - -void test_wdb_init_stmt_in_cache_invalid_statement(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int STR_SIZE = 48; - char error_message[STR_SIZE]; - snprintf(error_message, STR_SIZE, "DB(000) SQL statement index (%d) out of bounds", WDB_STMT_SIZE); - - will_return_always(__wrap_time, 0); - - // wdb_begin2 - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_stmt_cache - expect_string(__wrap__merror, formatted_msg, error_message); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - sqlite3_stmt* result = wdb_init_stmt_in_cache(data->wdb,WDB_STMT_SIZE); - - assert_null(result); -} - -void test_wdb_get_internal_config() { - cJSON *ret = wdb_get_internal_config(); - assert_true(cJSON_IsObject(ret)); - - cJSON* root = cJSON_GetObjectItem(ret, "wazuh_db"); - assert_true(cJSON_IsObject(root)); - - cJSON *c1 = cJSON_GetObjectItem(root, "commit_time_max"); - assert_true(cJSON_IsNumber(c1)); - cJSON *c2 = cJSON_GetObjectItem(root, "commit_time_min"); - assert_true(cJSON_IsNumber(c2)); - cJSON *c3 = cJSON_GetObjectItem(root, "open_db_limit"); - assert_true(cJSON_IsNumber(c3)); - cJSON *c4 = cJSON_GetObjectItem(root, "worker_pool_size"); - assert_true(cJSON_IsNumber(c4)); - - cJSON_Delete(ret); -} - -/* Tests wdb_get_config */ - -void test_wdb_get_config(){ - cJSON *ret = wdb_get_config(); - - cJSON *root = cJSON_GetObjectItem(ret, "wdb"); - assert_true(cJSON_IsObject(root)); - - cJSON *cfg_array = cJSON_GetObjectItem(root, "backup"); - assert_true(cJSON_IsArray(cfg_array)); - - cJSON *cfg = 0; - cJSON_ArrayForEach(cfg, cfg_array){ - assert_true(cJSON_IsObject(cfg)); - - cJSON *c0 = cJSON_GetObjectItem(cfg, "database"); - assert_true(cJSON_IsString(c0)); - cJSON *c1 = cJSON_GetObjectItem(cfg, "enabled"); - assert_true(cJSON_IsBool(c1)); - cJSON *c2 = cJSON_GetObjectItem(cfg, "interval"); - assert_true(cJSON_IsNumber(c2)); - cJSON *c3 = cJSON_GetObjectItem(cfg, "max_files"); - assert_true(cJSON_IsNumber(c3)); - } - - cJSON_Delete(ret); -} - -/* Tests wdb_check_backup_enabled */ - -void test_wdb_check_backup_enabled_enabled(void **state) -{ - bool ret = false; - wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->enabled = true; - - ret = wdb_check_backup_enabled(); - assert_true(ret); -} - -void test_wdb_check_backup_enabled_disabled(void **state) -{ - bool ret = false; - wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->enabled = false; - - ret = wdb_check_backup_enabled(); - assert_false(ret); -} - -/* Tests wdb_exec_row_stmt_single_column */ - -void test_wdb_exec_row_stmt_single_column_success_string(){ - int status = SQLITE_ERROR; - - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "COL_TEXT_0"); - - sqlite3_stmt *stmt = (sqlite3_stmt *)1; - cJSON *ret = wdb_exec_row_stmt_single_column(stmt, &status); - - char *ret_str = cJSON_PrintUnformatted(ret); - assert_string_equal("\"COL_TEXT_0\"", ret_str); - assert_int_equal(status, SQLITE_ROW); - cJSON_Delete(ret); - free(ret_str); -} - -void test_wdb_exec_row_stmt_single_column_success_number(){ - int status = SQLITE_ERROR; - - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 1); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_INTEGER); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 100); - - sqlite3_stmt *stmt = (sqlite3_stmt *)1; - cJSON *ret = wdb_exec_row_stmt_single_column(stmt, &status); - - char *ret_str = cJSON_PrintUnformatted(ret); - assert_string_equal("100", ret_str); - assert_int_equal(status, SQLITE_ROW); - cJSON_Delete(ret); - free(ret_str); -} - -void test_wdb_exec_row_stmt_single_column_invalid_stmt(){ - int *status = NULL; - expect_string(__wrap__mdebug1, formatted_msg, "Invalid SQL statement."); - - cJSON *ret = wdb_exec_row_stmt_single_column(NULL, status); - - assert_ptr_equal(status, NULL); - assert_null(ret); -} - -void test_wdb_exec_row_stmt_single_column_sql_error(void **state){ - int status = SQLITE_ERROR; - test_struct_t *data = (test_struct_t *)*state; - - expect_sqlite3_step_call(SQLITE_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "SQL statement execution failed"); - - cJSON *ret = wdb_exec_row_stmt_single_column(*data->wdb->stmt, &status); - - assert_int_equal(status, SQLITE_ERROR); - assert_null(ret); -} - -void test_wdb_finalize_all_statements(){ - const int kMaxStmt = 10; - wdb_t wdb = {0}; - - for (int i = 0; i < kMaxStmt; ++i) { wdb.stmt[i] = (sqlite3_stmt *)0xDEADBEEF; } - - struct stmt_cache_list** c = &(wdb.cache_list); - for(int i = 0; i < kMaxStmt; ++i){ - *c = calloc(1, sizeof(struct stmt_cache_list)); - (*c)->value.stmt = (sqlite3_stmt*) 0xDEADBEEF; - c = &((*c)->next); - } - - *c = 0; - - // free the prepared statements - will_return_count(__wrap_sqlite3_finalize, 1, kMaxStmt); - // free the statement cache - will_return_count(__wrap_sqlite3_finalize, 1, kMaxStmt); - - wdb_finalize_all_statements(&wdb); - - for (int i = 0; i < kMaxStmt; ++i) { assert_null(wdb.stmt[i]); } - assert_null(wdb.cache_list); -} - -/* Tests wdb_close*/ - -void test_wdb_close_no_commit_sqlerror(){ - wdb_t wdb = {0}; - wdb.id = "agent"; - - will_return(__wrap_sqlite3_close_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "mock_error"); - - expect_string(__wrap__merror, formatted_msg, "DB(agent) wdb_close(): mock_error"); - - assert_int_equal(-1, wdb_close(&wdb, 0)); -} - -void test_wdb_close_success(){ - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->id = strdup("agent"); - - test_mode = 1; - - will_return(__wrap_sqlite3_close_v2, SQLITE_OK); - - assert_int_equal(0, wdb_close(wdb, 0)); - wdb_destroy(wdb); -} - -void test_wdb_get_db_free_pages_percentage_page_count_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - os_strdup("000",wdb->id); - - // wdb_execute_single_int_select_query -> page_count - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - expect_string(__wrap__mdebug1, formatted_msg, "Error getting total_pages for '000' database."); - - assert_int_equal(OS_INVALID, wdb_get_db_free_pages_percentage(wdb)); - - os_free(wdb->db); - os_free(wdb->id); - os_free(wdb); -} - -void test_wdb_get_db_free_pages_percentage_page_free_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - os_strdup("000",wdb->id); - - // wdb_execute_single_int_select_query -> page_count - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_execute_single_int_select_query -> page_free - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - expect_string(__wrap__mdebug1, formatted_msg, "Error getting free_pages for '000' database."); - - assert_int_equal(OS_INVALID, wdb_get_db_free_pages_percentage(wdb)); - - os_free(wdb->db); - os_free(wdb->id); - os_free(wdb); -} - -void test_wdb_get_db_free_pages_percentage_success_10(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - os_strdup("000",wdb->id); - - // wdb_execute_single_int_select_query -> page_count - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_execute_single_int_select_query -> page_free - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(10, wdb_get_db_free_pages_percentage(wdb)); - - os_free(wdb->db); - os_free(wdb->id); - os_free(wdb); -} - -void test_wdb_execute_single_int_select_query_query_null(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - int value; - expect_string(__wrap__mdebug1, formatted_msg, "wdb_execute_single_int_select_query(): null query."); - - assert_int_equal(OS_INVALID, wdb_execute_single_int_select_query(wdb, NULL, &value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_execute_single_int_select_query_prepare_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - int value; - - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - assert_int_equal(OS_INVALID, wdb_execute_single_int_select_query(wdb, "query", &value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_execute_single_int_select_query_step_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - int value; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(OS_INVALID, wdb_execute_single_int_select_query(wdb, "query", &value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_execute_single_int_select_query_success_1(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - int value; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 1); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(0, wdb_execute_single_int_select_query(wdb, "query", &value)); - assert_int_equal(1, value); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_execute_non_select_query_query_null(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_execute_non_select_query(): null query."); - - assert_int_equal(OS_INVALID, wdb_execute_non_select_query(wdb, 0)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_execute_non_select_query_prepare_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - assert_int_equal(OS_INVALID, wdb_execute_non_select_query(wdb, "query")); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_execute_non_select_query_step_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_sqlite3_step_call(SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(OS_INVALID, wdb_execute_non_select_query(wdb, "query")); - - os_free(wdb); -} - -void test_wdb_execute_non_select_query_success(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(OS_SUCCESS, wdb_execute_non_select_query(wdb, "query")); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_select_from_temp_table_prepare_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - assert_int_equal(OS_INVALID, wdb_select_from_temp_table(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_select_from_temp_table_step_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(OS_INVALID, wdb_select_from_temp_table(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_select_from_temp_table_success_0(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(0, wdb_select_from_temp_table(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_select_from_temp_table_success_100(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(100, wdb_select_from_temp_table(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_db_state_create_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - // create temp table fail - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating temporary table."); - - assert_int_equal(OS_INVALID, wdb_get_db_state(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_db_state_truncate_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - // create temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // truncate table fail - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap__mdebug1, formatted_msg, "Error truncate temporary table."); - - assert_int_equal(OS_INVALID, wdb_get_db_state(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_db_state_insert_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - // create table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // truncate temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // insert temp table fail - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap__mdebug1, formatted_msg, "Error inserting into temporary table."); - - assert_int_equal(OS_INVALID, wdb_get_db_state(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_db_state_select_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - // create table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // truncate temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // insert temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // select from temp table fail - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap__mdebug1, formatted_msg, "Error in select from temporary table."); - - assert_int_equal(OS_INVALID, wdb_get_db_state(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_db_state_success_0(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - // create table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // truncate temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // insert temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // select from temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(0, wdb_get_db_state(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_db_state_success_100(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - - // create table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // truncate temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // insert temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // select from temp table success - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(100, wdb_get_db_state(wdb)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_last_vacuum_data_exec_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - int last_vacuum_time; - int last_vacuum_value; - - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - expect_string(__wrap__mdebug2, formatted_msg, "SQL: SELECT key, value FROM metadata WHERE key in ('last_vacuum_time', 'last_vacuum_value');"); - - assert_int_equal(-1, wdb_get_last_vacuum_data(wdb, &last_vacuum_time, &last_vacuum_value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_get_last_vacuum_data_ok(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - int last_vacuum_time; - int last_vacuum_value; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_time"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "1655555"); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_value"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "85"); - expect_sqlite3_step_call(SQLITE_DONE); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(0, wdb_get_last_vacuum_data(wdb, &last_vacuum_time, &last_vacuum_value)); - assert_int_equal(last_vacuum_time, 1655555); - assert_int_equal(last_vacuum_value, 85); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_update_last_vacuum_data_prepare_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - const char *last_vacuum_time = "1655555"; - const char *last_vacuum_value = "85"; - - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - assert_int_equal(-1, wdb_update_last_vacuum_data(wdb, last_vacuum_time, last_vacuum_value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_update_last_vacuum_data_step_error(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - const char *last_vacuum_time = "1655555"; - const char *last_vacuum_value = "85"; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, last_vacuum_time); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, last_vacuum_value); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(-1, wdb_update_last_vacuum_data(wdb, last_vacuum_time, last_vacuum_value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_update_last_vacuum_data_ok_done(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - const char *last_vacuum_time = "1655555"; - const char *last_vacuum_value = "85"; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, last_vacuum_time); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, last_vacuum_value); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(0, wdb_update_last_vacuum_data(wdb, last_vacuum_time, last_vacuum_value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_update_last_vacuum_data_ok_constraint(void **state) { - wdb_t *wdb = calloc(1, sizeof(wdb_t)); - wdb->db = calloc(1, sizeof(sqlite3 *)); - const char *last_vacuum_time = "1655555"; - const char *last_vacuum_value = "85"; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, last_vacuum_time); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, last_vacuum_value); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_CONSTRAINT); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(0, wdb_update_last_vacuum_data(wdb, last_vacuum_time, last_vacuum_value)); - - os_free(wdb->db); - os_free(wdb); -} - -void test_wdb_check_fragmentation_node_null(void **state) -{ - - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, NULL); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); -} - -void test_wdb_check_fragmentation_get_state_error(void **state) -{ - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - expect_string(__wrap__mdebug1, formatted_msg, "Error creating temporary table."); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting total_pages for '000' database."); - - expect_string(__wrap__merror, formatted_msg, "Couldn't get current state for the database '000'"); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_get_last_vacuum_data_error(void **state) -{ - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - expect_string(__wrap__mdebug2, formatted_msg, "SQL: SELECT key, value FROM metadata WHERE key in ('last_vacuum_time', 'last_vacuum_value');"); - - expect_string(__wrap__merror, formatted_msg, "Couldn't get last vacuum info for the database '000'"); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_commit_error(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 1; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_time"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "1655555"); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_value"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "85"); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_commit2 - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "Couldn't execute commit statement, before vacuum, for the database '000'"); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_vacuum_error(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_time"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "1655555"); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_value"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "85"); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_vacuum - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "Couldn't execute vacuum for the database '000'"); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_get_fragmentation_after_vacuum_error(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_time"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "1655555"); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_value"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "85"); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_vacuum - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time_diff, 2); - - expect_string(__wrap__mdebug1, formatted_msg, "Vacuum executed on the '000' database. Time: 2000.000 ms."); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - expect_string(__wrap__mdebug1, formatted_msg, "Error creating temporary table."); - - expect_string(__wrap__merror, formatted_msg, "Couldn't get fragmentation after vacuum for the database '000'"); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_update_last_vacuum_data_error(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_time"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "1655555"); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_value"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "85"); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_vacuum - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time_diff, 2); - - expect_string(__wrap__mdebug1, formatted_msg, "Vacuum executed on the '000' database. Time: 2000.000 ms."); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time, 0); - - // wdb_update_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "Couldn't update last vacuum info for the database '000'"); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_success_with_warning(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - expect_string(__wrap__mdebug2, formatted_msg, "No vacuum data in metadata table."); - - // wdb_vacuum - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time_diff, 2); - - expect_string(__wrap__mdebug1, formatted_msg, "Vacuum executed on the '000' database. Time: 2000.000 ms."); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time, 12); - - // wdb_update_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "12"); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "100"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap__mwarn, formatted_msg, "After vacuum, the database '000' has become just as fragmented or worse"); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_success(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - expect_string(__wrap__mdebug2, formatted_msg, "No vacuum data in metadata table."); - - // wdb_vacuum - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time_diff, 2); - - expect_string(__wrap__mdebug1, formatted_msg, "Vacuum executed on the '000' database. Time: 2000.000 ms."); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time, 12); - - // wdb_update_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "12"); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_no_vacuum_free_pages(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 4); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - expect_string(__wrap__mdebug2, formatted_msg, "No vacuum data in metadata table."); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_no_vacuum_current_fragmentation(void **state) -{ - wconfig.max_fragmentation = 80; - wconfig.free_pages_percentage = 5; - wconfig.fragmentation_threshold = 75; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 15); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - expect_string(__wrap__mdebug2, formatted_msg, "No vacuum data in metadata table."); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_no_vacuum_current_fragmentation_delta(void **state) -{ - wconfig.max_fragmentation = 100; - wconfig.free_pages_percentage = 5; - wconfig.fragmentation_threshold = 60; - wconfig.fragmentation_delta = 40; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 15); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_time"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "1655555"); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_value"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "85"); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_vacuum_first(void **state) -{ - wconfig.max_fragmentation = 100; - wconfig.free_pages_percentage = 5; - wconfig.fragmentation_threshold = 60; - wconfig.fragmentation_delta = 50; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 10); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - expect_string(__wrap__mdebug2, formatted_msg, "No vacuum data in metadata table."); - - // wdb_vacuum - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time_diff, 2); - - expect_string(__wrap__mdebug1, formatted_msg, "Vacuum executed on the '000' database. Time: 2000.000 ms."); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time, 12); - - // wdb_update_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "12"); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_check_fragmentation_vacuum_current_fragmentation_delta(void **state) -{ - wconfig.max_fragmentation = 100; - wconfig.free_pages_percentage = 5; - wconfig.fragmentation_threshold = 90; - wconfig.fragmentation_delta = 20; - // wdb_pool_keys - rb_tree * tree = rbtree_init(); - char *value = strdup("testing"); - rbtree_insert(tree, "000", value); - char** keys = rbtree_keys(tree); - - will_return(__wrap_wdb_pool_keys, keys); - - wdb_t *node = wdb_init("000"); - node->db = (sqlite3 *)1; - node->transaction = 0; - expect_string(__wrap_wdb_pool_get, name, "000"); - will_return(__wrap_wdb_pool_get, node); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 0); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_db_free_pages_percentage - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 100); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 15); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_get_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_time"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "1655555"); - expect_sqlite3_step_call(SQLITE_ROW); - will_return(__wrap_sqlite3_column_count, 2); - expect_value(__wrap_sqlite3_column_type, i, 0); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 0); - will_return(__wrap_sqlite3_column_name, "key"); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "last_vacuum_value"); - expect_value(__wrap_sqlite3_column_type, i, 1); - will_return(__wrap_sqlite3_column_type, SQLITE_TEXT); - expect_value(__wrap_sqlite3_column_name, N, 1); - will_return(__wrap_sqlite3_column_name, "value"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "70"); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // wdb_vacuum - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time_diff, 2); - - expect_string(__wrap__mdebug1, formatted_msg, "Vacuum executed on the '000' database. Time: 2000.000 ms."); - - // wdb_get_db_state - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_double, iCol, 0); - will_return(__wrap_sqlite3_column_double, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - will_return(__wrap_time, 12); - - // wdb_update_last_vacuum_data - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "12"); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_function_call(__wrap_wdb_pool_leave); - - wdb_check_fragmentation(); - - rbtree_destroy(tree); - os_free(value); - wdb_destroy(node); -} - -void test_wdb_set_synchronous_normal_null_errmsg(void ** state) { - wdb_t * wdb = wdb_init("000"); - assert_non_null(wdb); - wdb->db = (sqlite3 *)1; - - expect_string(__wrap_sqlite3_exec, sql, "PRAGMA synchronous=1;"); - will_return(__wrap_sqlite3_exec, NULL); - will_return(__wrap_sqlite3_exec, 0); - - int retval = wdb_set_synchronous_normal(wdb); - - assert_int_equal(retval, 0); - wdb_destroy(wdb); -} - -void test_wdb_set_synchronous_normal_with_errmsg(void ** state) { - wdb_t * wdb = wdb_init("000"); - assert_non_null(wdb); - wdb->db = (sqlite3 *)1; - - expect_string(__wrap_sqlite3_exec, sql, "PRAGMA synchronous=1;"); - will_return(__wrap_sqlite3_exec, "synchronous ERROR"); - will_return(__wrap_sqlite3_exec, -1); - - expect_string(__wrap__merror, formatted_msg, "Cannot set synchronous mode: 'synchronous ERROR'"); - - int result = wdb_set_synchronous_normal(wdb); - - assert_int_equal(result, -1); - wdb_destroy(wdb); -} - - -int main() { - const struct CMUnitTest tests[] = { - // wdb_open_tasks - cmocka_unit_test(test_wdb_open_tasks_pool_success_wdb_in_pool_db_open), - cmocka_unit_test(test_wdb_open_tasks_pool_success_wdb_in_pool_db_null), - cmocka_unit_test(test_wdb_open_tasks_create_error), - cmocka_unit_test(test_wdb_open_tasks_retry_open_error), - // wdb_open_global - cmocka_unit_test(test_wdb_open_global_pool_success_wdb_in_pool_db_open), - cmocka_unit_test(test_wdb_open_global_create_error), - // wdb_exec_row_stm - cmocka_unit_test_setup_teardown(test_wdb_exec_row_stmt_multi_column_one_int, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_row_stmt_multi_column_multiple_int, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_row_stmt_multi_column_one_text, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_row_stmt_multi_column_done, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_row_stmt_multi_column_error, setup_wdb, teardown_wdb), - // wdb_exec_stmt - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_invalid_statement, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_error, setup_wdb, teardown_wdb), - // wdb_exec_stmt_sized - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_sized_success_single_column_string, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_sized_success_single_column_value, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_sized_success_multi_column, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_sized_success_limited, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_sized_invalid_statement, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_sized_error, setup_wdb, teardown_wdb), - // wdb_exec_stmt_silent - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_silent_success_sqlite_done, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_silent_success_sqlite_row, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_silent_invalid, setup_wdb, teardown_wdb), - // wdb_exec_stmt_send - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_send_single_row_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_send_multiple_rows_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_send_no_rows_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_send_row_size_limit_err, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_send_socket_err, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_send_timeout_set_err, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_exec_stmt_send_statement_invalid, setup_wdb, teardown_wdb), - // wdb_init_stmt_in_cache - cmocka_unit_test_setup_teardown(test_wdb_init_stmt_in_cache_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_init_stmt_in_cache_invalid_transaction, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_init_stmt_in_cache_invalid_statement, setup_wdb, teardown_wdb), - // wdb_get_config - cmocka_unit_test_setup_teardown(test_wdb_get_config, wazuh_db_config_setup, wazuh_db_config_teardown), - // wdb_check_backup_enabled - cmocka_unit_test_setup_teardown(test_wdb_check_backup_enabled_enabled, wazuh_db_config_setup, wazuh_db_config_teardown), - cmocka_unit_test_setup_teardown(test_wdb_check_backup_enabled_disabled, wazuh_db_config_setup, wazuh_db_config_teardown), - // wdb_get_internal_config - cmocka_unit_test(test_wdb_get_internal_config), - // wdb_exec_row_stmt_single_column - cmocka_unit_test(test_wdb_exec_row_stmt_single_column_success_string), - cmocka_unit_test(test_wdb_exec_row_stmt_single_column_success_number), - cmocka_unit_test(test_wdb_exec_row_stmt_single_column_invalid_stmt), - cmocka_unit_test_setup_teardown(test_wdb_exec_row_stmt_single_column_sql_error, setup_wdb, teardown_wdb), - // wdb_finalize_all_statements - cmocka_unit_test(test_wdb_finalize_all_statements), - // wdb_close - cmocka_unit_test(test_wdb_close_no_commit_sqlerror), - cmocka_unit_test(test_wdb_close_success), - // wdb_get_db_free_pages_percentage - cmocka_unit_test(test_wdb_get_db_free_pages_percentage_page_count_error), - cmocka_unit_test(test_wdb_get_db_free_pages_percentage_page_free_error), - cmocka_unit_test(test_wdb_get_db_free_pages_percentage_success_10), - // wdb_execute_single_int_select_query - cmocka_unit_test(test_wdb_execute_single_int_select_query_query_null), - cmocka_unit_test(test_wdb_execute_single_int_select_query_prepare_error), - cmocka_unit_test(test_wdb_execute_single_int_select_query_step_error), - cmocka_unit_test(test_wdb_execute_single_int_select_query_success_1), - // wdb_execute_non_select_query - cmocka_unit_test(test_wdb_execute_non_select_query_query_null), - cmocka_unit_test(test_wdb_execute_non_select_query_prepare_error), - cmocka_unit_test(test_wdb_execute_non_select_query_step_error), - cmocka_unit_test(test_wdb_execute_non_select_query_success), - // wdb_select_from_temp_table - cmocka_unit_test(test_wdb_select_from_temp_table_prepare_error), - cmocka_unit_test(test_wdb_select_from_temp_table_step_error), - cmocka_unit_test(test_wdb_select_from_temp_table_success_0), - cmocka_unit_test(test_wdb_select_from_temp_table_success_100), - // wdb_get_db_state - cmocka_unit_test(test_wdb_get_db_state_create_error), - cmocka_unit_test(test_wdb_get_db_state_truncate_error), - cmocka_unit_test(test_wdb_get_db_state_insert_error), - cmocka_unit_test(test_wdb_get_db_state_select_error), - cmocka_unit_test(test_wdb_get_db_state_success_0), - cmocka_unit_test(test_wdb_get_db_state_success_100), - // wdb_get_last_vacuum_data - cmocka_unit_test(test_wdb_get_last_vacuum_data_exec_error), - cmocka_unit_test(test_wdb_get_last_vacuum_data_ok), - // wdb_update_last_vacuum_data - cmocka_unit_test(test_wdb_update_last_vacuum_data_prepare_error), - cmocka_unit_test(test_wdb_update_last_vacuum_data_step_error), - cmocka_unit_test(test_wdb_update_last_vacuum_data_ok_done), - cmocka_unit_test(test_wdb_update_last_vacuum_data_ok_constraint), - // wdb_check_fragmentation - cmocka_unit_test(test_wdb_check_fragmentation_node_null), - cmocka_unit_test(test_wdb_check_fragmentation_get_state_error), - cmocka_unit_test(test_wdb_check_fragmentation_get_last_vacuum_data_error), - cmocka_unit_test(test_wdb_check_fragmentation_commit_error), - cmocka_unit_test(test_wdb_check_fragmentation_vacuum_error), - cmocka_unit_test(test_wdb_check_fragmentation_get_fragmentation_after_vacuum_error), - cmocka_unit_test(test_wdb_check_fragmentation_update_last_vacuum_data_error), - cmocka_unit_test(test_wdb_check_fragmentation_success_with_warning), - cmocka_unit_test(test_wdb_check_fragmentation_success), - cmocka_unit_test(test_wdb_check_fragmentation_no_vacuum_free_pages), - cmocka_unit_test(test_wdb_check_fragmentation_no_vacuum_current_fragmentation), - cmocka_unit_test(test_wdb_check_fragmentation_no_vacuum_current_fragmentation_delta), - cmocka_unit_test(test_wdb_check_fragmentation_vacuum_first), - cmocka_unit_test(test_wdb_check_fragmentation_vacuum_current_fragmentation_delta), - // wdb_set_synchronous_normal - cmocka_unit_test(test_wdb_set_synchronous_normal_null_errmsg), - cmocka_unit_test(test_wdb_set_synchronous_normal_with_errmsg), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_agents.c b/src/unit_tests/wazuh_db/test_wdb_agents.c deleted file mode 100644 index 34206d074d0..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_agents.c +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * March, 2021. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "os_err.h" -#include "../wazuh_db/wdb.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "wazuhdb_op.h" -#include "../wazuh_db/wdb_agents.h" - -/* setup/teardown */ - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("000",init_data->wdb->id); - init_data->wdb->peer = 1234; - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - *state = init_data; - return 0; -} - -static int test_teardown(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - -/* wrappers configurations for fail/success */ - -// __wrap_wdb_exec_stmt_sized - -/** - * @brief Configure a successful call to __wrap_wdb_exec_stmt_sized - * - * @param j_array The cJSON* array to mock - * @param column_mode The expected column mode, STMT_MULTI_COLUMN or STMT_SINGLE_COLUMN - */ -void wrap_wdb_exec_stmt_sized_success_call(cJSON* j_array, int column_mode) { - expect_value(__wrap_wdb_exec_stmt_sized, max_size, WDB_MAX_RESPONSE_SIZE); - expect_value(__wrap_wdb_exec_stmt_sized, column_mode, column_mode); - will_return(__wrap_wdb_exec_stmt_sized, SQLITE_DONE); - will_return(__wrap_wdb_exec_stmt_sized, j_array); -} - -/** - * @brief Configure a failed call to __wrap_wdb_exec_stmt_sized - * - * @param column_mode The expected column mode, STMT_MULTI_COLUMN or STMT_SINGLE_COLUMN - */ -void wrap_wdb_exec_stmt_sized_failed_call(int column_mode) { - expect_value(__wrap_wdb_exec_stmt_sized, max_size, WDB_MAX_RESPONSE_SIZE); - expect_value(__wrap_wdb_exec_stmt_sized, column_mode, column_mode); - will_return(__wrap_wdb_exec_stmt_sized, SQLITE_ERROR); - will_return(__wrap_wdb_exec_stmt_sized, NULL); -} - -/* Tests wdb_agents_get_sys_osinfo */ - -void test_wdb_agents_get_sys_osinfo_statement_init_fail(void **state) { - cJSON *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_OSINFO_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - ret = wdb_agents_get_sys_osinfo(data->wdb); - - assert_null(ret); -} - -void test_wdb_agents_get_sys_osinfo_exec_stmt_fail(void **state) { - cJSON *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_OSINFO_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - ret = wdb_agents_get_sys_osinfo(data->wdb); - - assert_null(ret); -} - -void test_wdb_agents_get_sys_osinfo_success(void **state) { - cJSON *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_OSINFO_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - - ret = wdb_agents_get_sys_osinfo(data->wdb); - - assert_ptr_equal(ret, (cJSON*)1); -} - -/* Tests wdb_agents_find_package */ - -void test_wdb_agents_find_package_statement_init_fail(void **state) { - bool ret = FALSE; - test_struct_t *data = (test_struct_t *)*state; - const char* reference = "1c979289c63e6225fea818ff9ca83d9d0d25c46a"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_PROGRAM_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - ret = wdb_agents_find_package(data->wdb, reference); - - assert_false(ret); -} - -void test_wdb_agents_find_package_success_row(void **state) { - bool ret = FALSE; - test_struct_t *data = (test_struct_t *)*state; - const char* reference = "1c979289c63e6225fea818ff9ca83d9d0d25c46a"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_PROGRAM_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - - will_return_count(__wrap_sqlite3_bind_text, OS_SUCCESS, -1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, reference); - - expect_sqlite3_step_call(SQLITE_ROW); - - ret = wdb_agents_find_package(data->wdb, reference); - - assert_true(ret); -} - -void test_wdb_agents_find_package_success_done(void **state) { - bool ret = FALSE; - test_struct_t *data = (test_struct_t *)*state; - const char* reference = "1c979289c63e6225fea818ff9ca83d9d0d25c46a"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_PROGRAM_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - - will_return_count(__wrap_sqlite3_bind_text, OS_SUCCESS, -1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, reference); - - expect_sqlite3_step_call(SQLITE_DONE); - - ret = wdb_agents_find_package(data->wdb, reference); - - assert_false(ret); -} - -void test_wdb_agents_find_package_error(void **state) { - bool ret = FALSE; - test_struct_t *data = (test_struct_t *)*state; - const char* reference = "1c979289c63e6225fea818ff9ca83d9d0d25c46a"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_PROGRAM_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - - will_return_count(__wrap_sqlite3_bind_text, OS_SUCCESS, -1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, reference); - - expect_sqlite3_step_call(SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "test_sql_no_done"); - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_sql_no_done"); - - ret = wdb_agents_find_package(data->wdb, reference); - - assert_false(ret); -} - -/* wdb_agents_send_packages */ - -void test_wdb_agents_send_packages_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_PROGRAMS_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - expect_value(__wrap_wdb_exec_stmt_send, peer, 1234); - will_return(__wrap_wdb_exec_stmt_send, OS_SUCCESS); - - int ret = wdb_agents_send_packages(data->wdb); - - assert_int_equal (OS_SUCCESS, ret); -} - -void test_wdb_agents_send_packages_stmt_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_PROGRAMS_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - int ret = wdb_agents_send_packages(data->wdb); - - assert_int_equal (OS_INVALID, ret); -} - -/* wdb_agents_send_hotfixes */ - -void test_wdb_agents_send_hotfixes_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_HOTFIXES_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - expect_value(__wrap_wdb_exec_stmt_send, peer, 1234); - will_return(__wrap_wdb_exec_stmt_send, OS_SUCCESS); - - int ret = wdb_agents_send_hotfixes(data->wdb); - - assert_int_equal (OS_SUCCESS, ret); -} - -void test_wdb_agents_send_hotfixes_stmt_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_HOTFIXES_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - int ret = wdb_agents_send_hotfixes(data->wdb); - - assert_int_equal (OS_INVALID, ret); -} - -/* Tests wdb_agents_get_packages */ - -void test_wdb_agents_get_packages_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_PACKAGES); - will_return(__wrap_wdbi_check_sync_status, 1); - - /* wdb_agents_send_packages */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_PROGRAMS_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - expect_value(__wrap_wdb_exec_stmt_send, peer, 1234); - will_return(__wrap_wdb_exec_stmt_send, OS_SUCCESS); - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "SUCCESS"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_packages(data->wdb, &status_response); - - assert_int_equal (OS_SUCCESS, ret); -} - -void test_wdb_agents_get_packages_not_synced(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_PACKAGES); - will_return(__wrap_wdbi_check_sync_status, 0); - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "NOT_SYNCED"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_packages(data->wdb, &status_response); - - assert_int_equal (OS_SUCCESS, ret); -} - -void test_wdb_agents_get_packages_sync_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_PACKAGES); - will_return(__wrap_wdbi_check_sync_status, OS_INVALID); - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "ERROR"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_packages(data->wdb, &status_response); - - assert_int_equal (OS_INVALID, ret); -} - -void test_wdb_agents_get_packages_send_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_PACKAGES); - will_return(__wrap_wdbi_check_sync_status, 1); - - /* wdb_agents_send_packages */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_PROGRAMS_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - expect_value(__wrap_wdb_exec_stmt_send, peer, 1234); - will_return(__wrap_wdb_exec_stmt_send, OS_INVALID); - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "ERROR"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_packages(data->wdb, &status_response); - - assert_int_equal (OS_INVALID, ret); -} - -/* Tests wdb_agents_get_hotfixes */ - -void test_wdb_agents_get_hotfixes_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_HOTFIXES); - will_return(__wrap_wdbi_check_sync_status, 1); - - /* wdb_agents_send_hotfixes */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_HOTFIXES_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - expect_value(__wrap_wdb_exec_stmt_send, peer, 1234); - will_return(__wrap_wdb_exec_stmt_send, OS_SUCCESS); - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "SUCCESS"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_hotfixes(data->wdb, &status_response); - - assert_int_equal (OS_SUCCESS, ret); -} - -void test_wdb_agents_get_hotfixes_not_synced(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_HOTFIXES); - will_return(__wrap_wdbi_check_sync_status, 0); - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "NOT_SYNCED"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_hotfixes(data->wdb, &status_response); - - assert_int_equal (OS_SUCCESS, ret); -} - -void test_wdb_agents_get_hotfixes_sync_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_HOTFIXES); - will_return(__wrap_wdbi_check_sync_status, OS_INVALID); - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "ERROR"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_hotfixes(data->wdb, &status_response); - - assert_int_equal (OS_INVALID, ret); -} - -void test_wdb_agents_get_hotfixes_send_err(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_cJSON_CreateObject, (cJSON *)1); - - /* wdbi_check_sync_status */ - expect_value(__wrap_wdbi_check_sync_status, component, WDB_SYSCOLLECTOR_HOTFIXES); - will_return(__wrap_wdbi_check_sync_status, 1); - - /* wdb_agents_send_hotfixes */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_SYS_HOTFIXES_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); //Returning any value - expect_value(__wrap_wdb_exec_stmt_send, peer, 1234); - will_return(__wrap_wdb_exec_stmt_send, OS_INVALID); - - - expect_string(__wrap_cJSON_AddStringToObject, name, "status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "ERROR"); - will_return(__wrap_cJSON_AddStringToObject, (cJSON *)1); - - cJSON *status_response = NULL; - int ret = wdb_agents_get_hotfixes(data->wdb, &status_response); - - assert_int_equal (OS_INVALID, ret); -} - -int main() -{ - const struct CMUnitTest tests[] = { - /* Tests wdb_agents_get_sys_osinfo */ - cmocka_unit_test_setup_teardown(test_wdb_agents_get_sys_osinfo_statement_init_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_sys_osinfo_exec_stmt_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_sys_osinfo_success, test_setup, test_teardown), - /* Tests wdb_agents_find_package */ - cmocka_unit_test_setup_teardown(test_wdb_agents_find_package_statement_init_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_find_package_success_row, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_find_package_success_done, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_find_package_error, test_setup, test_teardown), - /* Tests wdb_agents_send_packages */ - cmocka_unit_test_setup_teardown(test_wdb_agents_send_packages_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_send_packages_stmt_err, test_setup, test_teardown), - /* Tests wdb_agents_send_hotfixes */ - cmocka_unit_test_setup_teardown(test_wdb_agents_send_hotfixes_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_send_hotfixes_stmt_err, test_setup, test_teardown), - /* wdb_agents_get_packages */ - cmocka_unit_test_setup_teardown(test_wdb_agents_get_packages_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_packages_not_synced, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_packages_sync_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_packages_send_err, test_setup, test_teardown), - /* Tests wdb_agents_get_hotfixes */ - cmocka_unit_test_setup_teardown(test_wdb_agents_get_hotfixes_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_hotfixes_not_synced, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_hotfixes_sync_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_agents_get_hotfixes_send_err, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_agents_helpers.c b/src/unit_tests/wazuh_db/test_wdb_agents_helpers.c deleted file mode 100644 index ca4fef17671..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_agents_helpers.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Wazuh SQLite integration - * Copyright (C) 2015, Wazuh Inc. - * February 23, 2021. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/helpers/wdb_agents_helpers.h" -#include "wazuhdb_op.h" - -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - -extern int test_mode; - -/* setup/teardown */ - -int setup_wdb_agents_helpers(void **state) { - test_mode = 1; - - return 0; -} - -int teardown_wdb_agents_helpers(void **state) { - test_mode = 0; - - return 0; -} - -/* Tests wdb_get_agent_sys_osinfo */ - -void test_wdb_get_sys_osinfo_error_sql_execution(void ** state) -{ - cJSON *ret = NULL; - int id = 1; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - //Cleaning memory - expect_function_call(__wrap_cJSON_Delete); - - ret = wdb_get_agent_sys_osinfo(id, NULL); - - assert_null(ret); -} - -void test_wdb_get_sys_osinfo_success(void ** state) -{ - cJSON *ret = NULL; - int id = 1; - - cJSON *root = __real_cJSON_CreateArray(); - cJSON *row = __real_cJSON_CreateObject(); - __real_cJSON_AddItemToArray(root, row); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - ret = wdb_get_agent_sys_osinfo(id, NULL); - - assert_ptr_equal(root, ret); - - __real_cJSON_Delete(root); -} - -int main() -{ - const struct CMUnitTest tests[] = - { - /* Tests wdb_get_agent_sys_osinfo */ - cmocka_unit_test_setup_teardown(test_wdb_get_sys_osinfo_error_sql_execution, setup_wdb_agents_helpers, teardown_wdb_agents_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_sys_osinfo_success, setup_wdb_agents_helpers, teardown_wdb_agents_helpers), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_com.c b/src/unit_tests/wazuh_db/test_wdb_com.c deleted file mode 100644 index ea87de43537..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_com.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include - -#include "../wrappers/wazuh/wazuh_db/wdb_state_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - -#include "../wazuh_db/wdb.h" - -char* wdbcom_output_builder(int error_code, const char* message, cJSON* data_json); -cJSON* wdbcom_getconfig(char* section); - -static int test_teardown(void ** state) { - char* string = *state; - os_free(string); - return 0; -} - -void test_wdbcom_output_builder(void ** state) { - int error_code = 5; - const char* message = "test msg"; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "wazuhdb"); - - char* msg = wdbcom_output_builder(error_code, message, data_json); - - *state = msg; - - assert_non_null(msg); - assert_string_equal(msg, "{\"error\":5,\"message\":\"test msg\",\"data\":{\"test1\":18,\"test2\":\"wazuhdb\"}}"); -} - -void test_wdbcom_dispatch_getstats(void ** state) { - char* request = "{\"command\":\"getstats\"}"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 18); - cJSON_AddStringToObject(data_json, "test2", "wazuhdb"); - - will_return(__wrap_wdb_create_state_json, data_json); - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":18,\"test2\":\"wazuhdb\"}}"); -} - -void test_wdbcom_dispatch_getconfig(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{\"section\":\"internal\"}}"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - cJSON* data_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(data_json, "test1", 12); - cJSON_AddStringToObject(data_json, "test2", "wazuhdb"); - - will_return(__wrap_wdb_get_internal_config, data_json); - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":0,\"message\":\"ok\",\"data\":{\"test1\":12,\"test2\":\"wazuhdb\"}}"); -} - -void test_wdbcom_dispatch_getconfig_unknown_section(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{\"section\":\"testtest\"}}"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":6,\"message\":\"Unrecognized or not configured section\",\"data\":{}}"); -} - -void test_wdbcom_dispatch_getconfig_empty_section(void ** state) { - char* request = "{\"command\":\"getconfig\",\"parameters\":{}}"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":5,\"message\":\"Empty section\",\"data\":{}}"); -} - -void test_wdbcom_dispatch_getconfig_empty_parameters(void ** state) { - char* request = "{\"command\":\"getconfig\"}"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":4,\"message\":\"Empty parameters\",\"data\":{}}"); -} - -void test_wdbcom_dispatch_unknown_command(void ** state) { - char* request = "{\"command\":\"unknown\"}"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":3,\"message\":\"Unrecognized command\",\"data\":{}}"); -} - -void test_wdbcom_dispatch_empty_command(void ** state) { - char* request = "{}"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":2,\"message\":\"Empty command\",\"data\":{}}"); -} - -void test_wdbcom_dispatch_invalid_json(void ** state) { - char* request = "unknown"; - char response[OS_MAXSTR + 1]; - *response = '\0'; - - wdbcom_dispatch(request, response); - - assert_non_null(response); - assert_string_equal(response, "{\"error\":1,\"message\":\"Invalid JSON input\",\"data\":{}}"); -} - -/* Tests wdbcom_getconfig */ - -void test_wdb_parse_get_config_internal() { - will_return(__wrap_wdb_get_internal_config, 1); - cJSON *ret = wdbcom_getconfig("internal"); - assert_int_equal(ret, 1); -} - -void test_wdb_parse_get_config_wdb() { - will_return(__wrap_wdb_get_config, 1); - cJSON *ret = wdbcom_getconfig("wdb"); - assert_int_equal(ret, 1); -} - -void test_wdb_parse_get_config_arg_null() { - cJSON *ret = wdbcom_getconfig("unknown"); - assert_int_equal(ret, NULL); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test wdbcom_output_builder - cmocka_unit_test_teardown(test_wdbcom_output_builder, test_teardown), - // Test wdbcom_dispatch - cmocka_unit_test(test_wdbcom_dispatch_getstats), - cmocka_unit_test(test_wdbcom_dispatch_getconfig), - cmocka_unit_test(test_wdbcom_dispatch_getconfig_unknown_section), - cmocka_unit_test(test_wdbcom_dispatch_getconfig_empty_section), - cmocka_unit_test(test_wdbcom_dispatch_getconfig_empty_parameters), - cmocka_unit_test(test_wdbcom_dispatch_unknown_command), - cmocka_unit_test(test_wdbcom_dispatch_empty_command), - cmocka_unit_test(test_wdbcom_dispatch_invalid_json), - /* Tests wdbcom_getconfig */ - cmocka_unit_test(test_wdb_parse_get_config_wdb), - cmocka_unit_test(test_wdb_parse_get_config_internal), - cmocka_unit_test(test_wdb_parse_get_config_arg_null), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_delta_event.c b/src/unit_tests/wazuh_db/test_wdb_delta_event.c deleted file mode 100644 index f94cf89a65a..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_delta_event.c +++ /dev/null @@ -1,960 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * March, 2021. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "wazuhdb_op.h" - -cJSON * wdb_dbsync_stmt_bind_from_json(sqlite3_stmt * stmt, int index, field_type_t type, const cJSON * value, const char * field_name, - const char * table_name, bool convert_empty_string_as_null); -const char * wdb_dbsync_translate_field(const struct field * field); -cJSON * wdb_dbsync_get_field_default(const struct field * field); - -#define ANY_PTR_VALUE 1 -#define TEST_INDEX 1 -#define HWINFO_TABLE "sys_hwinfo" - -/* wdb_dbsync_stmt_bind_from_json */ - -void test_wdb_dbsync_stmt_bind_from_json_null_inputs(void ** state) { - assert_false(wdb_dbsync_stmt_bind_from_json(NULL, TEST_INDEX, FIELD_TEXT, (cJSON *) ANY_PTR_VALUE, "", "", true)); - assert_false(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, NULL, "", "", true)); - assert_false(wdb_dbsync_stmt_bind_from_json(NULL, TEST_INDEX, FIELD_TEXT, NULL, "", "", true)); -} - -void test_wdb_dbsync_stmt_bind_from_json_value_contains_null_ok(void ** state) { - cJSON * value = cJSON_CreateNull(); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} -void test_wdb_dbsync_stmt_bind_from_json_value_contains_null_fail(void ** state) { - cJSON * value = cJSON_CreateNull(); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_ERROR); - assert_false(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} -void test_wdb_dbsync_stmt_bind_from_json_string_to_text_empty_canbenull_ok(void ** state) { - cJSON * value = cJSON_CreateString(""); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} -void test_wdb_dbsync_stmt_bind_from_json_string_to_text_empty_canbenull_err(void ** state) { - cJSON * value = cJSON_CreateString(""); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_ERROR); - assert_false(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_text_not_empty_canbenull_err(void ** state) { - cJSON * value = cJSON_CreateNull(); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_ERROR); - assert_false(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} -void test_wdb_dbsync_stmt_bind_from_json_string_to_text_not_empty_cannotbenull_ok(void ** state) { - cJSON * value = cJSON_CreateString("test string"); - expect_value(__wrap_sqlite3_bind_text, pos, TEST_INDEX); - expect_string(__wrap_sqlite3_bind_text, buffer, "test string"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_integer_to_text_ok(void ** state) { - cJSON * value = cJSON_CreateNumber(12345); - expect_value(__wrap_sqlite3_bind_text, pos, TEST_INDEX); - expect_string(__wrap_sqlite3_bind_text, buffer, "12345"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_real_to_text_ok(void ** state) { - cJSON * value = cJSON_CreateNumber(3.141592); - expect_value(__wrap_sqlite3_bind_text, pos, TEST_INDEX); - expect_string(__wrap_sqlite3_bind_text, buffer, "3.141592"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_TEXT, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_integer_ok(void ** state) { - cJSON * value = cJSON_CreateString("12345"); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 12345); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_integer_err_conversion(void ** state) { - cJSON * value = cJSON_CreateString("10Hz"); - assert_false( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_integer_err_stmt(void ** state) { - cJSON * value = cJSON_CreateString("12345"); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 12345); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - assert_false( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_integer_to_integer_ok(void ** state) { - cJSON * value = cJSON_CreateNumber(12345); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 12345); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_integer_to_integer_err_stmt(void ** state) { - cJSON * value = cJSON_CreateNumber(12345); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 12345); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - assert_false( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_real_to_integer_ok(void ** state) { - cJSON * value = cJSON_CreateNumber(3.14156); - expect_value(__wrap_sqlite3_bind_int, pos, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, index, 3.14156); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - assert_false( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_long_ok(void ** state) { - cJSON * value = cJSON_CreateString("123456789"); - expect_value(__wrap_sqlite3_bind_int64, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int64, value, 123456789); - will_return(__wrap_sqlite3_bind_int64, SQLITE_OK); - assert_true( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER_LONG, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_long_err(void ** state) { - cJSON * value = cJSON_CreateString("123456789Hz"); - assert_false( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER_LONG, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_long_err_stmt(void ** state) { - cJSON * value = cJSON_CreateString("123456789"); - expect_value(__wrap_sqlite3_bind_int64, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int64, value, 123456789); - will_return(__wrap_sqlite3_bind_int64, SQLITE_ERROR); - assert_false( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER_LONG, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_integer_to_long(void ** state) { - cJSON * value = cJSON_CreateNumber(123456789); - expect_value(__wrap_sqlite3_bind_int64, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int64, value, 123456789); - will_return(__wrap_sqlite3_bind_int64, SQLITE_OK); - assert_true( - wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER_LONG, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_real_ok(void ** state) { - cJSON * value = cJSON_CreateString("3.141592"); - expect_value(__wrap_sqlite3_bind_double, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_double, value, 3.141592); - will_return(__wrap_sqlite3_bind_double, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_REAL, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_string_to_real_err(void ** state) { - cJSON * value = cJSON_CreateString("3.141592"); - expect_value(__wrap_sqlite3_bind_double, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_double, value, 3.141592); - will_return(__wrap_sqlite3_bind_double, SQLITE_ERROR); - assert_false(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_REAL, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_integer_to_real_ok(void ** state) { - cJSON * value = cJSON_CreateNumber(12345); - expect_value(__wrap_sqlite3_bind_double, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_double, value, 12345); - will_return(__wrap_sqlite3_bind_double, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_REAL, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_from_json_integer_to_real_err(void ** state) { - cJSON * value = cJSON_CreateNumber(12345); - expect_value(__wrap_sqlite3_bind_double, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_double, value, 12345); - will_return(__wrap_sqlite3_bind_double, SQLITE_ERROR); - assert_false(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_REAL, value, "", "", true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_cpu_mhz_from_negative_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(-1); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_REAL, value, "cpu_mhz", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_cpu_cores_from_negative_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(-1); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "cpu_cores", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_free_from_negative_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(-1); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_free", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_total_from_negative_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(-1); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_total", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_negative_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(-1); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_usage", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_cpu_mhz_from_zero_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(0); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_REAL, value, "cpu_mhz", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_cpu_cores_from_zero_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(0); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "cpu_cores", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_free_from_zero_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(0); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_free", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_total_from_zero_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(0); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_total", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_zero_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(0); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_usage", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_over_onehundred_value_to_null (void **state) { - cJSON * value = cJSON_CreateNumber(101); - expect_value(__wrap_sqlite3_bind_null, index, TEST_INDEX); - will_return(__wrap_sqlite3_bind_null, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_usage", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_cpu_mhz_from_valid_value_to_number (void **state) { - cJSON * value = cJSON_CreateNumber(100); - expect_value(__wrap_sqlite3_bind_double, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_double, value, 100); - will_return(__wrap_sqlite3_bind_double, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_REAL, value, "cpu_mhz", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_cpu_cores_from_valid_value_to_number (void **state) { - cJSON * value = cJSON_CreateNumber(100); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 100); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "cpu_cores", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_free_from_valid_value_to_number (void **state) { - cJSON * value = cJSON_CreateNumber(100); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 100); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_free", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_total_from_valid_value_to_number (void **state) { - cJSON * value = cJSON_CreateNumber(100); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 100); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_total", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -void test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_valid_value_to_number (void **state) { - cJSON * value = cJSON_CreateNumber(100); - expect_value(__wrap_sqlite3_bind_int, index, TEST_INDEX); - expect_value(__wrap_sqlite3_bind_int, value, 100); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - assert_true(wdb_dbsync_stmt_bind_from_json((sqlite3_stmt *) ANY_PTR_VALUE, TEST_INDEX, FIELD_INTEGER, value, "ram_usage", HWINFO_TABLE, true)); - cJSON_Delete(value); -} - -/* wdb_upsert_dsync */ - -void test_wdb_upsert_dbsync_err(void ** state) { - assert_false(wdb_upsert_dbsync(NULL, (struct kv *) ANY_PTR_VALUE, (cJSON *) ANY_PTR_VALUE)); - assert_false(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, NULL, (cJSON *) ANY_PTR_VALUE)); - assert_false(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, (struct kv *) ANY_PTR_VALUE, NULL)); -} - -void test_wdb_upsert_dbsync_bad_cache(void ** state) { - struct column_list const TEST_FIELDS[] = { - {.value = {FIELD_INTEGER, 1, true, false, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, false, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - {.value = {FIELD_INTEGER, 3, true, false, NULL, "test_3", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - will_return(__wrap_wdb_get_cache_stmt, NULL); - expect_string(__wrap__merror, formatted_msg, DB_CACHE_NULL_STMT); - assert_false(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, (cJSON *) ANY_PTR_VALUE)); -} - -void test_wdb_upsert_dbsync_stmt_nok(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234,\"test_4\":\"value_4\"}"); - wdb_t db = {.id = "test-db"}; - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - expect_string(__wrap__merror, formatted_msg, - "(5216): DB(test-db) Could not bind delta field 'test_1' from 'table_origin_name' scan."); - assert_false(wdb_upsert_dbsync(&db, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_upsert_dbsync_field_stmt_nok(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234,\"test_4\":\"value_4\"}"); - wdb_t db = {.id = "test-db"}; - - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_2"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_4"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - // Not PKs or Aux fields - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_4"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - expect_string(__wrap__merror, formatted_msg, - "(5216): DB(test-db) Could not bind delta field 'test_4' from 'table_origin_name' scan."); - assert_false(wdb_upsert_dbsync(&db, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_upsert_dbsync_step_nok(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234,\"test_4\":\"value_4\"}"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_2"); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_4"); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 0); - // Not PKs or Aux fields - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_4"); - will_return(__wrap_wdb_step, SQLITE_ERROR); - assert_false(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_upsert_dbsync_ok(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234,\"test_4\":\"value_4\"}"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_2"); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_4"); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 0); - // Not PKs or Aux fields - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_4"); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_upsert_dbsync_default_regular_field_canbenull(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234}"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return_always(__wrap_sqlite3_bind_null, SQLITE_OK); - - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_2"); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - expect_value(__wrap_sqlite3_bind_null, index, 4); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 0); - // Not PKs or Aux fields - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_upsert_dbsync_default_regular_field_cannotbenull(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, false}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234}"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_2"); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 0); - // Not PKs or Aux fields - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_upsert_dbsync_packages_not_present_pk_field (void **state) { - struct column_list const TEST_FIELDS[] = { - // PKs. - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - { .value = { FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, false}, .next = &TEST_FIELDS[2] }, - // Regular field. - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"packages", "sys_programs", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_3\":1234}"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - // Not PKs or Aux fields - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_upsert_dbsync_packages_null_pk_field (void **state) { - struct column_list const TEST_FIELDS[] = { - // PKs. - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - { .value = { FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, false}, .next = &TEST_FIELDS[2] }, - // Regular field. - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"packages", "sys_programs", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":null,\"test_3\":1234}"); - will_return_always(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - // Not PKs or Aux fields - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 1234); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_upsert_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -// -// wdb_delete_dbsync -// - -void test_wdb_delete_dbsync_err(void ** state) { - assert_false(wdb_delete_dbsync(NULL, (struct kv *) ANY_PTR_VALUE, (cJSON *) ANY_PTR_VALUE)); - assert_false(wdb_delete_dbsync((wdb_t *) ANY_PTR_VALUE, NULL, (cJSON *) ANY_PTR_VALUE)); - assert_false(wdb_delete_dbsync((wdb_t *) ANY_PTR_VALUE, (struct kv *) ANY_PTR_VALUE, NULL)); -} - -void test_wdb_delete_dbsync_bad_cache(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - will_return(__wrap_wdb_get_cache_stmt, NULL); - expect_string(__wrap__merror, formatted_msg, DB_CACHE_NULL_STMT); - assert_false(wdb_delete_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, (cJSON *) ANY_PTR_VALUE)); -} - -void test_wdb_delete_dbsync_step_nok(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234,\"test_4\":\"value_4\"}"); - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_2"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_step, SQLITE_ERROR); - assert_false(wdb_delete_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_delete_dbsync_stmt_nok(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234,\"test_4\":\"value_4\"}"); - wdb_t db = {.id = "test-db"}; - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - expect_string(__wrap__merror, formatted_msg, - "(5216): DB(test-db) Could not bind delta field 'test_1' from 'table_origin_name' scan."); - assert_false(wdb_delete_dbsync(&db, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_delete_dbsync_ok(void ** state) { - struct column_list const TEST_FIELDS[] = { - // PKs - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - {.value = {FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, true}, .next = &TEST_FIELDS[2]}, - // Regular fields - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = &TEST_FIELDS[3]}, - {.value = {FIELD_TEXT, 5, false, false, NULL, "test_4", {.text = ""}, true}, .next = &TEST_FIELDS[4]}, - // Old values - {.value = {FIELD_INTEGER, 6, true, false, NULL, "test_5", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"table_origin_name", "table_target_name", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":\"value_2\",\"test_3\":1234,\"test_4\":\"value_4\"}"); - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "value_2"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_delete_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_delete_dbsync_packages_not_present_pk_field (void **state) { - struct column_list const TEST_FIELDS[] = { - // PKs. - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - { .value = { FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, false}, .next = &TEST_FIELDS[2] }, - // Regular field. - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"packages", "sys_programs", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_3\":1234}"); - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_delete_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -void test_wdb_delete_dbsync_packages_null_pk_field (void **state) { - struct column_list const TEST_FIELDS[] = { - // PKs. - {.value = {FIELD_INTEGER, 1, false, true, NULL, "test_1", {.integer = 0}, true}, .next = &TEST_FIELDS[1]}, - { .value = { FIELD_TEXT, 2, false, true, NULL, "test_2", {.text = ""}, false}, .next = &TEST_FIELDS[2] }, - // Regular field. - {.value = {FIELD_INTEGER, 3, false, false, NULL, "test_3", {.integer = 0}, true}, .next = NULL}, - }; - - struct kv const TEST_TABLE = {"packages", "sys_programs", false, TEST_FIELDS}; - - cJSON * delta = cJSON_Parse("{\"test_1\":4321,\"test_2\":null,\"test_3\":1234}"); - will_return(__wrap_wdb_get_cache_stmt, (sqlite3_stmt *) ANY_PTR_VALUE); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 4321); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_step, SQLITE_DONE); - assert_true(wdb_delete_dbsync((wdb_t *) ANY_PTR_VALUE, &TEST_TABLE, delta)); - cJSON_Delete(delta); -} - -/* wdb_dbsync_get_field_default */ - -void test_wdb_dbsync_get_field_default_null(void ** state) { assert_null(wdb_dbsync_get_field_default(NULL)); } - -void test_wdb_dbsync_get_field_default_text(void ** state) { - struct field test_field = {.type = FIELD_TEXT, .default_value.text = "test"}; - cJSON * retval = wdb_dbsync_get_field_default(&test_field); - assert_non_null(retval); - assert_string_equal(cJSON_GetStringValue(retval), "test"); - cJSON_Delete(retval); -} - -void test_wdb_dbsync_get_field_default_invalid_type(void ** state) { - struct field test_field = {.type = (field_type_t) 1234, .default_value.text = "test"}; - expect_string(__wrap__mdebug2, formatted_msg, "Invalid syscollector field type: 1234"); - assert_null(wdb_dbsync_get_field_default(&test_field)); -} - -void test_wdb_dbsync_get_field_default_integer(void ** state) { - struct field test_field = {.type = FIELD_INTEGER, .default_value.integer = 1234}; - cJSON * retval = wdb_dbsync_get_field_default(&test_field); - assert_non_null(retval); - assert_int_equal(retval->valueint, 1234); - cJSON_Delete(retval); -} - -void test_wdb_dbsync_get_field_default_real(void ** state) { - struct field test_field = {.type = FIELD_REAL, .default_value.real = 3.14159265}; - cJSON * retval = wdb_dbsync_get_field_default(&test_field); - assert_non_null(retval); - assert_float_equal(retval->valuedouble, 3.14159265, 0.001); - cJSON_Delete(retval); -} - -void test_wdb_dbsync_get_field_default_long(void ** state) { - struct field test_field = {.type = FIELD_INTEGER_LONG, .default_value.integer_long = LONG_MAX}; - cJSON * retval = wdb_dbsync_get_field_default(&test_field); - assert_non_null(retval); - assert_float_equal(retval->valuedouble, LONG_MAX, 0.001); - cJSON_Delete(retval); -} - -/* wdb_dbsync_translate_field */ - -void test_wdb_dbsync_translate_field_not_translated(void ** state) { - struct field test_field = {.source_name = NULL, .target_name = "db_field_name"}; - assert_string_equal(wdb_dbsync_translate_field(&test_field), "db_field_name"); -} - -void test_wdb_dbsync_translate_field_translated(void ** state) { - struct field test_field = {.source_name = "delta_field_name", .target_name = "db_field_name"}; - assert_string_equal(wdb_dbsync_translate_field(&test_field), "delta_field_name"); -} - -int main() { - const struct CMUnitTest tests[] = { - /* wdb_dbsync_get_field_default */ - cmocka_unit_test(test_wdb_dbsync_get_field_default_null), - cmocka_unit_test(test_wdb_dbsync_get_field_default_text), - cmocka_unit_test(test_wdb_dbsync_get_field_default_integer), - cmocka_unit_test(test_wdb_dbsync_get_field_default_real), - cmocka_unit_test(test_wdb_dbsync_get_field_default_long), - cmocka_unit_test(test_wdb_dbsync_get_field_default_invalid_type), - /* wdb_dbsync_translate_field */ - cmocka_unit_test(test_wdb_dbsync_translate_field_not_translated), - cmocka_unit_test(test_wdb_dbsync_translate_field_translated), - /* wdb_dbsync_stmt_bind_from_json */ - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_null_inputs), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_value_contains_null_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_value_contains_null_fail), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_text_empty_canbenull_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_text_empty_canbenull_err), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_text_not_empty_canbenull_err), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_text_not_empty_cannotbenull_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_integer_to_text_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_real_to_text_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_integer_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_integer_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_integer_err_conversion), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_integer_err_stmt), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_integer_to_integer_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_integer_to_integer_err_stmt), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_real_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_real_err), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_integer_to_real_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_integer_to_real_err), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_long_err_stmt), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_long_ok), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_string_to_long_err), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_from_json_integer_to_long), - // wdb_dbsync_stmt_bind_from_json for hwinfo - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_cpu_mhz_from_negative_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_cpu_cores_from_negative_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_free_from_negative_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_total_from_negative_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_negative_value_to_null), - - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_cpu_mhz_from_zero_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_cpu_cores_from_zero_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_free_from_zero_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_total_from_zero_value_to_null), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_zero_value_to_null), - - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_over_onehundred_value_to_null), - - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_cpu_mhz_from_valid_value_to_number), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_cpu_cores_from_valid_value_to_number), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_free_from_valid_value_to_number), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_total_from_valid_value_to_number), - cmocka_unit_test(test_wdb_dbsync_stmt_bind_hwinfo_ram_usage_from_valid_value_to_number), - /* wdb_upsert_dbsync */ - cmocka_unit_test(test_wdb_upsert_dbsync_err), - cmocka_unit_test(test_wdb_upsert_dbsync_bad_cache), - cmocka_unit_test(test_wdb_upsert_dbsync_stmt_nok), - cmocka_unit_test(test_wdb_upsert_dbsync_field_stmt_nok), - cmocka_unit_test(test_wdb_upsert_dbsync_step_nok), - cmocka_unit_test(test_wdb_upsert_dbsync_ok), - cmocka_unit_test(test_wdb_upsert_dbsync_default_regular_field_canbenull), - cmocka_unit_test(test_wdb_upsert_dbsync_default_regular_field_cannotbenull), - cmocka_unit_test(test_wdb_upsert_dbsync_packages_not_present_pk_field), - cmocka_unit_test(test_wdb_upsert_dbsync_packages_null_pk_field), - /* wdb_delete_dbsync */ - cmocka_unit_test(test_wdb_delete_dbsync_err), cmocka_unit_test(test_wdb_delete_dbsync_bad_cache), - cmocka_unit_test(test_wdb_delete_dbsync_step_nok), cmocka_unit_test(test_wdb_delete_dbsync_ok), - cmocka_unit_test(test_wdb_delete_dbsync_stmt_nok), - cmocka_unit_test(test_wdb_delete_dbsync_packages_not_present_pk_field), - cmocka_unit_test(test_wdb_delete_dbsync_packages_null_pk_field), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_fim.c b/src/unit_tests/wazuh_db/test_wdb_fim.c deleted file mode 100644 index f711f3654f8..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_fim.c +++ /dev/null @@ -1,801 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../headers/shared.h" - -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" - -static const char *VALID_ENTRY = "{\"path\":\"/test\",\"timestamp\":10,\"version\":2,\"attributes\":{\"type\":\"file\"}}"; -static const char *VALUE_V3_ENTRY = "{\"arch\":\"[x32]\",\"attributes\":{\"checksum\":\"920b517a949aec0a6fa91b0556f0a60503058fbb\",\ - \"hash_md5\":\"d41d8cd98f00b204e9800998ecf8427e\",\"hash_sha1\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\ - \"hash_sha256\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"size\":3221225472,\ - \"type\":\"registry_value\",\"value_type\":\"REG_UNKNOWN\"},\"index\":\"00a7ee53218b25b5364c8773f37a38c93eae3880\",\ - \"path\":\"HKEY_LOCAL_MACHINE\\\\System\\\\TEST\\\\key\",\ - \"timestamp\":1645981428,\"value_name\":\"test_name\",\"version\":3}"; -static const char *KEY_V3_ENTRY = "{\"arch\":\"[x32]\",\"attributes\":{\"checksum\":\"6853b29eef33ff39d8b63911673cf7b078f95485\",\ - \"gid\":\"0\",\"group_name\":\"SYSTEM\",\"mtime\":1645882878,\"perm\":\"perm_json\",\ - \"type\":\"registry_key\",\"uid\":\"0\",\"user_name\":\"Administradores\"},\ - \"index\":\"ff03d79932df0148efa6a066552badf25ea9c466\",\ - \"path\":\"HKEY_LOCAL_MACHINE\\\\System\\\\TEST\\\\key\",\ - \"timestamp\":1645981428,\"version\":3}"; - -#define BASE_WIN_ALLOWED_ACE \ - "[" \ - "\"delete\"," \ - "\"read_control\"," \ - "\"write_dac\"," \ - "\"write_owner\"," \ - "\"synchronize\"," \ - "\"read_data\"," \ - "\"write_data\"," \ - "\"append_data\"," \ - "\"read_ea\"," \ - "\"write_ea\"," \ - "\"execute\"," \ - "\"read_attributes\"," \ - "\"write_attributes\"" \ - "]" - -#define BASE_WIN_DENIED_ACE \ - "[" \ - "\"read_control\"," \ - "\"synchronize\"," \ - "\"read_data\"," \ - "\"read_ea\"," \ - "\"execute\"," \ - "\"read_attributes\"" \ - "]" - -#define BASE_WIN_ACE \ - "{" \ - "\"name\": \"Users\"," \ - "\"allowed\": " BASE_WIN_ALLOWED_ACE "," \ - "\"denied\": " BASE_WIN_DENIED_ACE "}" - -#define BASE_WIN_SID "S-1-5-32-636" - -static cJSON *create_win_permissions_object() { - static const char *const BASE_WIN_PERMS = "{\"" BASE_WIN_SID "\": " BASE_WIN_ACE "}"; - return cJSON_Parse(BASE_WIN_PERMS); -} - -typedef enum { PERM_JSON = 0, PERM_STRING = 1 } perm_format_t; - -#define prepare_valid_entry(inode) _prepare_valid_entry(inode, "yes", PERM_STRING) -#define prepare_valid_entry_json(inode, perm) _prepare_valid_entry(inode, perm, PERM_JSON) - -static cJSON *_prepare_valid_entry(sqlite3_int64 inode, void *perm, perm_format_t perm_format) { - cJSON* data = cJSON_Parse(VALID_ENTRY); - cJSON *object = cJSON_CreateObject(); - - cJSON_AddItemToObject(object, "size", cJSON_CreateNumber(3221225472)); - cJSON_AddItemToObject(object, "mtime", cJSON_CreateNumber(10)); - cJSON_AddItemToObject(object, "inode", cJSON_CreateNumber(inode)); - cJSON_AddItemToObject(object, "type", cJSON_CreateString("file")); - if (perm_format == PERM_JSON) { - cJSON_AddItemToObject(object, "perm", perm); - } else if (perm_format == PERM_STRING) { - cJSON_AddItemToObject(object, "perm", cJSON_CreateString(perm)); - } else { - fail_msg("Invalid format for permission (%d)", perm_format); - } - cJSON_AddItemToObject(object, "uid", cJSON_CreateString("00000")); - cJSON_AddItemToObject(object, "gid", cJSON_CreateString("AAAAA")); - cJSON_AddItemToObject(object, "hash_md5", cJSON_CreateString("AAAA23BCD1113A")); - cJSON_AddItemToObject(object, "hash_sha1", cJSON_CreateString("AAAA23BCD1113A")); - cJSON_AddItemToObject(object, "user_name", cJSON_CreateString("user")); - cJSON_AddItemToObject(object, "group_name", cJSON_CreateString("group")); - cJSON_AddItemToObject(object, "hash_sha256", cJSON_CreateString("AAAA23BCD1113AASDASDASD")); - cJSON_AddItemToObject(object, "symbolic_path", cJSON_CreateString("/path/second-path")); - cJSON_AddItemToObject(object, "checksum", cJSON_CreateString("GGGGGGGGGGGG")); - cJSON_AddItemToObject(object, "attributes", cJSON_CreateString("readonly")); - - cJSON_ReplaceItemInObject(data, "attributes", object); - - return data; -} - -/* expect functions */ -#define expect_wdb_fim_insert_entry2_success(inode) _expect_wdb_fim_insert_entry2_success(inode, "yes") -#define expect_wdb_fim_insert_entry2_perm_success(inode, perm) _expect_wdb_fim_insert_entry2_success(inode, perm) - -void _expect_wdb_fim_insert_entry2_success(sqlite3_int64 inode, const char *const perm) { - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "/test", 1); - expect_sqlite3_bind_text_call(2, "file", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, NULL, 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "/test", 1); - - expect_sqlite3_bind_int64_call(4, 3221225472, 1); - expect_sqlite3_bind_int_call(12, 10, 1); - expect_sqlite3_bind_int64_call(13, inode, 1); - - expect_sqlite3_bind_text_call(5, perm, 1); - expect_sqlite3_bind_text_call(6, "00000", 1); - expect_sqlite3_bind_text_call(7, "AAAAA", 1); - expect_sqlite3_bind_text_call(8, "AAAA23BCD1113A", 1); - expect_sqlite3_bind_text_call(9, "AAAA23BCD1113A", 1); - expect_sqlite3_bind_text_call(10, "user", 1); - expect_sqlite3_bind_text_call(11, "group", 1); - expect_sqlite3_bind_text_call(14, "AAAA23BCD1113AASDASDASD", 1); - expect_sqlite3_bind_text_call(16, "/path/second-path", 1); - expect_sqlite3_bind_text_call(17, "GGGGGGGGGGGG", 1); - expect_sqlite3_bind_text_call(15, "readonly", 1); - - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -/* setup/teardown */ -static int setup_wdb_t(void **state) { - wdb_t *data = calloc(1, sizeof(wdb_t)); - - if(!data) { - return -1; - } - - data->id = strdup("000"); - - *state = data; - - return 0; -} - -static int teardown_wdb_t(void **state) { - wdb_t *data = *state; - - if(data) { - os_free(data->id); - os_free(data); - } - - return 0; -} - -/* tests */ - -static void test_wdb_syscheck_save2_wbs_null(void **state) { - int ret; - - expect_string(__wrap__merror, formatted_msg, "WDB object cannot be null."); - - ret = wdb_syscheck_save2(NULL, "{}"); - - assert_int_equal(ret, -1); -} - -static void test_wdb_syscheck_save2_payload_null(void **state) { - int ret; - wdb_t * wdb = *state; - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000): cannot parse FIM payload: ''"); - - ret = wdb_syscheck_save2(wdb, NULL); - - assert_int_equal(ret, -1); -} - -static void test_wdb_syscheck_save2_data_null(void **state) { - int ret; - wdb_t * wdb = *state; - - will_return(__wrap_wdb_begin2, 0); - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with no file path argument."); - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Can't insert file entry."); - - ret = wdb_syscheck_save2(wdb, "{}"); - - assert_int_equal(ret, -1); -} - -static void test_wdb_syscheck_save2_fail_transaction(void **state) { - int ret; - wdb_t * wdb = *state; - - wdb->transaction = 0; - - will_return(__wrap_wdb_begin2, -1); - - expect_string(__wrap__merror, formatted_msg, "DB(000) Can't begin transaction."); - - ret = wdb_syscheck_save2(wdb, "{}"); - - assert_int_equal(ret, -1); -} - -static void test_wdb_syscheck_save2_fail_file_entry(void **state) { - int ret; - wdb_t * wdb = *state; - - wdb->transaction = 1; - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with no file path argument."); - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Can't insert file entry."); - - const char *entry = - "{" - "\"timestamp\": \"123456789\"\n" - "}"; - - ret = wdb_syscheck_save2(wdb, entry); - - assert_int_equal(ret, -1); -} - -static void test_wdb_syscheck_save2_success(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON *data = prepare_valid_entry(2); - char *unformatted_data = cJSON_PrintUnformatted(data); - - wdb->transaction = 1; - - expect_wdb_fim_insert_entry2_success(2); - - ret = wdb_syscheck_save2(wdb, unformatted_data); - - cJSON_Delete(data); - free(unformatted_data); - assert_int_equal(ret, 0); -} - - -static void test_wdb_fim_insert_entry2_wdb_null(void **state) { - (void) state; /* unused */ - int ret; - cJSON * data = cJSON_Parse(VALID_ENTRY); - - expect_string(__wrap__merror, formatted_msg, "WDB object cannot be null."); - - ret = wdb_fim_insert_entry2(NULL, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_data_null(void **state) { - int ret; - - wdb_t * wdb = *state; - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with no file path argument."); - - ret = wdb_fim_insert_entry2(wdb, NULL); - - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_path_null(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_CreateObject(); - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with no file path argument."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_timestamp_null(void **state) { - int ret; - cJSON* data = cJSON_Parse(VALID_ENTRY); - wdb_t * wdb = *state; - - cJSON_ReplaceItemInObject(data, "timestamp", cJSON_CreateString("")); - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with no timestamp path argument."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_attributes_null(void **state) { - int ret; - cJSON* data = cJSON_Parse(VALID_ENTRY); - wdb_t * wdb = *state; - - cJSON_ReplaceItemInObject(data, "attributes", cJSON_CreateString("")); - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with no valid attributes."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_fail_cache(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON *data = cJSON_Parse(VALID_ENTRY); - - will_return(__wrap_wdb_stmt_cache, -1); - - expect_string(__wrap__merror, formatted_msg, "DB(000) Can't cache statement"); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_fail_element_string(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - cJSON *array = cJSON_GetObjectItem(data, "attributes"); - - cJSON_AddItemToObject(array, "invalid_attribute", cJSON_CreateString("sasssss")); - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "/test", 1); - expect_sqlite3_bind_text_call(2, "file", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, NULL, 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "/test", 1); - - expect_string(__wrap__merror, formatted_msg, "DB(000) Invalid attribute name: invalid_attribute"); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_fail_element_number(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - cJSON *array = cJSON_GetObjectItem(data, "attributes"); - - - cJSON_AddItemToObject(array, "invalid_attribute", cJSON_CreateNumber(1000)); - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "/test", 1); - expect_sqlite3_bind_text_call(2, "file", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, NULL, 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "/test", 1); - - expect_string(__wrap__merror, formatted_msg, "DB(000) Invalid attribute name: invalid_attribute"); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_fail_sqlite3_stmt(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "/test", 1); - expect_sqlite3_bind_text_call(2, "file", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, NULL, 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "/test", 1); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - //expect_string(__wrap__mdebug1, formatted_msg, "sqlite3_prepare_v2(): out of memory"); - //expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot rollback transaction"); - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: out of memory"); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_registry_arch_null(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_ReplaceItemInObject(cJSON_GetObjectItem(data, "attributes"), "type", cJSON_CreateString("registry_value")); - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save registry request with no arch argument."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_registry_value_name_null(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_ReplaceItemInObject(cJSON_GetObjectItem(data, "attributes"), "type", cJSON_CreateString("registry_value")); - cJSON_AddItemToObject(data, "arch", cJSON_CreateString("[x32]")); - - expect_string(__wrap__merror, - formatted_msg, - "DB(000) fim/save registry value request with no value name argument."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_item_type_null(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_DeleteItemFromObject(cJSON_GetObjectItem(data, "attributes"), "type"); - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with no type attribute."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_invalid_item_type(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - if (data == NULL) { - fail_msg("Unable to parse base json"); - } - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("[x32] HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_ReplaceItemInObject(cJSON_GetObjectItem(data, "attributes"), "type", cJSON_CreateString("invalid")); - - expect_string(__wrap__merror, formatted_msg, "DB(000) fim/save request with invalid 'invalid' type argument."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_registry_invalid_item_type(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - if (data == NULL) { - fail_msg("Unable to parse base json"); - } - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_ReplaceItemInObject(cJSON_GetObjectItem(data, "attributes"), "type", cJSON_CreateString("registry_invalid")); - cJSON_AddItemToObject(data, "arch", cJSON_CreateString("[x32]")); - - expect_string(__wrap__merror, formatted_msg, - "DB(000) fim/save request with invalid 'registry_invalid' type argument."); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -static void test_wdb_fim_insert_entry2_registry_succesful(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - if (data == NULL) { - fail_msg("Unable to parse base json"); - } - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("[x32] HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_ReplaceItemInObject(cJSON_GetObjectItem(data, "attributes"), "type", cJSON_CreateString("registry")); - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "[x32] HKEY_LOCAL_MACHINE\\System\\TEST\\key", 1); - expect_sqlite3_bind_text_call(2, "registry_key", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, NULL, 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "[x32] HKEY_LOCAL_MACHINE\\System\\TEST\\key", 1); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_registry_key_succesful(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - if (data == NULL) { - fail_msg("Unable to parse base json"); - } - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_ReplaceItemInObject(cJSON_GetObjectItem(data, "attributes"), "type", cJSON_CreateString("registry_key")); - cJSON_AddItemToObject(data, "arch", cJSON_CreateString("[x32]")); - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "HKEY_LOCAL_MACHINE\\System\\TEST\\key", 1); - expect_sqlite3_bind_text_call(2, "registry_key", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, "[x32]", 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "[x32] HKEY_LOCAL_MACHINE\\\\System\\\\TEST\\\\key", 1); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_registry_value_succesful(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALID_ENTRY); - - if (data == NULL) { - fail_msg("Unable to parse base json"); - } - - cJSON *attributes = cJSON_GetObjectItem(data, "attributes"); - - if (attributes == NULL) { - cJSON_Delete(data); - fail_msg("Unable to retrieve 'attributes'"); - } - - cJSON_ReplaceItemInObject(data, "path", cJSON_CreateString("HKEY_LOCAL_MACHINE\\System\\TEST\\key")); - cJSON_ReplaceItemInObject(attributes, "type", cJSON_CreateString("registry_value")); - cJSON_AddItemToObject(data, "arch", cJSON_CreateString("[x32]")); - cJSON_AddItemToObject(data, "value_name", cJSON_CreateString("testname")); - cJSON_AddStringToObject(attributes, "value_type", "REG_SZ"); - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "HKEY_LOCAL_MACHINE\\System\\TEST\\key", 1); - expect_sqlite3_bind_text_call(2, "registry_value", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, "[x32]", 1); - expect_sqlite3_bind_text_call(19, "testname", 1); - expect_sqlite3_bind_text_call(21, "[x32] HKEY_LOCAL_MACHINE\\\\System\\\\TEST\\\\key:testname", 1); - expect_sqlite3_bind_text_call(20, "REG_SZ", 1); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_registry_key_succesful_v3(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(KEY_V3_ENTRY); - - if (data == NULL) { - fail_msg("Unable to parse base json"); - } - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "HKEY_LOCAL_MACHINE\\System\\TEST\\key", 1); - expect_sqlite3_bind_text_call(2, "registry_key", 1); - expect_sqlite3_bind_int64_call(3, 1645981428, 0); - expect_sqlite3_bind_text_call(18, "[x32]", 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "ff03d79932df0148efa6a066552badf25ea9c466", 1); - - expect_sqlite3_bind_text_call(17, "6853b29eef33ff39d8b63911673cf7b078f95485", 1); - expect_sqlite3_bind_text_call(7, "0", 1); - expect_sqlite3_bind_text_call(11, "SYSTEM", 1); - expect_sqlite3_bind_int_call(12, 1645882878, 1); - expect_sqlite3_bind_text_call(5, "perm_json", 1); - expect_sqlite3_bind_text_call(6, "0", 1); - expect_sqlite3_bind_text_call(10, "Administradores", 1); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_registry_value_succesful_v3(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = cJSON_Parse(VALUE_V3_ENTRY); - - if (data == NULL) { - fail_msg("Unable to parse base json"); - } - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "HKEY_LOCAL_MACHINE\\System\\TEST\\key", 1); - expect_sqlite3_bind_text_call(2, "registry_value", 1); - expect_sqlite3_bind_int64_call(3, 1645981428, 0); - expect_sqlite3_bind_text_call(18, "[x32]", 1); - expect_sqlite3_bind_text_call(19, "test_name", 1); - expect_sqlite3_bind_text_call(21, "00a7ee53218b25b5364c8773f37a38c93eae3880", 1); - - expect_sqlite3_bind_text_call(17, "920b517a949aec0a6fa91b0556f0a60503058fbb", 1); - expect_sqlite3_bind_text_call(8, "d41d8cd98f00b204e9800998ecf8427e", 1); - expect_sqlite3_bind_text_call(9, "da39a3ee5e6b4b0d3255bfef95601890afd80709", 1); - expect_sqlite3_bind_text_call(14, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 1); - expect_sqlite3_bind_int64_call(4, 3221225472, 1); - expect_sqlite3_bind_text_call(20, "REG_UNKNOWN", 1); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_success(void **state) { - int ret; - wdb_t * wdb = *state; - cJSON* data = prepare_valid_entry(2); - - expect_wdb_fim_insert_entry2_success(2); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_large_inode(void **state) { - int ret; - - wdb_t * wdb = *state; - cJSON* data = prepare_valid_entry(2311061769); - - expect_wdb_fim_insert_entry2_success(2311061769); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_json_perms(void **state) { - wdb_t *wdb = *state; - int ret; - cJSON *win_perms = create_win_permissions_object(); - - if (win_perms == NULL) { - fail_msg("Failed to create Windows permissions object"); - } - - char * win_perms_str = cJSON_PrintUnformatted(win_perms); - if (win_perms_str == NULL) { - fail_msg("Failed formatting Windows permissions object"); - } - - cJSON *data = prepare_valid_entry_json(2311061769, win_perms); - - expect_wdb_fim_insert_entry2_perm_success(2311061769, win_perms_str); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - free(win_perms_str); - assert_int_equal(ret, 0); -} - -static void test_wdb_fim_insert_entry2_invalid_json_object(void **state) { - wdb_t *wdb = *state; - int ret; - cJSON *object = cJSON_CreateObject(); - cJSON* data = cJSON_Parse(VALID_ENTRY); - - if (object == NULL || data == NULL) { - fail_msg("Failed to create object"); - } - - cJSON_AddItemToObject(cJSON_GetObjectItem(data, "attributes"), "invalid", object); - - expect_wdb_stmt_cache_call(1); - - expect_sqlite3_bind_text_call(1, "/test", 1); - expect_sqlite3_bind_text_call(2, "file", 1); - expect_sqlite3_bind_int64_call(3, 10, 0); - expect_sqlite3_bind_text_call(18, NULL, 1); - expect_sqlite3_bind_text_call(19, NULL, 1); - expect_sqlite3_bind_text_call(21, "/test", 1); - - expect_string(__wrap__merror, formatted_msg, "DB(000) Invalid attribute name: invalid"); - - ret = wdb_fim_insert_entry2(wdb, data); - - cJSON_Delete(data); - assert_int_equal(ret, -1); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test wdb_syscheck_save2 - cmocka_unit_test(test_wdb_syscheck_save2_wbs_null), - cmocka_unit_test(test_wdb_syscheck_save2_payload_null), - cmocka_unit_test(test_wdb_syscheck_save2_data_null), - cmocka_unit_test(test_wdb_syscheck_save2_fail_transaction), - cmocka_unit_test(test_wdb_syscheck_save2_fail_file_entry), - cmocka_unit_test(test_wdb_syscheck_save2_success), - - // Test wdb_fim_insert_entry2 - cmocka_unit_test(test_wdb_fim_insert_entry2_wdb_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_data_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_path_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_timestamp_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_attributes_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_fail_cache), - cmocka_unit_test(test_wdb_fim_insert_entry2_fail_element_string), - cmocka_unit_test(test_wdb_fim_insert_entry2_fail_element_number), - cmocka_unit_test(test_wdb_fim_insert_entry2_fail_sqlite3_stmt), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_arch_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_value_name_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_item_type_null), - cmocka_unit_test(test_wdb_fim_insert_entry2_invalid_item_type), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_invalid_item_type), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_succesful), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_key_succesful), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_value_succesful), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_key_succesful_v3), - cmocka_unit_test(test_wdb_fim_insert_entry2_registry_value_succesful_v3), - cmocka_unit_test(test_wdb_fim_insert_entry2_success), - cmocka_unit_test(test_wdb_fim_insert_entry2_large_inode), - cmocka_unit_test(test_wdb_fim_insert_entry2_json_perms), - cmocka_unit_test(test_wdb_fim_insert_entry2_invalid_json_object), - cmocka_unit_test(test_wdb_fim_insert_entry2_invalid_json_object) - }; - - return cmocka_run_group_tests(tests, setup_wdb_t, teardown_wdb_t); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_global.c b/src/unit_tests/wazuh_db/test_wdb_global.c deleted file mode 100644 index c0dd61ecdab..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_global.c +++ /dev/null @@ -1,9856 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/wazuh/shared/time_op_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/posix/time_wrappers.h" -#include "../wrappers/wazuh/shared/cluster_op_wrappers.h" -#include "wazuhdb_op.h" - -#define GROUPS_SIZE 10 -#define AGENTS_SIZE 10 - -extern void __real_cJSON_Delete(cJSON *item); -extern int test_mode; - -/* setup/teardown */ -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("global",init_data->wdb->id); - os_calloc(256,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - *state = init_data; - wdb_init_conf(); - return 0; -} - -static int test_teardown(void **state){ - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - wdb_free_conf(); - return 0; -} - -/* wrappers configurations for fail/success */ - -/** - * @brief Configure a successful call to __wrap_wdb_exec_stmt_sized - * - * @param j_array The cJSON* array to mock - * @param column_mode The expected column mode, STMT_MULTI_COLUMN or STMT_SINGLE_COLUMN - */ -void wrap_wdb_exec_stmt_sized_success_call(cJSON* j_array, int column_mode) { - expect_value(__wrap_wdb_exec_stmt_sized, max_size, WDB_MAX_RESPONSE_SIZE); - expect_value(__wrap_wdb_exec_stmt_sized, column_mode, column_mode); - will_return(__wrap_wdb_exec_stmt_sized, SQLITE_DONE); - will_return(__wrap_wdb_exec_stmt_sized, j_array); -} - -/** - * @brief Configure a failed call to __wrap_wdb_exec_stmt_sized - * - * @param column_mode The expected column mode, STMT_MULTI_COLUMN or STMT_SINGLE_COLUMN - */ -void wrap_wdb_exec_stmt_sized_failed_call(int column_mode) { - expect_value(__wrap_wdb_exec_stmt_sized, max_size, WDB_MAX_RESPONSE_SIZE); - expect_value(__wrap_wdb_exec_stmt_sized, column_mode, column_mode); - will_return(__wrap_wdb_exec_stmt_sized, SQLITE_ERROR); - will_return(__wrap_wdb_exec_stmt_sized, NULL); -} - -/** - * @brief Configure a call to __wrap_wdb_exec_stmt_sized where the result is bigger than WDB_MAX_RESPONSE_SIZE - * - * @param j_array The cJSON* array to mock - * @param column_mode The expected column mode, STMT_MULTI_COLUMN or STMT_SINGLE_COLUMN - */ -void wrap_wdb_exec_stmt_sized_socket_full_call(cJSON* j_array, int column_mode) { - expect_value(__wrap_wdb_exec_stmt_sized, max_size, WDB_MAX_RESPONSE_SIZE); - expect_value(__wrap_wdb_exec_stmt_sized, column_mode, column_mode); - will_return(__wrap_wdb_exec_stmt_sized, SQLITE_ROW); - will_return(__wrap_wdb_exec_stmt_sized, j_array); -} - -/** - * @brief Configure all the wrappers to simulate a successful call to wdb_global_get_agent_max_group_priority() method - * @param agent_id The id of the agent to get the max priority of its groups - * @param j_priority_resp The response of the priority query - */ -void create_wdb_global_get_agent_max_group_priority_success_call(int agent_id, cJSON* j_priority_resp) { - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_PRIORITY_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_priority_resp); - expect_function_call(__wrap_cJSON_Delete); -} - -/** - * @brief Configure all the wrappers to simulate a successful call to create_wdb_global_validate_groups_success_call() method - * - * @param agent_id The agent ID the new groups will be assigned to. - * @param j_groups_number Existent groups number of agent_id. - * @param j_groups Groups to be assigned to agent_id - */ -void create_wdb_global_validate_groups_success_call(int agent_id, cJSON *j_groups_number) { - /* wdb_global_groups_number_get */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_AGENT_GROUPS_NUMBER_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_groups_number); - expect_function_call(__wrap_cJSON_Delete); -} - -/** - * @brief Configure all the wrappers to simulate a successful call to wdb_global_delete_agent_belong() method - * @param agent_id The id of the agent whose groups are being deleted - */ -void create_wdb_global_delete_agent_belong_success_call(int agent_id) { - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); -} - -/** - * @brief Configure all the wrappers to simulate a successful call to _wdb_global_unassign_agent_group() method - * @param agent_id The id of the agent being removed from the belongs table - * @param group_id The id of the group being removed from the the belongs table - * @param group_name The name of the group being searched for remove - * @param find_group_resp The response of the find group query - */ -void create_wdb_global_unassign_agent_group_success_call(int agent_id, int group_id, char* group_name, cJSON* find_group_resp) { - // wdb_global_find_group - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, find_group_resp); - expect_function_call(__wrap_cJSON_Delete); - // wdb_global_delete_tuple_belong - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_DELETE_TUPLE_BELONG); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, group_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); -} - -/** - * @brief Configure all the wrappers to simulate a successful call to wdb_global_calculate_agent_group_csv() method - * @param agent_id The id of the agent to calculate its groups csv - * @param find_group_resp The response of the find select group query - */ -void create_wdb_global_calculate_agent_group_csv_success_call(int agent_id, cJSON* j_group_resp) { - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_success_call(j_group_resp, STMT_SINGLE_COLUMN); - expect_function_call(__wrap_cJSON_Delete); -} - -/** - * @brief Configure all the wrappers to simulate a successful call to wdb_global_set_agent_group_context() method - * @param agent_id The id of the agent to set its group context - * @param csv The groups csv to be written in the groups column - * @param hash The hash to be written in the group_hash column - * @param sync_status The sync status to be written in the group_sync_status column - */ -void create_wdb_global_set_agent_group_context_success_call(int agent_id, char* csv, char* hash, char* sync_status) { - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_CTX_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - if (csv) { - expect_string(__wrap_sqlite3_bind_text, buffer, csv); - } - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - if (hash) { - expect_string(__wrap_sqlite3_bind_text, buffer, hash); - } - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); -} - -/* Tests wdb_global_get_agent_labels */ - -void test_wdb_global_get_agent_labels_transaction_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - output = wdb_global_get_agent_labels(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_labels_cache_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - output = wdb_global_get_agent_labels(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_labels_bind_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - output = wdb_global_get_agent_labels(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_labels_exec_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_always(__wrap_sqlite3_bind_int, index); - expect_any_always(__wrap_sqlite3_bind_int, value); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - will_return(__wrap_wdb_exec_stmt, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - output = wdb_global_get_agent_labels(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_labels_success(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_always(__wrap_sqlite3_bind_int, index); - expect_any_always(__wrap_sqlite3_bind_int, value); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - - output = wdb_global_get_agent_labels(data->wdb, 1); - assert_ptr_equal(output, (cJSON*)1); -} - -/* Tests wdb_global_del_agent_labels */ - -void test_wdb_global_del_agent_labels_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_del_agent_labels(data->wdb, 1); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_del_agent_labels_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_del_agent_labels(data->wdb, 1); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_del_agent_labels_bind_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_del_agent_labels(data->wdb, 1); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_del_agent_labels_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_del_agent_labels(data->wdb, 1); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_del_agent_labels_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_del_agent_labels(data->wdb, 1); - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_set_agent_label */ - -void test_wdb_global_set_agent_label_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char key[] = "test_key"; - char value[] = "test_value"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_set_agent_label(data->wdb, 1, key, value); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_agent_label_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char key[] = "test_key"; - char value[] = "test_value"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_set_agent_label(data->wdb, 1, key, value); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_agent_label_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char key[] = "test_key"; - char value[] = "test_value"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_set_agent_label(data->wdb, 1, key, value); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_agent_label_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char key[] = "test_key"; - char value[] = "test_value"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_key"); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_set_agent_label(data->wdb, 1, key, value); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_agent_label_bind3_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char key[] = "test_key"; - char value[] = "test_value"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_key"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_value"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_set_agent_label(data->wdb, 1, key, value); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_agent_label_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char key[] = "test_key"; - char value[] = "test_value"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_key"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_value"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_set_agent_label(data->wdb, 1, key, value); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_agent_label_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char key[] = "test_key"; - char value[] = "test_value"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_key"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_value"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_set_agent_label(data->wdb, 1, key, value); - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_set_sync_status */ - -void test_wdb_global_set_sync_status_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_set_sync_status(data->wdb, 1, status); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_sync_status_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_set_sync_status(data->wdb, 1, status); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_sync_status_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_set_sync_status(data->wdb, 1, status); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_sync_status_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_set_sync_status(data->wdb, 1, status); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_sync_status_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_set_sync_status(data->wdb, 1, status); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_set_sync_status_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_set_sync_status(data->wdb, 1, status); - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_sync_agent_info_get */ - -void test_wdb_global_sync_agent_info_get_transaction_fail(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - - assert_string_equal(output, "Cannot begin transaction"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_sync_agent_info_get_cache_fail(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - - assert_string_equal(output, "Cannot cache statement"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_sync_agent_info_get_bind_fail(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - - assert_string_equal(output, "Cannot bind sql statement"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_sync_agent_info_get_no_agents(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - expect_function_call_any(__wrap_cJSON_Delete); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - - assert_string_equal(output, "[]"); - os_free(output); - assert_int_equal(result, WDBC_OK); -} - -void test_wdb_global_sync_agent_info_get_success(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - cJSON *json_output = NULL; - cJSON *root = NULL; - cJSON *json_agent = NULL; - cJSON *json_labels = NULL; - cJSON *json_label = NULL; - int agent_id = 10; - - root = __real_cJSON_CreateArray(); - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", agent_id); - cJSON_AddStringToObject(json_agent,"test_field", "test_value"); - cJSON_AddItemToArray(root, json_agent); - - will_return_count(__wrap_wdb_begin2, 1, -1); - will_return_count(__wrap_wdb_stmt_cache, 1, -1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Required for wdb_get_agent_labels() - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Required for wdb_global_set_sync_status() - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "synced"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Mocking one valid agent - will_return(__wrap_wdb_exec_stmt, root); - expect_function_call_any(__wrap_cJSON_Delete); - - // Required for wdb_get_agent_labels() - json_labels = __real_cJSON_CreateArray(); - json_label = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_label, "id", agent_id); - cJSON_AddStringToObject(json_label,"key", "test_key"); - cJSON_AddStringToObject(json_label,"value", "test_value"); - cJSON_AddItemToArray(json_labels, json_label); - will_return(__wrap_wdb_exec_stmt, json_labels); - - // Required for wdb_global_set_sync_status() - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - // No more agents - will_return(__wrap_wdb_exec_stmt, NULL); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - - assert_string_equal(output, "[{\"id\":10,\"test_field\":\"test_value\",\"labels\":[{\"id\":10,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"); - os_free(output); - __real_cJSON_Delete(json_output); - __real_cJSON_Delete(root); - assert_int_equal(result, WDBC_OK); -} - -void test_wdb_global_sync_agent_info_get_sync_fail(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - cJSON *root = NULL; - cJSON *json_agent = NULL; - cJSON *json_labels = NULL; - int agent_id = 10; - - root = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(root, json_agent = cJSON_CreateObject()); - cJSON_AddItemToObject(json_agent, "id", cJSON_CreateNumber(agent_id)); - - will_return_count(__wrap_wdb_begin2, 1, -1); - will_return_count(__wrap_wdb_stmt_cache, 1, -1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Required for wdb_get_agent_labels() - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Required for wdb_global_set_sync_status() - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "synced"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Mocking one valid agent - will_return(__wrap_wdb_exec_stmt, root); - expect_function_call_any(__wrap_cJSON_Delete); - - // Required for wdb_get_agent_labels() - json_labels = __real_cJSON_CreateArray(); - will_return(__wrap_wdb_exec_stmt, json_labels); - - // Required for wdb_global_set_sync_status() - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "Cannot set sync_status for agent 10"); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - - assert_string_equal(output, "Cannot set sync_status for agent 10"); - os_free(output); - __real_cJSON_Delete(root); - __real_cJSON_Delete(json_labels); - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_sync_agent_info_get_full(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - cJSON *root = NULL; - cJSON *json_agent = NULL; - cJSON *json_labels = NULL; - cJSON *json_label = NULL; - int agent_id = 10; - - root = __real_cJSON_CreateArray(); - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", agent_id); - // Creating a cJSON array bigger than WDB_MAX_RESPONSE_SIZE - for(int i = 0; i < 2500; i++){ - cJSON_AddStringToObject(json_agent,"test_field", "test_value"); - } - cJSON_AddItemToArray(root, json_agent); - - will_return_count(__wrap_wdb_begin2, 1, -1); - will_return_count(__wrap_wdb_stmt_cache, 1, -1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Required for wdb_get_agent_labels() - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Mocking one valid agent - will_return(__wrap_wdb_exec_stmt, root); - expect_function_call_any(__wrap_cJSON_Delete); - - // Required for wdb_get_agent_labels() - json_labels = __real_cJSON_CreateArray(); - json_label = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_label, "id", 1); - cJSON_AddStringToObject(json_label,"key", "test_key"); - cJSON_AddStringToObject(json_label,"value", "test_value"); - cJSON_AddItemToArray(json_labels, json_label); - will_return(__wrap_wdb_exec_stmt, json_labels); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - - assert_string_equal(output, "[]"); - os_free(output); - __real_cJSON_Delete(root); - assert_int_equal(result, WDBC_DUE); -} - -void test_wdb_global_sync_agent_info_get_size_limit(void **state) -{ - int result = 0; - int last_agent_id = 0; - test_struct_t *data = (test_struct_t *)*state; - char *output = NULL; - cJSON *json_output = NULL; - cJSON *root = NULL; - cJSON *json_agent = NULL; - int agent_id = 10000; - - root = __real_cJSON_CreateArray(); - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", agent_id); - // Creating a cJSON array of WDB_MAX_RESPONSE_SIZE - for(int i = 0; i < 8126; i++){ - cJSON_AddStringToObject(json_agent,"a", "b"); - } - cJSON_AddItemToArray(root, json_agent); - - will_return_count(__wrap_wdb_begin2, 1, -1); - will_return_count(__wrap_wdb_stmt_cache, 1, -1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Required for wdb_get_agent_labels() - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Required for wdb_global_set_sync_status() - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "synced"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - // Mocking one valid agent - will_return(__wrap_wdb_exec_stmt, root); - expect_function_call_any(__wrap_cJSON_Delete); - - // Required for wdb_get_agent_labels() - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "SQL MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): SQL MESSAGE"); - - // Required for wdb_global_set_sync_status() - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - // No more agents - will_return(__wrap_wdb_exec_stmt, NULL); - - result = wdb_global_sync_agent_info_get(data->wdb, &last_agent_id, &output); - assert_int_equal(result, WDBC_OK); - - os_free(output); - __real_cJSON_Delete(json_output); - __real_cJSON_Delete(root); -} - -/* Tests wdb_global_get_groups_integrity */ - -void test_wdb_global_get_groups_integrity_statement_fail(void **state) -{ - cJSON* j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNCREQ_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - j_result = wdb_global_get_groups_integrity(data->wdb, NULL); - - assert_null(j_result); -} - -void test_wdb_global_get_groups_integrity_syncreq(void **state) -{ - cJSON* j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNCREQ_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - will_return(__wrap_wdb_step, SQLITE_ROW); - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - j_result = wdb_global_get_groups_integrity(data->wdb, NULL); - - char *result = cJSON_PrintUnformatted(j_result); - assert_string_equal(result, "[\"syncreq\"]"); - os_free(result); - __real_cJSON_Delete(j_result); -} - -void test_wdb_global_get_groups_integrity_hash_mismatch(void **state) -{ - cJSON* j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - os_sha1 digest = ""; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNCREQ_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - will_return(__wrap_wdb_step, SQLITE_DONE); - expect_string(__wrap_wdb_get_global_group_hash, hexdigest, digest); - will_return(__wrap_wdb_get_global_group_hash, OS_INVALID); - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - j_result = wdb_global_get_groups_integrity(data->wdb, digest); - - char *result = cJSON_PrintUnformatted(j_result); - assert_string_equal(result, "[\"hash_mismatch\"]"); - os_free(result); - __real_cJSON_Delete(j_result); -} - -void test_wdb_global_get_groups_integrity_synced(void **state) -{ - cJSON* j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - os_sha1 digest = ""; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNCREQ_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - will_return(__wrap_wdb_step, SQLITE_DONE); - expect_string(__wrap_wdb_get_global_group_hash, hexdigest, digest); - will_return(__wrap_wdb_get_global_group_hash, OS_SUCCESS); - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - j_result = wdb_global_get_groups_integrity(data->wdb, digest); - - char *result = cJSON_PrintUnformatted(j_result); - assert_string_equal(result, "[\"synced\"]"); - os_free(result); - __real_cJSON_Delete(j_result); -} - -void test_wdb_global_get_groups_integrity_error(void **state) -{ - cJSON* j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNCREQ_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "DB(global) SQLite: ERROR MESSAGE"); - - j_result = wdb_global_get_groups_integrity(data->wdb, NULL); - - assert_null(j_result); -} - -/* Tests wdb_global_get_agent_max_group_priority */ - -void test_wdb_global_get_agent_max_group_priority_statement_fail(void **state) -{ - int result = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_PRIORITY_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - result = wdb_global_get_agent_max_group_priority(data->wdb, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_get_agent_max_group_priority_bind_fail(void **state) -{ - int result = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_PRIORITY_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_get_agent_max_group_priority(data->wdb, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_get_agent_max_group_priority_step_fail(void **state) -{ - int result = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_PRIORITY_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - result = wdb_global_get_agent_max_group_priority(data->wdb, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_get_agent_max_group_priority_success(void **state) -{ - int result = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON *j_result = cJSON_Parse("[{\"MAX(priority)\":5}]"); - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_PRIORITY_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_result); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_get_agent_max_group_priority(data->wdb, agent_id); - - assert_int_equal(result, 5); - __real_cJSON_Delete(j_result); -} - -/* Tests wdb_global_sync_agent_groups_get */ - -void test_wdb_global_sync_agent_groups_get_no_condition_get_hash_true(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_NO_CONDITION; - int last_agent_id = 0; - bool set_synced = false; - bool get_hash = true; - cJSON *j_output = NULL; - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - - expect_string(__wrap_wdb_get_global_group_hash, hexdigest, ""); - will_return(__wrap_wdb_get_global_group_hash, OS_SUCCESS); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, 10, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[],\"hash\":null}]"); - os_free(output); - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_transaction_fail(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_SYNC_STATUS; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - cJSON *j_output = NULL; - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_cache_fail(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_SYNC_STATUS; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - cJSON *j_output = NULL; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, 100); - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[]}]"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_bind_fail(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_ALL; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - cJSON *j_output = NULL; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, 100); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[]}]"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_bind2_fail(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_ALL; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - cJSON *j_output = NULL; - int wrapped_time = 100; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, wrapped_time); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, wrapped_time - agent_registration_delta); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[]}]"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_no_agents_get_hash_false(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = 0; - int last_agent_id = 0; - bool set_synced = false; - bool get_hash = false; - int agent_registration_delta = 10; - int wrapped_time = 100; - cJSON *j_output = NULL; - cJSON *j_exec_response = __real_cJSON_CreateArray(); - cJSON *j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "id", 1); - cJSON_AddItemToArray(j_exec_response, j_object); - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, wrapped_time); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, wrapped_time - agent_registration_delta); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, j_exec_response); - expect_function_call(__wrap_cJSON_Delete); - - /* wdb_global_select_group_belong */ - cJSON *j_groups = NULL; - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id+1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_success_call(j_groups, STMT_SINGLE_COLUMN); - expect_function_call(__wrap_cJSON_Delete); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - - /* Next agent */ - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id+1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, wrapped_time - agent_registration_delta); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[{\"id\":1,\"groups\":[]}]}]"); - os_free(output); - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_exec_response); - __real_cJSON_Delete(j_output); - __real_cJSON_Delete(j_groups); -} - -void test_wdb_global_sync_agent_groups_get_exec_fail_get_hash_true_success(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_ALL; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - cJSON *j_output = NULL; - int wrapped_time = 100; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, wrapped_time); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, wrapped_time - agent_registration_delta); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, NULL); - expect_string(__wrap_wdb_get_global_group_hash, hexdigest, ""); - will_return(__wrap_wdb_get_global_group_hash, OS_SUCCESS); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[],\"hash\":null}]"); - os_free(output); - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_exec_fail_get_hash_true_fail(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_ALL; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - cJSON *j_output = NULL; - int wrapped_time = 100; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, wrapped_time); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, wrapped_time - agent_registration_delta); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, NULL); - expect_string(__wrap_wdb_get_global_group_hash, hexdigest, ""); - will_return(__wrap_wdb_get_global_group_hash, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "Cannot obtain the global group hash"); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[]}]"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_set_synced_error(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_ALL; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - int wrapped_time = 100; - cJSON *j_output = NULL; - cJSON *j_exec_response = __real_cJSON_CreateArray(); - cJSON *j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "id", 1); - cJSON_AddItemToArray(j_exec_response, j_object); - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, wrapped_time); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, wrapped_time - agent_registration_delta); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, j_exec_response); - expect_function_call(__wrap_cJSON_Delete); - - /* wdb_global_select_group_belong */ - cJSON *root = cJSON_Parse("[\"default\",\"new_group\"]"); - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id+1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_success_call(root, STMT_SINGLE_COLUMN); - - /* wdb_global_set_agent_groups_sync_status */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNC_SET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - expect_string(__wrap__merror, formatted_msg, "Cannot set group_sync_status for agent 1"); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - char *output = cJSON_PrintUnformatted(j_output); - assert_string_equal(output, "[{\"data\":[{\"id\":1,\"groups\":[\"default\",\"new_group\"]}]}]"); - os_free(output); - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_exec_response); - __real_cJSON_Delete(j_output); -} - -void test_wdb_global_sync_agent_groups_get_due_buffer_full(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = 0; - int last_agent_id = 0; - bool set_synced = false; - bool get_hash = true; - int agent_registration_delta = 10; - int wrapped_time = 100; - cJSON *j_output = NULL; - cJSON *j_exec_response = __real_cJSON_CreateArray(); - cJSON *j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "id", 1); - cJSON_AddItemToArray(j_exec_response, j_object); - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - will_return(__wrap_time, 100); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, wrapped_time - agent_registration_delta); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, j_exec_response); - expect_function_call(__wrap_cJSON_Delete); - - /* wdb_global_select_group_belong */ - cJSON *j_groups = __real_cJSON_CreateArray(); - /* Creating a JSON object with 5000 groups of name "test_group" - to exceed the WDB_MAX_RESPONSE_SIZE just for testing purposes. - In a real scenario an agent won't belong to more than MAX_GROUPS_PER_MULTIGROUP (128), - the group names will be unique and not longer than MAX_GROUP_NAME (255). - */ - for (int i = 0; i < 5000; ++i) { - cJSON_AddItemToArray(j_groups, cJSON_CreateString("test_group")); - } - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id+1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_success_call(j_groups, STMT_SINGLE_COLUMN); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, &j_output); - - assert_int_equal(result, WDBC_DUE); - __real_cJSON_Delete(j_exec_response); - __real_cJSON_Delete(j_output); -} - -/* Tests wdb_global_add_global_group_hash_to_response */ - -void test_wdb_global_sync_agent_groups_get_invalid_condition(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - wdb_groups_sync_condition_t condition = WDB_GROUP_INVALID_CONDITION; - int last_agent_id = 0; - bool set_synced = true; - bool get_hash = true; - int agent_registration_delta = 10; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid groups sync condition"); - - result = wdb_global_sync_agent_groups_get(data->wdb, condition, last_agent_id, set_synced, get_hash, agent_registration_delta, NULL); - - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_add_global_group_hash_to_resposne_response_null(void **state) { - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid JSON object."); - - result = wdb_global_add_global_group_hash_to_response(data->wdb, NULL, 1); - - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_add_global_group_hash_to_resposne_get_hash_return_null(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_response = cJSON_CreateObject(); - - expect_string(__wrap_wdb_get_global_group_hash, hexdigest, ""); - will_return(__wrap_wdb_get_global_group_hash, OS_SUCCESS); - - result = wdb_global_add_global_group_hash_to_response(data->wdb, &j_response, 1); - - char *output = cJSON_PrintUnformatted(j_response); - assert_string_equal(output, "{\"hash\":null}"); - os_free(output); - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_response); -} - -void test_wdb_global_add_global_group_hash_to_resposne_response_due(void **state) { - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_response = cJSON_CreateObject(); - - result = wdb_global_add_global_group_hash_to_response(data->wdb, &j_response, WDB_MAX_RESPONSE_SIZE-1); - - assert_int_equal(result, WDBC_DUE); - __real_cJSON_Delete(j_response); -} - -void test_wdb_global_add_global_group_hash_to_resposne_get_hash_error(void **state) -{ - wdbc_result result = WDBC_OK; - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_response = cJSON_CreateObject(); - - expect_string(__wrap_wdb_get_global_group_hash, hexdigest, ""); - will_return(__wrap_wdb_get_global_group_hash, OS_INVALID); - - expect_string(__wrap__merror, formatted_msg, "Cannot obtain the global group hash"); - - result = wdb_global_add_global_group_hash_to_response(data->wdb, &j_response, 1); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_response); -} - -/* Tests wdb_global_sync_agent_info_set */ - -void test_wdb_global_sync_agent_info_set_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_sync_agent_info_set(data->wdb, json_agent); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_sync_agent_info_set_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_sync_agent_info_set(data->wdb, json_agent); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_sync_agent_info_set_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_count(__wrap_sqlite3_bind_parameter_index, zName, -1); - will_return_count(__wrap_sqlite3_bind_parameter_index, 1, -1); - - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", 1); - cJSON_AddStringToObject(json_agent, "name", "test_name"); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_name"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_sync_agent_info_set(data->wdb, json_agent); - - __real_cJSON_Delete(json_agent); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_sync_agent_info_set_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - int agent_id = 10; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_count(__wrap_sqlite3_bind_parameter_index, zName, -1); - will_return_count(__wrap_sqlite3_bind_parameter_index, 1, -1); - - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", agent_id); - cJSON_AddStringToObject(json_agent, "name", "test_name"); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_name"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_sync_agent_info_set(data->wdb, json_agent); - __real_cJSON_Delete(json_agent); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_sync_agent_info_set_bind3_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - int agent_id = 10; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_count(__wrap_sqlite3_bind_parameter_index, zName, -1); - will_return_count(__wrap_sqlite3_bind_parameter_index, 1, -1); - - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", agent_id); - cJSON_AddStringToObject(json_agent, "name", "test_name"); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_name"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "synced"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_sync_agent_info_set(data->wdb, json_agent); - __real_cJSON_Delete(json_agent); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_sync_agent_info_set_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - int agent_id = 10; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_count(__wrap_sqlite3_bind_parameter_index, zName, -1); - will_return_count(__wrap_sqlite3_bind_parameter_index, 1, -1); - - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", agent_id); - cJSON_AddStringToObject(json_agent, "name", "test_name"); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_name"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "synced"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_sync_agent_info_set(data->wdb, json_agent); - __real_cJSON_Delete(json_agent); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_sync_agent_info_set_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - int agent_id = 10; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_count(__wrap_sqlite3_bind_parameter_index, zName, -1); - will_return_count(__wrap_sqlite3_bind_parameter_index, 1, -1); - - json_agent = cJSON_CreateObject(); - cJSON_AddNumberToObject(json_agent, "id", agent_id); - cJSON_AddStringToObject(json_agent, "name", "test_name"); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "test_name"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "synced"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_sync_agent_info_set(data->wdb, json_agent); - __real_cJSON_Delete(json_agent); - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_insert_agent */ - -void test_wdb_global_insert_agent_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = NULL; - char *ip = NULL; - char *register_ip = NULL; - char *internal_key = NULL; - char *group = NULL; - int date_add = 0; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = NULL; - char *ip = NULL; - char *register_ip = NULL; - char *internal_key = NULL; - char *group = NULL; - int date_add = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_bind3_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_bind4_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, register_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_bind5_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, register_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, internal_key); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_bind6_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, register_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, internal_key); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, date_add); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_bind7_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, register_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, internal_key); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, date_add); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, group); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, register_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, internal_key); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, date_add); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, group); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "test_ip"; - char *register_ip = "0.0.0.0"; - char *internal_key = "test_key"; - char *group = "test_group"; - int date_add = 100; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, register_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, internal_key); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, date_add); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, group); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_insert_agent(data->wdb, 1, name, ip, register_ip, internal_key, group, date_add); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_update_agent_name */ - -void test_wdb_global_update_agent_name_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = NULL; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_update_agent_name(data->wdb, 1, name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_name_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = NULL; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_update_agent_name(data->wdb, 1, name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_name_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_name(data->wdb, 1, name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_name_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_update_agent_name(data->wdb, 1, name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_name_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_update_agent_name(data->wdb, 1, name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_name_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_update_agent_name(data->wdb, 1, name); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_update_agent_version */ - -void test_wdb_global_update_agent_version_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = NULL; - const char *os_version = NULL; - const char *os_major = NULL; - const char *os_minor = NULL; - const char *os_codename = NULL; - const char *os_platform = NULL; - const char *os_build = NULL; - const char *os_uname = NULL; - const char *os_arch = NULL; - const char *version = NULL; - const char *config_sum = NULL; - const char *merged_sum = NULL; - const char *manager_host = NULL; - const char *node_name = NULL; - const char *agent_ip = NULL; - const char *connection_status = NULL; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = NULL; - const char *os_version = NULL; - const char *os_major = NULL; - const char *os_minor = NULL; - const char *os_codename = NULL; - const char *os_platform = NULL; - const char *os_build = NULL; - const char *os_uname = NULL; - const char *os_arch = NULL; - const char *version = NULL; - const char *config_sum = NULL; - const char *merged_sum = NULL; - const char *manager_host = NULL; - const char *node_name = NULL; - const char *agent_ip = NULL; - const char *connection_status = NULL; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind3_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind4_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind5_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind6_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind7_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind8_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind9_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind10_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind11_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind12_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind13_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind14_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind15_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_value(__wrap_sqlite3_bind_text, buffer, agent_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind16_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_value(__wrap_sqlite3_bind_text, buffer, agent_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind17_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_value(__wrap_sqlite3_bind_text, buffer, agent_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind18_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_value(__wrap_sqlite3_bind_text, buffer, agent_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_value(__wrap_sqlite3_bind_text, buffer, group_config_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_bind19_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_value(__wrap_sqlite3_bind_text, buffer, agent_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_value(__wrap_sqlite3_bind_text, buffer, group_config_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 19); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_value(__wrap_sqlite3_bind_text, buffer, agent_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_value(__wrap_sqlite3_bind_text, buffer, group_config_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 19); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_version_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - const char *os_name = "test_name"; - const char *os_version = "test_version"; - const char *os_major = "test_major"; - const char *os_minor = "test_minor"; - const char *os_codename = "test_codename"; - const char *os_platform = "test_platform"; - const char *os_build = "test_build"; - const char *os_uname = "test_uname"; - const char *os_arch = "test_arch"; - const char *version = "test_version"; - const char *config_sum = "test_config"; - const char *merged_sum = "test_merged"; - const char *manager_host = "test_manager"; - const char *node_name = "test_node"; - const char *agent_ip = "test_ip"; - const char *connection_status = "active"; - const char *sync_status = "synced"; - const char *group_config_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, os_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, os_version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, os_major); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_value(__wrap_sqlite3_bind_text, buffer, os_minor); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_value(__wrap_sqlite3_bind_text, buffer, os_codename); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_value(__wrap_sqlite3_bind_text, buffer, os_platform); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_value(__wrap_sqlite3_bind_text, buffer, os_build); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_value(__wrap_sqlite3_bind_text, buffer, os_uname); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_value(__wrap_sqlite3_bind_text, buffer, os_arch); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_value(__wrap_sqlite3_bind_text, buffer, config_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_value(__wrap_sqlite3_bind_text, buffer, merged_sum); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_value(__wrap_sqlite3_bind_text, buffer, manager_host); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_value(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_value(__wrap_sqlite3_bind_text, buffer, agent_ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_value(__wrap_sqlite3_bind_text, buffer, group_config_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 19); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_update_agent_version(data->wdb, agent_id, os_name, os_version, os_major, - os_minor, os_codename, os_platform, os_build, os_uname, os_arch, version, - config_sum, merged_sum, manager_host, node_name, agent_ip, connection_status, - sync_status, group_config_status); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_update_agent_keepalive */ - -void test_wdb_global_update_agent_keepalive_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_update_agent_keepalive(data->wdb, 1, connection_status, status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_keepalive_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_update_agent_keepalive(data->wdb, 1, connection_status, status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_keepalive_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_keepalive(data->wdb, 1, connection_status, status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_keepalive_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_keepalive(data->wdb, 1, connection_status, status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_keepalive_bind3_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_update_agent_keepalive(data->wdb, 1, connection_status, status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_keepalive_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_update_agent_keepalive(data->wdb, 1, connection_status, status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_keepalive_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_update_agent_keepalive(data->wdb, 1, connection_status, status); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_update_agent_connection_status */ - -void test_wdb_global_update_agent_connection_status_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_bind3_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_bind4_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_bind5_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_connection_status_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_update_agent_connection_status(data->wdb, 1, connection_status, sync_status, 0); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_update_agent_status_code */ - -void test_wdb_global_update_agent_status_code_transaction_fail(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_status_code_cache_fail(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_INVALID); -} - - -void test_wdb_global_update_agent_status_code_bind1_fail(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, status_code); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_INVALID); -} - - -void test_wdb_global_update_agent_status_code_bind2_fail(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, status_code); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_INVALID); -} - - -void test_wdb_global_update_agent_status_code_bind3_fail(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, status_code); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_INVALID); -} - - -void test_wdb_global_update_agent_status_code_bind4_fail(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, status_code); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_INVALID); -} - - -void test_wdb_global_update_agent_status_code_step_fail(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, status_code); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_INVALID); -} - - -void test_wdb_global_update_agent_status_code_success(void **state) { - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int status_code = 0; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, status_code); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, version); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_update_agent_status_code(data->wdb, 1, status_code, version, sync_status); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_delete_agent */ - -void test_wdb_global_delete_agent_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_delete_agent(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_delete_agent(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_bind_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_delete_agent(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_delete_agent(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_delete_agent(data->wdb, 1); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_select_agent_name */ - -void test_wdb_global_select_agent_name_transaction_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_select_agent_name(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_name_cache_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_select_agent_name(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_name_bind_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_select_agent_name(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_name_exec_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - result = wdb_global_select_agent_name(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_name_success(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*) 1); - - result = wdb_global_select_agent_name(data->wdb, 1); - - assert_ptr_equal(result, (cJSON*) 1); -} - -/* Tests wdb_global_select_agent_group */ - -void test_wdb_global_select_agent_group_transaction_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_select_agent_group(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_group_cache_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_select_agent_group(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_group_bind_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_select_agent_group(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_group_exec_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - result = wdb_global_select_agent_group(data->wdb, 1); - - assert_null(result); -} - -void test_wdb_global_select_agent_group_success(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*) 1); - - result = wdb_global_select_agent_group(data->wdb, 1); - - assert_ptr_equal(result, (cJSON*) 1); -} - -/* Tests wdb_global_select_groups */ - -void test_wdb_global_select_groups_transaction_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_select_groups(data->wdb); - - assert_null(result); -} - -void test_wdb_global_select_groups_cache_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_select_groups(data->wdb); - - assert_null(result); -} - -void test_wdb_global_select_groups_exec_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_failed_call(STMT_MULTI_COLUMN); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "Failed to get groups: ERROR MESSAGE."); - - result = wdb_global_select_groups(data->wdb); - - assert_null(result); -} - -void test_wdb_global_select_groups_socket_full(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_socket_full_call(NULL, STMT_MULTI_COLUMN); - expect_string(__wrap__mwarn, formatted_msg, "The groups exceed the socket maximum response size."); - - result = wdb_global_select_groups(data->wdb); - - assert_null(result); -} - -void test_wdb_global_select_groups_success(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_success_call((cJSON*) 1, STMT_MULTI_COLUMN); - - result = wdb_global_select_groups(data->wdb); - - assert_ptr_equal(result, (cJSON*) 1); -} - -/* Tests wdb_global_find_agent */ - -void test_wdb_global_find_agent_transaction_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "0.0.0.0"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_find_agent(data->wdb, name, ip); - - assert_null(result); -} - -void test_wdb_global_find_agent_cache_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "0.0.0.0"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_find_agent(data->wdb, name, ip); - - assert_null(result); -} - -void test_wdb_global_find_agent_bind1_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "0.0.0.0"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_find_agent(data->wdb, name, ip); - - assert_null(result); -} - -void test_wdb_global_find_agent_bind2_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "0.0.0.0"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_find_agent(data->wdb, name, ip); - - assert_null(result); -} - -void test_wdb_global_find_agent_bind3_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "0.0.0.0"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_find_agent(data->wdb, name, ip); - - assert_null(result); -} - -void test_wdb_global_find_agent_exec_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "0.0.0.0"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - result = wdb_global_find_agent(data->wdb, name, ip); - - assert_null(result); -} - -void test_wdb_global_find_agent_success(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *name = "test_name"; - char *ip = "0.0.0.0"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, ip); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*) 1); - - result = wdb_global_find_agent(data->wdb, name, ip); - - assert_ptr_equal(result, (cJSON*) 1); -} - -/* Tests wdb_global_find_group */ - -void test_wdb_global_find_group_transaction_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_find_group(data->wdb, group_name); - - assert_null(result); -} - -void test_wdb_global_find_group_cache_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_find_group(data->wdb, group_name); - - assert_null(result); -} - -void test_wdb_global_find_group_bind_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_find_group(data->wdb, group_name); - - assert_null(result); -} - -void test_wdb_global_find_group_exec_fail(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - result = wdb_global_find_group(data->wdb, group_name); - - assert_null(result); -} - -void test_wdb_global_find_group_success(void **state) -{ - cJSON *result = NULL; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*) 1); - - result = wdb_global_find_group(data->wdb, group_name); - - assert_ptr_equal(result, (cJSON*) 1); -} - -/* Tests wdb_global_insert_agent_group */ - -void test_wdb_global_insert_agent_group_invalid_group_name(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "group_name,with_comma"; - - expect_string(__wrap__mwarn, formatted_msg, "Invalid group name. 'group_name,with_comma' " - "contains invalid characters"); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot insert 'group_name,with_comma'"); - - result = wdb_global_insert_agent_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_group_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_insert_agent_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_group_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_insert_agent_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_group_bind_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - result = wdb_global_insert_agent_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_group_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_insert_agent_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_group_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_insert_agent_group(data->wdb, group_name); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_select_group_belong */ - -void test_wdb_global_select_group_belong_transaction_fail(void **state) -{ - cJSON *j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - j_result = wdb_global_select_group_belong(data->wdb, 1); - assert_null(j_result); -} - -void test_wdb_global_select_group_belong_cache_fail(void **state) -{ - cJSON *j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - j_result = wdb_global_select_group_belong(data->wdb, 1); - assert_null(j_result); -} - -void test_wdb_global_select_group_belong_bind_fail(void **state) -{ - cJSON *j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - j_result = wdb_global_select_group_belong(data->wdb, 1); - assert_null(j_result); -} - -void test_wdb_global_select_group_belong_exec_fail(void **state) -{ - cJSON *j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_always(__wrap_sqlite3_bind_int, index); - expect_any_always(__wrap_sqlite3_bind_int, value); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_failed_call(STMT_SINGLE_COLUMN); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - expect_string(__wrap__mdebug1, formatted_msg, "Failed to get agent groups: ERROR MESSAGE."); - - j_result = wdb_global_select_group_belong(data->wdb, 1); - assert_null(j_result); -} - -void test_wdb_global_select_group_belong_socket_size_error(void **state) -{ - cJSON *j_result = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_always(__wrap_sqlite3_bind_int, index); - expect_any_always(__wrap_sqlite3_bind_int, value); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_socket_full_call(NULL, STMT_SINGLE_COLUMN); - expect_string(__wrap__mwarn, formatted_msg, "The agent's groups exceed the socket maximum response size."); - - j_result = wdb_global_select_group_belong(data->wdb, 1); - assert_null(j_result); -} - -void test_wdb_global_select_group_belong_success(void **state) -{ - cJSON *j_result = NULL; - cJSON *j_root = NULL; - test_struct_t *data = (test_struct_t *)*state; - - j_root = cJSON_Parse("[\"default\",\"new_group\"]"); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_always(__wrap_sqlite3_bind_int, index); - expect_any_always(__wrap_sqlite3_bind_int, value); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_success_call(j_root, STMT_SINGLE_COLUMN); - - j_result = wdb_global_select_group_belong(data->wdb, 1); - - char *result = cJSON_PrintUnformatted(j_result); - assert_string_equal(result, "[\"default\",\"new_group\"]"); - __real_cJSON_Delete(j_root); - os_free(result); -} - -/* Tests wdb_global_get_group_agents */ - -void test_wdb_global_get_group_agents_cache_fail(void **state) { - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_result = NULL; - wdbc_result status = WDBC_UNKNOWN; - char* group_name = "group_name"; - int last_agent_id = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - j_result = wdb_global_get_group_agents(data->wdb, &status, group_name, last_agent_id); - - assert_null(j_result); - assert_int_equal(status, WDBC_ERROR); -} - -void test_wdb_global_get_group_agents_bind_text_fail(void **state) { - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_result = NULL; - wdbc_result status = WDBC_UNKNOWN; - char* group_name = "group_name"; - int last_agent_id = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - j_result = wdb_global_get_group_agents(data->wdb, &status, group_name, last_agent_id); - - assert_null(j_result); - assert_int_equal(status, WDBC_ERROR); -} - -void test_wdb_global_get_group_agents_bind_int_fail(void **state) { - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_result = NULL; - wdbc_result status = WDBC_UNKNOWN; - char* group_name = "group_name"; - int last_agent_id = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - j_result = wdb_global_get_group_agents(data->wdb, &status, group_name, last_agent_id); - - assert_null(j_result); - assert_int_equal(status, WDBC_ERROR); -} - -void test_wdb_global_get_group_agents_stmt_ok(void **state) { - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_result = NULL; - wdbc_result status = WDBC_UNKNOWN; - char* group_name = "group_name"; - int last_agent_id = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - wrap_wdb_exec_stmt_sized_success_call(j_result, STMT_SINGLE_COLUMN); - - j_result = wdb_global_get_group_agents(data->wdb, &status, group_name, last_agent_id); - - assert_null(j_result); - assert_int_equal(status, WDBC_OK); -} - -void test_wdb_global_get_group_agents_stmt_due(void **state) { - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_result = NULL; - wdbc_result status = WDBC_UNKNOWN; - char* group_name = "group_name"; - int last_agent_id = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - wrap_wdb_exec_stmt_sized_socket_full_call(j_result, STMT_SINGLE_COLUMN); - - j_result = wdb_global_get_group_agents(data->wdb, &status, group_name, last_agent_id); - - assert_null(j_result); - assert_int_equal(status, WDBC_DUE); -} - -void test_wdb_global_get_group_agents_stmt_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - cJSON *j_result = NULL; - wdbc_result status = WDBC_UNKNOWN; - char* group_name = "group_name"; - int last_agent_id = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, last_agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - wrap_wdb_exec_stmt_sized_failed_call(STMT_SINGLE_COLUMN); - - j_result = wdb_global_get_group_agents(data->wdb, &status, group_name, last_agent_id); - - assert_null(j_result); - assert_int_equal(status, WDBC_ERROR); -} - -/* Tests wdb_global_insert_agent_belong */ - -void test_wdb_global_insert_agent_belong_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int id_group = 2; - int id_agent = 2; - int priority = 0; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_insert_agent_belong(data->wdb, id_group, id_agent, priority); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_belong_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int id_group = 2; - int id_agent = 2; - int priority = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_insert_agent_belong(data->wdb, id_group, id_agent, priority); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_belong_bind1_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int id_group = 2; - int id_agent = 2; - int priority = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, id_group); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_insert_agent_belong(data->wdb, id_group, id_agent, priority); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_belong_bind2_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int id_group = 2; - int id_agent = 2; - int priority = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, id_group); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, id_agent); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_insert_agent_belong(data->wdb, id_group, id_agent, priority); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_belong_bind3_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int id_group = 2; - int id_agent = 2; - int priority = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, id_group); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, id_agent); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, priority); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_insert_agent_belong(data->wdb, id_group, id_agent, priority); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_belong_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int id_group = 2; - int id_agent = 2; - int priority = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, id_group); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, id_agent); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, priority); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_insert_agent_belong(data->wdb, id_group, id_agent, priority); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_insert_agent_belong_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int id_group = 2; - int id_agent = 2; - int priority = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, id_group); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, id_agent); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, priority); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_insert_agent_belong(data->wdb, id_group, id_agent, priority); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_is_group_empty */ - -void test_wdb_is_group_empty_stmt_init_group_not_found(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - cJSON *result = NULL; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, SQLITE_OK); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - result = wdb_is_group_empty(data->wdb, group_name); - - assert_null(result); -} - -void test_wdb_is_group_empty_stmt_init_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - cJSON *result = NULL; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - result = wdb_is_group_empty(data->wdb, group_name); - - assert_null(result); -} - -void test_wdb_is_group_empty_stmt_init_group_found(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - cJSON *result = NULL; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - - result = wdb_is_group_empty(data->wdb, group_name); - - assert_non_null(result); -} - -void test_wdb_is_group_empty_stmt_invalid_result(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - cJSON *result = NULL; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - result = wdb_is_group_empty(data->wdb, group_name); - - assert_null(result); -} - -/* Tests wdb_global_delete_group */ - -void test_wdb_global_delete_group_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_delete_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_group_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_delete_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_group_bind_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_delete_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_group_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "test_name"; - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_delete_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_group_recalculate_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "GROUP"; - cJSON *sql_agents_id = cJSON_Parse("[{\"id_agent\":1}]"); - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":0}]"); - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, sql_agents_id); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - will_return(__wrap_w_is_single_node, 1); - will_return(__wrap_w_is_single_node, 1); - - /* wdb_global_get_agent_max_group_priority */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_PRIORITY_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - cJSON* j_path = __real_cJSON_CreateArray(); - will_return(__wrap_cJSON_CreateArray, j_path); - - //wdb_global_find_group - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - expect_string(__wrap__mwarn, formatted_msg, "Unable to find the id of the group 'default'"); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap__merror, formatted_msg, "There was an error assigning the agent '001' to default group"); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap__merror, formatted_msg, "Couldn't recalculate hash group for agent: '001'"); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_delete_group(data->wdb, group_name); - - assert_int_equal(result, OS_INVALID); - __real_cJSON_Delete(j_priority_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(sql_agents_id); - __real_cJSON_Delete(j_path); -} - -void test_wdb_global_delete_group_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - char *group_name = "GROUP"; - char *sync_status = "syncreq"; - cJSON *sql_agents_id = cJSON_Parse("[{\"id_agent\":1}]"); - int agent_id = 1; - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":0}]"); - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - char hash[] = "19dcd0dd"; //"GROUP" hash - - //wdb_is_group_empty - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_BELONG_FIND); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, sql_agents_id); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - will_return(__wrap_w_is_single_node, 0); - will_return(__wrap_w_is_single_node, 0); - - /* wdb_global_get_agent_max_group_priority */ - create_wdb_global_get_agent_max_group_priority_success_call(agent_id, j_priority_resp); - - /* wdb_global_calculate_agent_group_csv */ - create_wdb_global_calculate_agent_group_csv_success_call(agent_id, j_group_array); - - /* wdb_global_set_agent_group_context */ - create_wdb_global_set_agent_group_context_success_call(agent_id, group_name, hash, sync_status); - - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_delete_group(data->wdb, group_name); - - assert_int_equal(result, OS_SUCCESS); - __real_cJSON_Delete(j_priority_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(sql_agents_id); -} - -/* Tests wdb_global_delete_agent_belong */ - -void test_wdb_global_delete_agent_belong_transaction_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - result = wdb_global_delete_agent_belong(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_belong_cache_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - result = wdb_global_delete_agent_belong(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_belong_bind_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_delete_agent_belong(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_belong_step_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_delete_agent_belong(data->wdb, 1); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_agent_belong_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_delete_agent_belong(data->wdb, 1); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_delete_tuple_belong */ - -void test_wdb_global_delete_tuple_belong_init_stmt_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int group_id = 1; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_DELETE_TUPLE_BELONG); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - result = wdb_global_delete_tuple_belong(data->wdb, group_id, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_tuple_belong_exec_stmt_fail(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int group_id = 1; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_DELETE_TUPLE_BELONG); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, group_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - result = wdb_global_delete_tuple_belong(data->wdb, group_id, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_delete_tuple_belong_success(void **state) -{ - int result = 0; - test_struct_t *data = (test_struct_t *)*state; - int group_id = 1; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_DELETE_TUPLE_BELONG); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, group_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - result = wdb_global_delete_tuple_belong(data->wdb, group_id, agent_id); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_get_agent_info */ - -void test_wdb_global_get_agent_info_transaction_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - output = wdb_global_get_agent_info(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_info_cache_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - output = wdb_global_get_agent_info(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_info_bind_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - output = wdb_global_get_agent_info(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_info_exec_fail(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_always(__wrap_sqlite3_bind_int, index); - expect_any_always(__wrap_sqlite3_bind_int, value); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - will_return(__wrap_wdb_exec_stmt, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - output = wdb_global_get_agent_info(data->wdb, 1); - assert_null(output); -} - -void test_wdb_global_get_agent_info_success(void **state) -{ - cJSON *output = NULL; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_any_always(__wrap_sqlite3_bind_int, index); - expect_any_always(__wrap_sqlite3_bind_int, value); - will_return_always(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, (cJSON*)1); - - output = wdb_global_get_agent_info(data->wdb, 1); - assert_ptr_equal(output, (cJSON*)1); -} - -/* Tests wdb_global_get_agents_to_disconnect */ - -void test_wdb_global_get_agents_to_disconnect_transaction_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int keepalive = 100; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_to_disconnect(data->wdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_to_disconnect_cache_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int keepalive = 100; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_to_disconnect(data->wdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_to_disconnect_bind1_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int keepalive = 100; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_to_disconnect(data->wdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_to_disconnect_bind2_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int keepalive = 100; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, keepalive); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_to_disconnect(data->wdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_to_disconnect_ok(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - int keepalive = 0; - const char *sync_status = "synced"; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_OK); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_agents_to_disconnect_due(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - int keepalive = 100; - const char *sync_status = "synced"; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_DUE); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_agents_to_disconnect_err(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int keepalive = 0; - const char *sync_status = "synced"; - - //Preparing statement - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, keepalive); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - //Executing statement - wrap_wdb_exec_stmt_sized_failed_call(STMT_MULTI_COLUMN); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_to_disconnect(data->wdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_to_disconnect_invalid_elements(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int keepalive = 100; - const char *sync_status = "synced"; - cJSON* root = __real_cJSON_CreateArray(); - cJSON* json_agent = cJSON_CreateObject(); - cJSON_AddItemToArray(root, json_agent); - - //Preparing statement - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, keepalive); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - //Executing statement - wrap_wdb_exec_stmt_sized_success_call(root, STMT_MULTI_COLUMN); - //Element error - expect_string(__wrap__merror, formatted_msg, "Invalid element returned by disconnect query"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_to_disconnect(data->wdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_agents_to_disconnect_update_status_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int keepalive = 100; - const char *sync_status = "synced"; - cJSON* root = __real_cJSON_CreateArray(); - cJSON* json_agent = cJSON_CreateObject(); - cJSON_AddItemToObject(json_agent, "id", cJSON_CreateNumber(10)); - cJSON_AddItemToArray(root, json_agent); - - //Preparing statement - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, keepalive); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - //Executing statement - wrap_wdb_exec_stmt_sized_success_call(root, STMT_MULTI_COLUMN); - //Disconnect query error - will_return(__wrap_time, (time_t)0); - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_any(__wrap__mdebug1, formatted_msg); - expect_string(__wrap__merror, formatted_msg, "Cannot set connection_status for agent 10"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_to_disconnect(data->wdb, last_id, keepalive, sync_status, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -/* Tests wdb_global_get_all_agents */ - -void test_wdb_global_get_all_agents_transaction_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_all_agents(data->wdb, last_id, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_all_agents_cache_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_all_agents(data->wdb, last_id, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_all_agents_bind_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_all_agents(data->wdb, last_id, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_all_agents_ok(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, &status); - - assert_int_equal(status, WDBC_OK); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_all_agents_due(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, &status); - - assert_int_equal(status, WDBC_DUE); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_all_agents_err(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - - //Preparing statement - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - //Executing statement - wrap_wdb_exec_stmt_sized_failed_call(STMT_MULTI_COLUMN); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_all_agents(data->wdb, last_id, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -/* Tests wdb_global_reset_agents_connection */ - -void test_wdb_global_reset_agents_connection_transaction_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - int result = wdb_global_reset_agents_connection(data->wdb, sync_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_reset_agents_connection_cache_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - int result = wdb_global_reset_agents_connection(data->wdb, sync_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_reset_agents_connection_bind1_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, RESET_BY_MANAGER); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - int result = wdb_global_reset_agents_connection(data->wdb, sync_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_reset_agents_connection_bind2_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, RESET_BY_MANAGER); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - int result = wdb_global_reset_agents_connection(data->wdb, sync_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_reset_agents_step_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, RESET_BY_MANAGER); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - int result = wdb_global_reset_agents_connection(data->wdb, sync_status); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_reset_agents_connection_success(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const char *sync_status = "synced"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, RESET_BY_MANAGER); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_value(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - int result = wdb_global_reset_agents_connection(data->wdb, sync_status); - - assert_int_equal(result, OS_SUCCESS); -} - -/* Tests wdb_global_get_agents_by_connection_status */ - -void test_wdb_global_get_agents_by_connection_status_transaction_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - const char connection_status[] = "active"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, NULL, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_cache_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - const char connection_status[] = "active"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, NULL, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_and_node_cache_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - const char connection_status[] = "active"; - const char node_name[] = "node01"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, node_name, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_bind1_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - const char connection_status[] = "active"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, NULL, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_bind2_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - const char connection_status[] = "active"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, NULL, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_and_node_bind3_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - const char connection_status[] = "active"; - const char node_name[] = "node01"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, node_name, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_and_node_bind4_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int limit = -1; - const char connection_status[] = "active"; - const char node_name[] = "node01"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, limit); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, node_name, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_ok(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - const char connection_status[] = "active"; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, connection_status, NULL, -1, &status); - - assert_int_equal(status, WDBC_OK); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_agents_by_connection_status_and_node_ok(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - int limit = -1; - const char connection_status[] = "active"; - const char node_name[] = "node01"; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, connection_status, node_name, -1, &status); - - assert_int_equal(status, WDBC_OK); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_agents_by_connection_status_due(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - const char connection_status[] = "active"; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, connection_status, NULL, -1, &status); - - assert_int_equal(status, WDBC_DUE); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_agents_by_connection_status_and_node_due(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - const int agents_amount = 10; - int last_id = 0; - int limit = -1; - const char connection_status[] = "active"; - const char node_name[] = "node01"; - cJSON* root = __real_cJSON_CreateArray(); - for (int i=0; iwdb, last_id, connection_status, node_name, -1, &status); - - assert_int_equal(status, WDBC_DUE); - assert_non_null(result); - - __real_cJSON_Delete(root); -} - -void test_wdb_global_get_agents_by_connection_status_err(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - const char connection_status[] = "active"; - - //Preparing statement - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - //Executing statement - wrap_wdb_exec_stmt_sized_failed_call(STMT_MULTI_COLUMN); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, NULL, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_agents_by_connection_status_and_node_err(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int last_id = 0; - int limit = -1; - const char connection_status[] = "active"; - const char node_name[] = "node01"; - - //Preparing statement - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, last_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, connection_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, node_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, limit); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - //Executing statement - wrap_wdb_exec_stmt_sized_failed_call(STMT_MULTI_COLUMN); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_agents_by_connection_status(data->wdb, last_id, connection_status, node_name, -1, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -/* Tests wdb_global_create_backup */ - -void test_wdb_global_create_backup_commit_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char* test_date = strdup("2015/11/23 12:00:00"); - - will_return(__wrap_time, (time_t)0); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - will_return(__wrap_wdb_commit2, OS_INVALID); - - result = wdb_global_create_backup(data->wdb, data->output, "-tag"); - - assert_string_equal(data->output, "err Cannot commit current transaction to create backup"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_create_backup_prepare_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char* test_date = strdup("2015/11/23 12:00:00"); - - will_return(__wrap_time, (time_t)0); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - expect_function_call(__wrap_wdb_finalize_all_statements); - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - result = wdb_global_create_backup(data->wdb, data->output, "-tag"); - - assert_string_equal(data->output, "err DB(global) sqlite3_prepare_v2(): ERROR MESSAGE"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_create_backup_bind_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char* test_date = strdup("2015/11/23 12:00:00"); - - will_return(__wrap_time, (time_t)0); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - expect_function_call(__wrap_wdb_finalize_all_statements); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - result = wdb_global_create_backup(data->wdb, data->output, "-tag"); - - assert_string_equal(data->output, "err DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_create_backup_exec_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char* test_date = strdup("2015/11/23 12:00:00"); - - will_return(__wrap_time, (time_t)0); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - expect_function_call(__wrap_wdb_finalize_all_statements); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - - result = wdb_global_create_backup(data->wdb, data->output, "-tag"); - - assert_string_equal(data->output, "err SQLite: ERROR MESSAGE"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_create_backup_compress_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char* test_date = strdup("2015/11/23 12:00:00"); - - will_return(__wrap_time, (time_t)0); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - expect_function_call(__wrap_wdb_finalize_all_statements); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap_w_compress_gzfile, filesrc, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - expect_string(__wrap_w_compress_gzfile, filedst, "backup/db/global.db-backup-2015-11-23-12:00:00-tag.gz"); - will_return(__wrap_w_compress_gzfile, OS_INVALID); - expect_string(__wrap_unlink, file, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - will_return(__wrap_unlink, OS_SUCCESS); - - result = wdb_global_create_backup(data->wdb, data->output, "-tag"); - - assert_string_equal(data->output, "err Failed during database backup compression"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_create_backup_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char* test_date = strdup("2015/11/23 12:00:00"); - - will_return(__wrap_time, (time_t)0); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - expect_function_call(__wrap_wdb_finalize_all_statements); - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap_w_compress_gzfile, filesrc, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - expect_string(__wrap_w_compress_gzfile, filedst, "backup/db/global.db-backup-2015-11-23-12:00:00-tag.gz"); - will_return(__wrap_w_compress_gzfile, OS_SUCCESS); - expect_string(__wrap_unlink, file, "backup/db/global.db-backup-2015-11-23-12:00:00-tag"); - will_return(__wrap_unlink, OS_SUCCESS); - expect_string(__wrap__minfo, formatted_msg, "Created Global database backup \"backup/db/global.db-backup-2015-11-23-12:00:00-tag.gz\""); - cJSON* j_path = __real_cJSON_CreateArray(); - will_return(__wrap_cJSON_CreateArray, j_path); - expect_function_call(__wrap_cJSON_Delete); - - // wdb_global_remove_old_backups - will_return(__wrap_opendir, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to open backup directory 'backup/db'"); - - result = wdb_global_create_backup(data->wdb, data->output, "-tag"); - - assert_string_equal(data->output, "ok [\"backup/db/global.db-backup-2015-11-23-12:00:00-tag.gz\"]"); - assert_int_equal(result, OS_SUCCESS); - __real_cJSON_Delete(j_path); -} - -/* Tests wdb_global_remove_old_backups */ - -void test_wdb_global_remove_old_backups_opendir_failed(void **state) { - int result = OS_INVALID; - - will_return(__wrap_opendir, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to open backup directory 'backup/db'"); - - result = wdb_global_remove_old_backups(); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_remove_old_backups_success_without_removing(void **state) { - int result = OS_INVALID; - - will_return(__wrap_opendir, (DIR*)1); - will_return(__wrap_readdir, NULL); - - result = wdb_global_remove_old_backups(); - - assert_int_equal(result, OS_SUCCESS); -} - -void test_wdb_global_remove_old_backups_success(void **state) { - int result = OS_INVALID; - struct dirent* entry = calloc(1, sizeof(struct dirent)); - - snprintf(entry->d_name, OS_SIZE_256, "%s", "global.db-backup-TIMESTAMP"); - - will_return(__wrap_opendir, (DIR*)1); - // To delete a backup, it must find at least one more than max_files - wconfig.wdb_backup_settings[WDB_GLOBAL_BACKUP]->max_files = 3; - will_return_count(__wrap_readdir, entry, 4); - will_return(__wrap_readdir, NULL); - - /* wdb_global_get_oldest_backup */ - test_mode = 1; - will_return(__wrap_opendir, (DIR*)1); - will_return(__wrap_readdir, entry); - will_return(__wrap_readdir, NULL); - will_return(__wrap_time, (time_t)0); - struct stat* file_info = calloc(1, sizeof(struct stat)); - file_info->st_mtime = 0; - expect_string(__wrap_stat, __file, "backup/db/global.db-backup-TIMESTAMP"); - will_return(__wrap_stat, file_info); - will_return(__wrap_stat, OS_SUCCESS); - - expect_string(__wrap_unlink, file, "backup/db/global.db-backup-TIMESTAMP"); - will_return(__wrap_unlink, OS_SUCCESS); - expect_string(__wrap__minfo, formatted_msg, "Deleted Global database backup: \"backup/db/global.db-backup-TIMESTAMP\""); - - result = wdb_global_remove_old_backups(); - - assert_int_equal(result, OS_SUCCESS); - os_free(entry); - os_free(file_info); - test_mode = 0; -} - -/* Tests wdb_global_get_backups */ - -void test_wdb_global_get_backups_opendir_failed(void **state) { - cJSON* j_result = NULL; - - will_return(__wrap_opendir, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to open backup directory 'backup/db'"); - - j_result = wdb_global_get_backups(); - - assert_ptr_equal(j_result, NULL); -} - -void test_wdb_global_get_backups_success(void **state) { - cJSON* j_result = NULL; - struct dirent* entry = calloc(1, sizeof(struct dirent)); - - snprintf(entry->d_name, OS_SIZE_256, "%s", "global.db-backup-TIMESTAMP"); - - will_return(__wrap_opendir, (DIR*)1); - will_return_count(__wrap_readdir, entry, 2); - will_return(__wrap_readdir, NULL); - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - j_result = wdb_global_get_backups(); - - char* str_result = cJSON_PrintUnformatted(j_result); - assert_string_equal(str_result, "[\"global.db-backup-TIMESTAMP\",\"global.db-backup-TIMESTAMP\"]"); - os_free(entry); - os_free(str_result); - __real_cJSON_Delete(j_result); -} - -/* Tests wdb_global_restore_backup */ - -void test_wdb_global_restore_backup_pre_restore_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char* test_date = strdup("2015/11/23 12:00:00"); - - will_return(__wrap_time, (time_t)0); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - will_return(__wrap_wdb_commit2, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "Creating pre-restore Global DB snapshot failed. Backup restore stopped: " - "err Cannot commit current transaction to create backup"); - - result = wdb_global_restore_backup(&data->wdb, "global.db-backup-TIMESTAMP", true, data->output); - - assert_string_equal(data->output, "err Cannot commit current transaction to create backup"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_restore_backup_no_snapshot(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - - // wdb_global_get_most_recent_backup - will_return(__wrap_opendir, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to open backup directory 'backup/db'"); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to found a snapshot to restore"); - - result = wdb_global_restore_backup(&data->wdb, NULL, false, data->output); - - assert_string_equal(data->output, "err Unable to found a snapshot to restore"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_restore_backup_compression_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - - expect_string(__wrap_w_uncompress_gzfile, gzfilesrc, "backup/db/global.db-backup-TIMESTAMP.gz"); - expect_string(__wrap_w_uncompress_gzfile, gzfiledst, "queue/db/global.db.back"); - will_return(__wrap_w_uncompress_gzfile, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Failed during backup decompression"); - - result = wdb_global_restore_backup(&data->wdb, "global.db-backup-TIMESTAMP.gz", false, data->output); - - assert_string_equal(data->output, "err Failed during backup decompression"); - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_restore_backup_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - wdb_t *wdb = NULL; - os_calloc(1,sizeof(wdb_t),wdb); - os_strdup("global",wdb->id); - os_calloc(1,sizeof(sqlite3 *),wdb->db); - - expect_string(__wrap_w_uncompress_gzfile, gzfilesrc, "backup/db/global.db-backup-TIMESTAMP.gz"); - expect_string(__wrap_w_uncompress_gzfile, gzfiledst, "queue/db/global.db.back"); - will_return(__wrap_w_uncompress_gzfile, OS_SUCCESS); - will_return(__wrap_wdb_close, 1); - will_return(__wrap_wdb_close, OS_SUCCESS); - expect_string(__wrap_unlink, file, "queue/db/global.db"); - will_return(__wrap_unlink, OS_SUCCESS); - expect_string(__wrap_rename, __old, "queue/db/global.db.back"); - expect_string(__wrap_rename, __new, "queue/db/global.db"); - will_return(__wrap_rename, OS_SUCCESS); - - result = wdb_global_restore_backup(&wdb, "global.db-backup-TIMESTAMP.gz", false, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(result, OS_SUCCESS); - os_free(wdb->id); - os_free(wdb); -} - -/* Tests wdb_global_get_most_recent_backup */ - -void test_wdb_global_get_most_recent_backup_opendir_failed(void **state) { - char* most_recent_backup_name = NULL; - time_t most_recent_backup_time = OS_INVALID; - - will_return(__wrap_opendir, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to open backup directory 'backup/db'"); - - most_recent_backup_time = wdb_global_get_most_recent_backup(&most_recent_backup_name); - - assert_int_equal(most_recent_backup_time, OS_INVALID); - assert_ptr_equal(most_recent_backup_name, NULL); -} - -void test_wdb_global_get_most_recent_backup_success(void **state) { - char* most_recent_backup_name = NULL; - time_t most_recent_backup_time = OS_INVALID; - struct dirent* entry = calloc(1, sizeof(struct dirent)); - struct stat* file_info = calloc(1, sizeof(struct stat)); - - test_mode = 1; - snprintf(entry->d_name, OS_SIZE_256, "%s", "global.db-backup-TIMESTAMP"); - will_return(__wrap_opendir, (DIR*)1); - will_return(__wrap_readdir, entry); - will_return(__wrap_readdir, NULL); - file_info->st_mtime = 123; - expect_string(__wrap_stat, __file, "backup/db/global.db-backup-TIMESTAMP"); - will_return(__wrap_stat, file_info); - will_return(__wrap_stat, OS_SUCCESS); - - most_recent_backup_time = wdb_global_get_most_recent_backup(&most_recent_backup_name); - - assert_int_equal(most_recent_backup_time, 123); - assert_string_equal(most_recent_backup_name, "global.db-backup-TIMESTAMP"); - os_free(most_recent_backup_name); - os_free(entry); - os_free(file_info); - test_mode = 0; -} - -/* Tests wdb_global_get_oldest_backup */ - -void test_wdb_global_get_oldest_backup_opendir_failed(void **state) { - char* oldest_backup_name = NULL; - time_t oldest_backup_time = OS_INVALID; - - will_return(__wrap_opendir, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to open backup directory 'backup/db'"); - - oldest_backup_time = wdb_global_get_oldest_backup(&oldest_backup_name); - - assert_int_equal(oldest_backup_time, OS_INVALID); - assert_ptr_equal(oldest_backup_name, NULL); -} - -void test_wdb_global_get_oldest_backup_success(void **state) { - char* oldest_backup_name = NULL; - time_t oldest_backup_time = OS_INVALID; - struct dirent* entry = calloc(1, sizeof(struct dirent)); - struct stat* file_info = calloc(1, sizeof(struct stat)); - - test_mode = 1; - will_return(__wrap_opendir, (DIR*)1); - will_return(__wrap_time, (time_t)123); - snprintf(entry->d_name, OS_SIZE_256, "%s", "global.db-backup-TIMESTAMP"); - will_return(__wrap_readdir, entry); - will_return(__wrap_readdir, NULL); - file_info->st_mtime = 123; - expect_string(__wrap_stat, __file, "backup/db/global.db-backup-TIMESTAMP"); - will_return(__wrap_stat, file_info); - will_return(__wrap_stat, OS_SUCCESS); - - oldest_backup_time = wdb_global_get_oldest_backup(&oldest_backup_name); - - assert_int_equal(oldest_backup_time, 123); - assert_string_equal(oldest_backup_name, "global.db-backup-TIMESTAMP"); - os_free(oldest_backup_name); - os_free(entry); - os_free(file_info); - test_mode = 0; -} - -/* Tests wdb_global_update_agent_groups_hash */ - -void test_wdb_global_update_agent_groups_hash_begin_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char *groups_string = "group1,group2"; - - data->wdb->transaction = 0; - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - will_return(__wrap_wdb_begin2, OS_INVALID); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, groups_string); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_groups_hash_cache_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char *groups_string = "group1,group2"; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, groups_string); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_groups_hash_bind_text_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char *groups_string = "group1,group2"; - char *groups_string_hash = "ef48b4cd"; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, groups_string_hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, groups_string); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_groups_hash_bind_int_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char *groups_string = "group1,group2"; - char *groups_string_hash = "ef48b4cd"; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, groups_string_hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, groups_string); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_groups_hash_step_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char *groups_string = "group1,group2"; - char *groups_string_hash = "ef48b4cd"; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, groups_string_hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, groups_string); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_update_agent_groups_hash_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char *groups_string = "group1,group2"; - char *groups_string_hash = "ef48b4cd"; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, groups_string_hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, groups_string); - - assert_int_equal(result, OS_SUCCESS); -} - -void test_wdb_global_update_agent_groups_hash_groups_string_null_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char *groups_string = "group1,group2"; - char *groups_string_hash = "ef48b4cd"; - data->wdb->transaction = 1; - - // wdb_global_select_agent_group - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - cJSON *j_result = __real_cJSON_CreateArray(); - cJSON *j_object = cJSON_CreateObject(); - cJSON_AddItemToObject(j_object, "group", cJSON_CreateString(groups_string)); - cJSON_AddItemToArray(j_result, j_object); - will_return(__wrap_wdb_exec_stmt, j_result); - expect_function_call(__wrap_cJSON_Delete); - - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, groups_string_hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, NULL); - - assert_int_equal(result, OS_SUCCESS); - __real_cJSON_Delete(j_result); -} - -void test_wdb_global_update_agent_groups_hash_empty_group_column_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - data->wdb->transaction = 1; - - // wdb_global_select_agent_group - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - cJSON *j_result = __real_cJSON_CreateArray(); - cJSON *j_object = cJSON_CreateObject(); - cJSON_AddItemToArray(j_result, j_object); - will_return(__wrap_wdb_exec_stmt, j_result); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap__mdebug2, formatted_msg, "Unable to get group column for agent '1'. The groups_hash column won't be updated"); - - int result = wdb_global_update_agent_groups_hash(data->wdb, agent_id, NULL); - - assert_int_equal(result, OS_SUCCESS); - __real_cJSON_Delete(j_result); -} - -/* Tests wdb_global_adjust_v4 */ - -void test_wdb_global_adjust_v4_begin_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->wdb->transaction = 0; - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - will_return(__wrap_wdb_begin2, OS_INVALID); - - int result = wdb_global_adjust_v4(data->wdb); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_adjust_v4_cache_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - int result = wdb_global_adjust_v4(data->wdb); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_adjust_v4_bind_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - int result = wdb_global_adjust_v4(data->wdb); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_adjust_v4_step_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: ERROR MESSAGE"); - - int result = wdb_global_adjust_v4(data->wdb); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_adjust_v4_commit_fail(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, agent_id); - - // wdb_global_select_agent_group - char *groups_string = "group1,group2"; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - cJSON *j_result = __real_cJSON_CreateArray(); - cJSON *j_object = cJSON_CreateObject(); - cJSON_AddItemToObject(j_object, "group", cJSON_CreateString(groups_string)); - cJSON_AddItemToArray(j_result, j_object); - will_return(__wrap_wdb_exec_stmt, j_result); - expect_function_call(__wrap_cJSON_Delete); - - // wdb_global_update_agent_groups_hash - char *groups_string_hash = "ef48b4cd"; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, groups_string_hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_commit2, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "DB(global) The commit statement could not be executed."); - - int result = wdb_global_adjust_v4(data->wdb); - - assert_int_equal(result, OS_INVALID); - __real_cJSON_Delete(j_result); -} - -void test_wdb_global_adjust_v4_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, agent_id); - - // wdb_global_select_agent_group - char *groups_string = "group1,group2"; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - cJSON *j_result = __real_cJSON_CreateArray(); - cJSON *j_object = cJSON_CreateObject(); - cJSON_AddItemToObject(j_object, "group", cJSON_CreateString(groups_string)); - cJSON_AddItemToArray(j_result, j_object); - will_return(__wrap_wdb_exec_stmt, j_result); - expect_function_call(__wrap_cJSON_Delete); - - // wdb_global_update_agent_groups_hash - char *groups_string_hash = "ef48b4cd"; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, groups_string_hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - int result = wdb_global_adjust_v4(data->wdb); - - assert_int_equal(result, OS_SUCCESS); - __real_cJSON_Delete(j_result); -} - -/* Tests wdb_global_calculate_agent_group_csv */ - -void test_wdb_global_calculate_agent_group_csv_unable_to_get_group(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - // wdb_global_select_group_belong - data->wdb->transaction = 0; - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - expect_string(__wrap__mdebug1, formatted_msg, "Unable to get groups of agent '001'"); - - char *result = wdb_global_calculate_agent_group_csv(data->wdb, agent_id); - - assert_ptr_equal(result, NULL); -} - -void test_wdb_global_calculate_agent_group_csv_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - // wdb_global_select_group_belong - data->wdb->transaction = 1; - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - cJSON *j_groups = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_groups, cJSON_CreateString("group1")); - cJSON_AddItemToArray(j_groups, cJSON_CreateString("group2")); - /* wdb_exec_stmt_sized */ - wrap_wdb_exec_stmt_sized_success_call(j_groups, STMT_SINGLE_COLUMN); - - expect_function_call(__wrap_cJSON_Delete); - - char *result = wdb_global_calculate_agent_group_csv(data->wdb, agent_id); - - assert_string_equal(result, "group1,group2"); - os_free(result); - __real_cJSON_Delete(j_groups); -} - -/* wdb_global_assign_agent_group */ - -void test_wdb_global_assign_agent_group_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - int initial_priority = 0; - int actual_priority = initial_priority; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - char group_name[GROUPS_SIZE][OS_SIZE_128] = {0}; - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups, initial_priority); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -void test_wdb_global_assign_agent_group_insert_belong_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int initial_priority = 0; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - char debug_message[GROUPS_SIZE][OS_MAXSTR] = {0}; - char group_name[GROUPS_SIZE][OS_SIZE_128] = {0}; - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups, initial_priority); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -void test_wdb_global_assign_agent_group_find_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int initial_priority = 0; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - char warn_message[GROUPS_SIZE][OS_MAXSTR] = {0}; - char group_name[GROUPS_SIZE][OS_SIZE_128] = {0}; - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups, initial_priority); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -void test_wdb_global_assign_agent_group_invalid_json(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int initial_priority = 0; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups, initial_priority); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -/* wdb_global_unassign_agent_group */ - -void test_wdb_global_unassign_agent_group_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - char group_name[GROUPS_SIZE][OS_SIZE_128] = {0}; - cJSON* j_groups = __real_cJSON_CreateArray(); - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":0}]"); - - for (int i=0; iwdb, agent_id, j_groups); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); - __real_cJSON_Delete(j_priority_resp); -} - -/** - * @brief Configure all the wrappers to simulate a successful call to wdb_global_assign_agent_group() method - * @param agent_id The id of the agent being assigned in the belongs table - * @param group_id The id of the group being assigned in the belongs table - * @param group_name The name of the group being inserted in the group table - * @param find_group_resp The response of the find group query - */ -void create_wdb_global_assign_agent_group_success_call(int agent_id, int group_id, char* group_name, cJSON* find_group_resp) { - int actual_priority = 0; - // wdb_global_find_group - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, group_name); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, find_group_resp); - expect_function_call(__wrap_cJSON_Delete); - // wdb_global_insert_agent_belong - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, group_id); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, actual_priority); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); -} - -void test_wdb_global_unassign_agent_group_success_assign_default_group(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_groups = __real_cJSON_CreateArray(); - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":-1}]"); - - cJSON_AddItemToArray(j_groups, cJSON_CreateString("random_group")); - - // wdb_global_find_group - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "random_group"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_find_group_resp); - - expect_function_call(__wrap_cJSON_Delete); - - // wdb_global_delete_tuple_belong - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_DELETE_TUPLE_BELONG); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, group_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - /* wdb_global_get_agent_max_group_priority */ - create_wdb_global_get_agent_max_group_priority_success_call(agent_id, j_priority_resp); - - cJSON* j_default_group = __real_cJSON_CreateArray(); - will_return(__wrap_cJSON_CreateArray, j_default_group); - expect_function_call(__wrap_cJSON_Delete); - - /* wdb_global_assign_agent_group */ - create_wdb_global_assign_agent_group_success_call(agent_id, group_id, "default", j_find_group_resp); - expect_string(__wrap__mdebug1, formatted_msg, "Agent '001' reassigned to 'default' group"); - - wdbc_result result = wdb_global_unassign_agent_group(data->wdb, agent_id, j_groups); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_priority_resp); - __real_cJSON_Delete(j_default_group); -} - -void test_wdb_global_unassign_agent_group_delete_tuple_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - char debug_message[GROUPS_SIZE][OS_MAXSTR] = {0}; - char group_name[GROUPS_SIZE][OS_SIZE_128] = {0}; - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -void test_wdb_global_unassign_agent_group_find_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - char warn_message[GROUPS_SIZE][OS_MAXSTR] = {0}; - char group_name[GROUPS_SIZE][OS_SIZE_128] = {0}; - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -void test_wdb_global_unassign_agent_group_find_invalid_response(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":\"invalid\"}]"); - char group_name[GROUPS_SIZE][OS_SIZE_128] = {0}; - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -void test_wdb_global_unassign_agent_group_invalid_json(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON* find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_groups = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, agent_id, j_groups); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(find_group_resp); -} - -void test_wdb_global_unassign_agent_group_error_assign_default_group(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_groups = __real_cJSON_CreateArray(); - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":-1}]"); - - cJSON_AddItemToArray(j_groups, cJSON_CreateString("random_group")); - - // wdb_global_find_group - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "random_group"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_find_group_resp); - - expect_function_call(__wrap_cJSON_Delete); - - // wdb_global_delete_tuple_belong - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_DELETE_TUPLE_BELONG); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, group_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - /* wdb_global_get_agent_max_group_priority */ - create_wdb_global_get_agent_max_group_priority_success_call(agent_id, j_priority_resp); - - cJSON* j_default_group = __real_cJSON_CreateArray(); - will_return(__wrap_cJSON_CreateArray, j_default_group); - expect_function_call(__wrap_cJSON_Delete); - - /* wdb_global_if_empty_set_default_agent_group */ - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "default"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_find_group_resp); - expect_function_call(__wrap_cJSON_Delete); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to insert group 'default' for agent '1'"); - - expect_string(__wrap__merror, formatted_msg, "There was an error assigning the agent '001' to default group"); - - wdbc_result result = wdb_global_unassign_agent_group(data->wdb, agent_id, j_groups); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_priority_resp); - __real_cJSON_Delete(j_default_group); -} - -/* wdb_global_set_agent_group_context */ - -void test_wdb_global_set_agent_group_context_success(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char* csv = "GROUP1,GROUP2,GROUP3"; - char* hash = "DUMMYHASH"; - char* sync_status = "synced"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_CTX_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, csv); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - wdbc_result result = wdb_global_set_agent_group_context(data->wdb, agent_id, csv, hash, sync_status); - - assert_int_equal(result, WDBC_OK); -} - -void test_wdb_global_set_agent_group_context_init_stmt_error(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char* csv = "GROUP1,GROUP2,GROUP3"; - char* hash = "DUMMYHASH"; - char* sync_status = "synced"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_CTX_SET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - wdbc_result result = wdb_global_set_agent_group_context(data->wdb, agent_id, csv, hash, sync_status); - - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_set_agent_group_context_exec_stmt_error(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char* csv = "GROUP1,GROUP2,GROUP3"; - char* hash = "DUMMYHASH"; - char* sync_status = "synced"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_CTX_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, csv); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, sync_status); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "Error executing setting the agent group context: ERROR MESSAGE"); - - wdbc_result result = wdb_global_set_agent_group_context(data->wdb, agent_id, csv, hash, sync_status); - - assert_int_equal(result, WDBC_ERROR); -} - -/* wdb_global_set_agent_group_hash */ - -void test_wdb_global_set_agent_group_hash_success(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char* csv = "GROUP1,GROUP2,GROUP3"; - char* hash = "DUMMYHASH"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_HASH_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, csv); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - wdbc_result result = wdb_global_set_agent_group_hash(data->wdb, agent_id, csv, hash); - - assert_int_equal(result, WDBC_OK); -} - -void test_wdb_global_set_agent_group_hash_init_stmt_error(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char* csv = "GROUP1,GROUP2,GROUP3"; - char* hash = "DUMMYHASH"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_HASH_SET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - wdbc_result result = wdb_global_set_agent_group_hash(data->wdb, agent_id, csv, hash); - - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_global_set_agent_group_hash_exec_stmt_error(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char* csv = "GROUP1,GROUP2,GROUP3"; - char* hash = "DUMMYHASH"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_HASH_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, csv); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, hash); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt_silent, OS_INVALID); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "Error executing setting the agent group hash: ERROR MESSAGE"); - - wdbc_result result = wdb_global_set_agent_group_hash(data->wdb, agent_id, csv, hash); - - assert_int_equal(result, WDBC_ERROR); -} - -/* Tests wdb_global_groups_number_get */ - -void test_wdb_global_groups_number_get_stmt_error(void **state) -{ - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_AGENT_GROUPS_NUMBER_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - result = wdb_global_groups_number_get(data->wdb, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_groups_number_get_bind_fail(void **state) -{ - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_AGENT_GROUPS_NUMBER_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - result = wdb_global_groups_number_get(data->wdb, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_groups_number_get_exec_fail(void **state) -{ - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_AGENT_GROUPS_NUMBER_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR MESSAGE"); - - result = wdb_global_groups_number_get(data->wdb, agent_id); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_groups_number_get_success(void **state) -{ - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON *j_groups_number = cJSON_Parse("[{\"groups_number\":100}]"); - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_AGENT_GROUPS_NUMBER_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt, j_groups_number); - expect_function_call(__wrap_cJSON_Delete); - - result = wdb_global_groups_number_get(data->wdb, agent_id); - - assert_int_equal(result, 100); - __real_cJSON_Delete(j_groups_number); -} - -/* wdb_global_validate_group_name */ - -void test_wdb_global_validate_group_name_fail_group_name_contains_invalid_character_1(void **state) -{ - char *group_name = "group_name,with_comma"; - - expect_string(__wrap__mwarn, formatted_msg, "Invalid group name. 'group_name,with_comma' " - "contains invalid characters"); - - w_err_t result = wdb_global_validate_group_name(group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_validate_group_name_fail_group_name_contains_invalid_character_2(void **state) -{ - char *group_name = "group_name/with_slash"; - - expect_string(__wrap__mwarn, formatted_msg, "Invalid group name. 'group_name/with_slash' " - "contains invalid characters"); - - w_err_t result = wdb_global_validate_group_name(group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_validate_group_name_fail_group_name_exceeds_max_length(void **state) -{ - char *group_name = "zrosiZrfyMMKt9Lw9qMTCO45OsaFG0NOiHn8noYsuuXHCqPCeDpFE3NxZt8mb44g6G36xL4y59TA_7obQfkSwjczMp9vrNZI9Jltc_8k322ZApibRftAi_T6SD9-AD0YwY_eWbG-uSfYw7BFX2OAgkD2vp3Z9AgZsN3NQNiDG1ng5WNm5H_bbLh6_BtotzJfNYr8awmZ62IuhTH6eNLN9yzn4ZhWt_XxaHUe6O-uf68PNh4HMv3NuvDGFFXBkysN"; - - expect_string(__wrap__mwarn, formatted_msg, "Invalid group name. The group 'zrosiZrfyMMKt9Lw9qMTCO45OsaFG0NOiHn8noYsuuXHCqPCeDpFE3NxZt8mb44g" - "6G36xL4y59TA_7obQfkSwjczMp9vrNZI9Jltc_8k322ZApibRftAi_T6SD9-AD0Y" - "wY_eWbG-uSfYw7BFX2OAgkD2vp3Z9AgZsN3NQNiDG1ng5WNm5H_bbLh6_BtotzJf" - "NYr8awmZ62IuhTH6eNLN9yzn4ZhWt_XxaHUe6O-uf68PNh4HMv3NuvDGFFXBkysN'" - " exceeds the maximum length of 255 characters permitted"); - - w_err_t result = wdb_global_validate_group_name(group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_validate_group_name_fail_group_name_current_directory_reserved_name(void **state) -{ - char *group_name = "."; - - expect_string(__wrap__mwarn, formatted_msg, "Invalid group name. '.' represents the current directory in unix systems"); - - w_err_t result = wdb_global_validate_group_name(group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_validate_group_name_fail_group_name_parent_directory_reserved_name(void **state) -{ - char *group_name = ".."; - - expect_string(__wrap__mwarn, formatted_msg, "Invalid group name. '..' represents the parent directory in unix systems"); - - w_err_t result = wdb_global_validate_group_name(group_name); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_validate_group_name_success(void **state) -{ - char *group_name = "5eCJIZNU_U8vxPcxPXOrtCM22qKbwz95jvkQVYpHwbz6D9KUIgLyd-Tf1HnBJrAUqI9ytsLdMVA6UhOM6Ej_XAVU9POtKCUzJSHml0g7yOzBnuNxt-8VzL2t5tosAZ7zBImnl0Yq-1LgAVecU_p7yBTw5ZmXg3ZswuCgeVrD0NSk_bwOKMHeRx7XuvIOlJGRC8YO7QeE6Gpc_tK5ZkAty4HyVlMlUI72kQeDAoGK1mhq1LfiUu9VGNFXi6HBGnd"; - - w_err_t result = wdb_global_validate_group_name(group_name); - - assert_int_equal(result, OS_SUCCESS); -} - -/* wdb_global_validate_groups */ - -void test_wdb_global_validate_groups_fail_groups_exceeds_max_number(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON* j_groups = __real_cJSON_CreateArray(); - char group_name[MAX_GROUP_NAME] = {0}; - - snprintf(group_name, MAX_GROUP_NAME, "RANDOM_GROUP"); - cJSON_AddItemToArray(j_groups, cJSON_CreateString(group_name)); - - /* wdb_global_groups_number_get */ - cJSON *j_groups_number = cJSON_Parse("[{\"groups_number\":128}]"); - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_AGENT_GROUPS_NUMBER_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_groups_number); - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap__mwarn, formatted_msg, "The groups assigned to agent 001 exceed the maximum of 128 permitted."); - - w_err_t result = wdb_global_validate_groups(data->wdb, j_groups, agent_id); - - assert_int_equal(result, OS_INVALID); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(j_groups_number); -} - -void test_wdb_global_validate_groups_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - cJSON* j_groups = __real_cJSON_CreateArray(); - char group_name[MAX_GROUP_NAME+1] = {0}; - - snprintf(group_name, MAX_GROUP_NAME+1, - /* Random 255 characters long group name */ - "5eCJIZNU_U8vxPcxPXOrtCM22qKbwz95jvkQVYpHwbz6D9KUIgLyd-Tf1HnBJrAU" - "qI9ytsLdMVA6UhOM6Ej_XAVU9POtKCUzJSHml0g7yOzBnuNxt-8VzL2t5tosAZ7z" - "BImnl0Yq-1LgAVecU_p7yBTw5ZmXg3ZswuCgeVrD0NSk_bwOKMHeRx7XuvIOlJGR" - "C8YO7QeE6Gpc_tK5ZkAty4HyVlMlUI72kQeDAoGK1mhq1LfiUu9VGNFXi6HBGnd" - ); - cJSON_AddItemToArray(j_groups, cJSON_CreateString(group_name)); - - /* wdb_global_groups_number_get */ - cJSON *j_groups_number = cJSON_Parse("[{\"groups_number\":127}]"); - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_AGENT_GROUPS_NUMBER_GET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt*)1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_groups_number); - expect_function_call(__wrap_cJSON_Delete); - - w_err_t result = wdb_global_validate_groups(data->wdb, j_groups, agent_id); - - assert_int_equal(result, OS_SUCCESS); - __real_cJSON_Delete(j_groups); - __real_cJSON_Delete(j_groups_number); -} - -/* wdb_global_set_agent_groups */ - -void test_wdb_global_set_agent_groups_override_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - char group_name[] = "GROUP"; - char hash[] = "19dcd0dd"; //"GROUP" hash - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_OVERRIDE; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_groups_number = cJSON_Parse("[{\"groups_number\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_groups_number); -} - -void test_wdb_global_set_agent_groups_override_delete_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - char group_name[] = "GROUP"; - char hash[] = "19dcd0dd"; //"GROUP" hash - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_OVERRIDE; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_groups_number = cJSON_Parse("[{\"groups_number\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_groups_number); -} - -void test_wdb_global_set_agent_groups_add_modes_assign_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char group_name[] = "GROUP"; - char hash[] = "19dcd0dd"; //"GROUP" hash - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_OVERRIDE; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_group_array_invalid = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array_invalid, cJSON_CreateNumber(-1)); //Invalid group information - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_groups_number = cJSON_Parse("[{\"groups_number\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_group_array_invalid); - __real_cJSON_Delete(j_groups_number); -} - -void test_wdb_global_set_agent_groups_append_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - char group_name[] = "GROUP"; - char hash[] = "19dcd0dd"; //"GROUP" hash - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_APPEND; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_priority_resp = cJSON_Parse("[]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_groups_number = cJSON_Parse("[{\"groups_number\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_priority_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_groups_number); -} - -void test_wdb_global_set_agent_groups_empty_only_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - char group_name[] = "GROUP"; - char hash[] = "19dcd0dd"; //"GROUP" hash - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_EMPTY_ONLY; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_priority_resp = cJSON_Parse("[]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_groups_number = cJSON_Parse("[{\"groups_number\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_priority_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_groups_number); -} - -void test_wdb_global_set_agent_groups_empty_only_not_empty_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char group_name[] = "GROUP"; - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_EMPTY_ONLY; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_priority_resp = cJSON_Parse("[{\"MAX(priority)\":0}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_priority_resp); - __real_cJSON_Delete(j_group_array); -} - -void test_wdb_global_set_agent_groups_remove_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - char group_name[] = "GROUP"; - char hash[] = "19dcd0dd"; //"GROUP" hash - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_REMOVE; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_priority_resp); -} - -void test_wdb_global_set_agent_groups_remove_unassign_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - char group_name[] = "GROUP"; - char hash[] = "19dcd0dd"; //"GROUP" hash - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_REMOVE; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_group_array_invalid = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array_invalid, cJSON_CreateNumber(-1)); //Invalid group information - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_group_array_invalid); -} - -void test_wdb_global_set_agent_groups_invalid_json(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_REMOVE; - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_agents_group_info); -} - -void test_wdb_global_set_agent_groups_calculate_csv_empty(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - char group_name[] = "GROUP"; - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_REMOVE; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_OK); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_priority_resp); -} - -void test_wdb_global_set_agent_groups_set_group_ctx_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int agent_id = 1; - int group_id = 1; - char group_name[] = "GROUP"; - char sync_status[] = "synced"; - wdb_groups_set_mode_t mode = WDB_GROUP_REMOVE; - cJSON* j_group_array = __real_cJSON_CreateArray(); - cJSON_AddItemToArray(j_group_array, cJSON_CreateString(group_name)); - cJSON* j_find_group_resp = cJSON_Parse("[{\"id\":1}]"); - cJSON* j_agents_group_info = __real_cJSON_CreateArray(); - cJSON* j_priority_resp = cJSON_Parse("[{\"id\":0}]"); - - for (int i=0; iwdb, mode, sync_status, j_agents_group_info); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(j_agents_group_info); - __real_cJSON_Delete(j_find_group_resp); - __real_cJSON_Delete(j_group_array); - __real_cJSON_Delete(j_priority_resp); -} - -void test_wdb_global_set_agent_groups_sync_status_invalid_stmt(){ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNC_SET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - assert_int_equal(OS_INVALID, wdb_global_set_agent_groups_sync_status((wdb_t *)0xDEADBEEF, 1, "test")); -} - -void test_wdb_global_set_agent_groups_sync_status_bad_bind_sync(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char sync[] = "test"; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNC_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt *)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, sync); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "test_error"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): test_error"); - - assert_int_equal(OS_INVALID, wdb_global_set_agent_groups_sync_status(data->wdb, 1, sync)); -} - -void test_wdb_global_set_agent_groups_sync_status_bad_bind_id(void** state){ - test_struct_t *data = (test_struct_t *)*state; - char sync[] = "test"; - int id = 001; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNC_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt *)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, sync); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, id); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "test_error"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): test_error"); - - assert_int_equal(OS_INVALID, wdb_global_set_agent_groups_sync_status(data->wdb, id, sync)); -} - -void test_wdb_global_set_agent_groups_sync_status_success(void** state){ - test_struct_t *data = (test_struct_t *)*state; - char sync[] = "test"; - int id = 001; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_SYNC_SET); - will_return(__wrap_wdb_init_stmt_in_cache, (sqlite3_stmt *)1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, sync); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, id); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - - will_return(__wrap_wdb_exec_stmt_silent, OS_SUCCESS); - - assert_int_equal(OS_SUCCESS, wdb_global_set_agent_groups_sync_status(data->wdb, id, sync)); -} - -/* Tests wdb_global_get_distinct_agent_groups */ - -void test_wdb_global_get_distinct_agent_groups_transaction_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char group_hash[] = "abcdef"; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_distinct_agent_groups(data->wdb, group_hash, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_distinct_agent_groups_cache_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char group_hash[] = "abcdef"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_distinct_agent_groups(data->wdb, group_hash, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_distinct_agent_groups_bind_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char group_hash[] = "abcdef"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "abcdef"); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_text(): ERROR MESSAGE"); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_distinct_agent_groups(data->wdb, group_hash, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_distinct_agent_groups_exec_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char group_hash[] = "abcdef"; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "abcdef"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - wrap_wdb_exec_stmt_sized_failed_call(STMT_MULTI_COLUMN); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_distinct_agent_groups(data->wdb, group_hash, &status); - - assert_int_equal(status, WDBC_ERROR); - assert_null(result); -} - -void test_wdb_global_get_distinct_agent_groups_succes_due(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char group_hash[] = "abcdef"; - cJSON* j_result = cJSON_Parse("[{\"group\":\"group1\",\"group_hash\":\"ec282560\"}]"); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "abcdef"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - wrap_wdb_exec_stmt_sized_socket_full_call(j_result, STMT_MULTI_COLUMN); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_distinct_agent_groups(data->wdb, group_hash, &status); - - char *output = cJSON_PrintUnformatted(result); - assert_string_equal(output, "[{\"group\":\"group1\",\"group_hash\":\"ec282560\"}]"); - os_free(output); - assert_int_equal(status, WDBC_DUE); - __real_cJSON_Delete(result); -} - -void test_wdb_global_get_distinct_agent_groups_succes_ok(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - char group_hash[] = "abcdef"; - cJSON* j_result = cJSON_Parse("[{\"group\":\"group1\",\"group_hash\":\"ec282560\"}]"); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "abcdef"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - - wrap_wdb_exec_stmt_sized_success_call(j_result, STMT_MULTI_COLUMN); - - wdbc_result status = WDBC_UNKNOWN; - cJSON* result = wdb_global_get_distinct_agent_groups(data->wdb, group_hash, &status); - - char *output = cJSON_PrintUnformatted(result); - assert_string_equal(output, "[{\"group\":\"group1\",\"group_hash\":\"ec282560\"}]"); - os_free(output); - assert_int_equal(status, WDBC_OK); - __real_cJSON_Delete(result); -} - -/* Tests wdb_global_recalculate_all_agent_groups_hash */ - -void test_wdb_global_recalculate_all_agent_groups_hash_transaction_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - - int result = wdb_global_recalculate_all_agent_groups_hash(data->wdb); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_recalculate_all_agent_groups_hash_cache_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - int result = wdb_global_recalculate_all_agent_groups_hash(data->wdb); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_recalculate_all_agent_groups_hash_bind_fail(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_bind_int(): ERROR MESSAGE"); - - int result = wdb_global_recalculate_all_agent_groups_hash(data->wdb); - - assert_int_equal(result, OS_INVALID); -} - -void test_wdb_global_recalculate_all_agent_groups_hash_exec_stmt_null(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, NULL); - - expect_function_call(__wrap_cJSON_Delete); - - int result = wdb_global_recalculate_all_agent_groups_hash(data->wdb); - - assert_int_equal(result, OS_SUCCESS); -} - -void test_wdb_global_recalculate_all_agent_groups_hash_invalid_id(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - - json_agent = cJSON_CreateObject(); - cJSON_AddStringToObject(json_agent, "id", "id_str"); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, json_agent); - - expect_string(__wrap__merror, formatted_msg, "Invalid element returned by get all agents query"); - - expect_function_call(__wrap_cJSON_Delete); - - int result = wdb_global_recalculate_all_agent_groups_hash(data->wdb); - - assert_int_equal(result, OS_INVALID); - __real_cJSON_Delete(json_agent); -} - -void test_wdb_global_recalculate_all_agent_groups_hash_recalculate_error(void **state) -{ - test_struct_t *data = (test_struct_t *)*state; - cJSON *json_agent = NULL; - int agent_id = 1; - - cJSON* j_stmt_result = __real_cJSON_CreateArray(); - json_agent = cJSON_CreateObject(); - cJSON_AddItemToObject(json_agent, "id", cJSON_CreateNumber(agent_id)); - cJSON_AddItemToArray(j_stmt_result, json_agent); - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 0); - will_return(__wrap_sqlite3_bind_int, SQLITE_OK); - will_return(__wrap_wdb_exec_stmt, j_stmt_result); - - /* wdb_global_calculate_agent_group_csv */ - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot begin transaction"); - expect_string(__wrap__mdebug1, formatted_msg, "Unable to get groups of agent '001'"); - expect_string(__wrap__mdebug1, formatted_msg, "No groups in belongs table for agent '001'"); - - /* wdb_global_set_agent_group_context */ - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_HASH_SET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - expect_string(__wrap__merror, formatted_msg, "There was an error assigning the groups hash to agent '001'"); - - expect_string(__wrap__merror, formatted_msg, "Couldn't recalculate hash group for agent: '001'"); - - expect_function_call(__wrap_cJSON_Delete); - - int result = wdb_global_recalculate_all_agent_groups_hash(data->wdb); - - assert_int_equal(result, OS_INVALID); - __real_cJSON_Delete(j_stmt_result); -} - - -int main() -{ - const struct CMUnitTest tests[] = { - /* Tests wdb_global_get_agent_labels */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_labels_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_labels_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_labels_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_labels_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_labels_success, test_setup, test_teardown), - /* Tests wdb_global_del_agent_labels */ - cmocka_unit_test_setup_teardown(test_wdb_global_del_agent_labels_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_del_agent_labels_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_del_agent_labels_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_del_agent_labels_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_del_agent_labels_success, test_setup, test_teardown), - /* Tests wdb_global_set_agent_label */ - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_label_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_label_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_label_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_label_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_label_bind3_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_label_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_label_success, test_setup, test_teardown), - /* Tests wdb_global_set_sync_status */ - cmocka_unit_test_setup_teardown(test_wdb_global_set_sync_status_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_sync_status_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_sync_status_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_sync_status_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_sync_status_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_sync_status_success, test_setup, test_teardown), - /* Tests wdb_global_sync_agent_info_get */ - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_no_agents, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_sync_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_full, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_get_size_limit, test_setup, test_teardown), - /* Tests wdb_global_get_groups_integrity */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_groups_integrity_statement_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_groups_integrity_syncreq, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_groups_integrity_hash_mismatch, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_groups_integrity_synced, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_groups_integrity_error, test_setup, test_teardown), - /* Tests wdb_global_get_agent_max_group_priority */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_max_group_priority_statement_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_max_group_priority_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_max_group_priority_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_max_group_priority_success, test_setup, test_teardown), - /* Tests wdb_global_sync_agent_groups_get */ - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_invalid_condition, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_no_condition_get_hash_true, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_no_agents_get_hash_false, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_exec_fail_get_hash_true_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_exec_fail_get_hash_true_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_set_synced_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_groups_get_due_buffer_full, test_setup, test_teardown), - /* Tests wdb_global_add_global_group_hash_to_response */ - cmocka_unit_test_setup_teardown(test_wdb_global_add_global_group_hash_to_resposne_response_null, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_add_global_group_hash_to_resposne_response_due, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_add_global_group_hash_to_resposne_get_hash_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_add_global_group_hash_to_resposne_get_hash_return_null, test_setup, test_teardown), - /* Tests wdb_global_sync_agent_info_set */ - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_set_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_set_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_set_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_set_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_set_bind3_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_set_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_sync_agent_info_set_success, test_setup, test_teardown), - /* Tests wdb_global_insert_agent */ - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_bind3_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_bind4_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_bind5_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_bind6_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_bind7_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_success, test_setup, test_teardown), - /* Tests wdb_global_update_agent_name */ - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_name_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_name_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_name_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_name_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_name_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_name_success, test_setup, test_teardown), - /* Tests wdb_global_update_agent_version */ - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind3_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind4_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind5_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind6_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind7_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind8_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind9_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind10_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind11_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind12_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind13_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind14_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind15_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind16_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind17_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind18_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_bind19_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_version_success, test_setup, test_teardown), - /* Tests wdb_global_update_agent_keepalive */ - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_keepalive_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_keepalive_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_keepalive_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_keepalive_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_keepalive_bind3_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_keepalive_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_keepalive_success, test_setup, test_teardown), - /* Tests wdb_global_update_agent_connection_status */ - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_cache_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_bind1_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_bind2_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_bind3_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_bind4_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_bind5_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_step_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_connection_status_success, - test_setup, - test_teardown), - /* Tests wdb_global_update_agent_status_code */ - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_cache_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_bind1_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_bind2_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_bind3_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_bind4_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_step_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_status_code_success, - test_setup, - test_teardown), - /* Tests wdb_global_delete_agent */ - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_success, test_setup, test_teardown), - /* Tests wdb_global_select_agent_name */ - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_name_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_name_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_name_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_name_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_name_success, test_setup, test_teardown), - /* Tests wdb_global_select_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_group_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_group_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_group_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_group_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_agent_group_success, test_setup, test_teardown), - /* Tests wdb_global_select_groups */ - cmocka_unit_test_setup_teardown(test_wdb_global_select_groups_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_groups_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_groups_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_groups_socket_full, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_groups_success, test_setup, test_teardown), - /* Tests wdb_global_find_agent */ - cmocka_unit_test_setup_teardown(test_wdb_global_find_agent_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_agent_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_agent_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_agent_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_agent_bind3_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_agent_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_agent_success, test_setup, test_teardown), - /* Tests wdb_global_find_group */ - cmocka_unit_test_setup_teardown(test_wdb_global_find_group_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_group_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_group_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_group_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_find_group_success, test_setup, test_teardown), - /* Tests wdb_global_insert_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_group_invalid_group_name, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_group_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_group_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_group_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_group_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_group_success, test_setup, test_teardown), - /* Tests wdb_global_select_group_belong */ - cmocka_unit_test_setup_teardown(test_wdb_global_select_group_belong_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_group_belong_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_group_belong_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_group_belong_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_group_belong_socket_size_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_select_group_belong_success, test_setup, test_teardown), - /* Tests wdb_global_get_group_agents */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_group_agents_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_group_agents_bind_text_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_group_agents_bind_int_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_group_agents_stmt_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_group_agents_stmt_due, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_group_agents_stmt_error, test_setup, test_teardown), - /* Tests wdb_global_insert_agent_belong */ - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_belong_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_belong_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_belong_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_belong_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_belong_bind3_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_belong_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_insert_agent_belong_success, test_setup, test_teardown), - /* Tests wdb_is_group_empty */ - cmocka_unit_test_setup_teardown(test_wdb_is_group_empty_stmt_init_group_not_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_is_group_empty_stmt_init_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_is_group_empty_stmt_init_group_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_is_group_empty_stmt_invalid_result, test_setup, test_teardown), - /* Tests wdb_global_delete_group */ - cmocka_unit_test_setup_teardown(test_wdb_global_delete_group_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_group_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_group_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_group_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_group_recalculate_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_group_success, test_setup, test_teardown), - /* Tests wdb_global_delete_agent_belong */ - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_belong_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_belong_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_belong_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_belong_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_agent_belong_success, test_setup, test_teardown), - /* Tests wdb_global_delete_tuple_belong */ - cmocka_unit_test_setup_teardown(test_wdb_global_delete_tuple_belong_init_stmt_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_tuple_belong_exec_stmt_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_delete_tuple_belong_success, test_setup, test_teardown), - /* Tests wdb_global_get_agent_info */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_info_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_info_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_info_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_info_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agent_info_success, test_setup, test_teardown), - /* Tests wdb_global_get_agents_to_disconnect */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_due, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_update_status_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_to_disconnect_invalid_elements, - test_setup, - test_teardown), - /* Tests wdb_global_get_all_agents */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_all_agents_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_all_agents_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_all_agents_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_all_agents_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_all_agents_due, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_all_agents_err, test_setup, test_teardown), - /* Tests wdb_global_reset_agents_connection */ - cmocka_unit_test_setup_teardown(test_wdb_global_reset_agents_connection_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_reset_agents_connection_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_reset_agents_connection_bind1_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_reset_agents_connection_bind2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_reset_agents_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_reset_agents_connection_success, test_setup, test_teardown), - /* Tests wdb_global_get_agents_by_connection_status */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_transaction_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_cache_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_and_node_cache_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_bind1_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_bind2_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_and_node_bind3_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_and_node_bind4_fail, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_and_node_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_due, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_and_node_due, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_agents_by_connection_status_and_node_err, test_setup, test_teardown), - /* Tests wdb_global_create_backup */ - cmocka_unit_test_setup_teardown(test_wdb_global_create_backup_commit_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_create_backup_prepare_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_create_backup_bind_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_create_backup_exec_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_create_backup_compress_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_create_backup_success, test_setup, test_teardown), - /* Tests wdb_global_remove_old_backups */ - cmocka_unit_test_setup_teardown(test_wdb_global_remove_old_backups_opendir_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_remove_old_backups_success_without_removing, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_remove_old_backups_success, test_setup, test_teardown), - /* Tests wdb_global_get_backups */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_backups_opendir_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_backups_success, test_setup, test_teardown), - /* Tests wdb_global_restore_backup */ - cmocka_unit_test_setup_teardown(test_wdb_global_restore_backup_pre_restore_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_restore_backup_no_snapshot, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_restore_backup_compression_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_restore_backup_success, test_setup, test_teardown), - /* Tests wdb_global_get_most_recent_backup */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_most_recent_backup_opendir_failed, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_most_recent_backup_success, test_setup, test_teardown), - /* Tests wdb_global_get_oldest_backup */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_oldest_backup_opendir_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_oldest_backup_success, test_setup, test_teardown), - /* Tests wdb_global_update_agent_groups_hash */ - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_begin_failed, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_cache_failed, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_bind_text_failed, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_bind_int_failed, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_step_failed, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_groups_string_null_success, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_update_agent_groups_hash_empty_group_column_success, - test_setup, - test_teardown), - /* Tests wdb_global_adjust_v4 */ - cmocka_unit_test_setup_teardown(test_wdb_global_adjust_v4_begin_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_adjust_v4_cache_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_adjust_v4_bind_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_adjust_v4_step_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_adjust_v4_commit_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_adjust_v4_success, test_setup, test_teardown), - /* Tests wdb_global_calculate_agent_group_csv */ - cmocka_unit_test_setup_teardown(test_wdb_global_calculate_agent_group_csv_unable_to_get_group, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_calculate_agent_group_csv_success, test_setup, test_teardown), - /* Tests wdb_global_assign_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_global_assign_agent_group_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_assign_agent_group_insert_belong_error, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_assign_agent_group_find_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_assign_agent_group_invalid_json, test_setup, test_teardown), - /* Tests wdb_global_unassign_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_global_unassign_agent_group_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_unassign_agent_group_success_assign_default_group, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_unassign_agent_group_delete_tuple_error, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_unassign_agent_group_find_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_unassign_agent_group_find_invalid_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_unassign_agent_group_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_unassign_agent_group_error_assign_default_group, test_setup, test_teardown), - /* Tests wdb_global_set_agent_group_context */ - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_group_context_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_group_context_init_stmt_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_group_context_exec_stmt_error, test_setup, test_teardown), - /* Tests wdb_global_set_agent_group_hash */ - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_group_hash_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_group_hash_init_stmt_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_group_hash_exec_stmt_error, test_setup, test_teardown), - /* Tests wdb_global_groups_number_get */ - cmocka_unit_test_setup_teardown(test_wdb_global_groups_number_get_stmt_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_groups_number_get_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_groups_number_get_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_groups_number_get_success, test_setup, test_teardown), - /* Tests wdb_global_validate_group_name */ - cmocka_unit_test_setup_teardown(test_wdb_global_validate_group_name_fail_group_name_contains_invalid_character_1, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_validate_group_name_fail_group_name_contains_invalid_character_2, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_validate_group_name_fail_group_name_exceeds_max_length, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_validate_group_name_fail_group_name_current_directory_reserved_name, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_validate_group_name_fail_group_name_parent_directory_reserved_name, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_validate_group_name_success, test_setup, test_teardown), - /* Tests wdb_global_validate_groups */ - cmocka_unit_test_setup_teardown(test_wdb_global_validate_groups_fail_groups_exceeds_max_number, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_validate_groups_success, test_setup, test_teardown), - /* Tests wdb_global_set_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_override_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_override_delete_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_add_modes_assign_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_append_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_empty_only_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_empty_only_not_empty_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_remove_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_remove_unassign_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_calculate_csv_empty, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_set_group_ctx_error, test_setup, test_teardown), - /* Tests wdb_global_set_agent_groups_sync_status*/ - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_sync_status_invalid_stmt, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_sync_status_bad_bind_sync, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_sync_status_bad_bind_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_set_agent_groups_sync_status_success, test_setup, test_teardown), - /* Tests wdb_global_get_distinct_agent_groups */ - cmocka_unit_test_setup_teardown(test_wdb_global_get_distinct_agent_groups_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_distinct_agent_groups_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_distinct_agent_groups_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_distinct_agent_groups_exec_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_distinct_agent_groups_succes_due, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_get_distinct_agent_groups_succes_ok, test_setup, test_teardown), - /* Tests wdb_global_recalculate_all_agent_groups_hash */ - cmocka_unit_test_setup_teardown(test_wdb_global_recalculate_all_agent_groups_hash_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_recalculate_all_agent_groups_hash_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_recalculate_all_agent_groups_hash_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_recalculate_all_agent_groups_hash_exec_stmt_null, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_recalculate_all_agent_groups_hash_invalid_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_global_recalculate_all_agent_groups_hash_recalculate_error, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_global_helpers.c b/src/unit_tests/wazuh_db/test_wdb_global_helpers.c deleted file mode 100644 index 4c50658c900..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_global_helpers.c +++ /dev/null @@ -1,4258 +0,0 @@ -/* - * Wazuh SQLite integration - * Copyright (C) 2015, Wazuh Inc. - * July 5, 2016. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/helpers/wdb_global_helpers.h" -#include "wazuhdb_op.h" - -#include "../wrappers/posix/dirent_wrappers.h" -#include "../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/shared/rbtree_op_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/libc/string_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/posix/stat_wrappers.h" - -extern int test_mode; -int set_payload = 0; - -char test_payload[OS_MAXSTR] = { 0 }; - -/* redefinitons/wrapping */ - -time_t __wrap_time(time_t *__timer) { - *__timer = 1; - return 1; -} - -int __wrap_wdb_create_profile(const char *path) { - check_expected(path); - - return mock_type(int); -} - -uid_t __wrap_Privsep_GetUser(const char *name) { - check_expected(name); - - return mock_type(uid_t); -} - -gid_t __wrap_Privsep_GetGroup(const char *name) { - check_expected(name); - - return mock_type(gid_t); -} - -/* test struc definition*/ -typedef struct test_struct { - char** groups_array; - char* data_in_str; - char groups_csv[256]; - char mode[256]; - char sync_status[256]; - char query_str[256]; - char response[256]; - int id; - int socket; -} test_struct_t; - -/* setup/teardown */ - -int setup_wdb_global_helpers(void **state) { - test_mode = 1; - - return 0; -} - -int setup_wdb_global_helpers_add_agent(void **state) { - test_mode = 1; - - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - - init_data->groups_array = NULL; - init_data->data_in_str = NULL; - strcpy(init_data->groups_csv,"default,Group1,Group2"); - strcpy(init_data->mode,"override"); - strcpy(init_data->sync_status,"synced"); - strcpy(init_data->response,"ok"); - init_data->id = 1; - init_data->socket = -1; - - strcpy(init_data->query_str,"global set-agent-groups {\"mode\":\"mode_value\",\"sync_status\":\ - \"sync_status_value\",\"data\":[{\"id\":0,\"groups\":[\"default\",\"Group1\",\"Group2\"]}]}"); - os_strdup("{\"mode\":\"mode_value\",\"sync_status\":\ - \"sync_status_value\",\"data\":[{\"id\":0,\"groups\":[\"default\",\"Group1\",\"Group2\"]}]}", init_data->data_in_str); - - // spliting string - init_data->groups_array = w_string_split(init_data->groups_csv, ",", 0); - - *state = init_data; - return 0; -} - -int teardown_wdb_global_helpers_add_agent(void **state) { - test_mode = 0; - - test_struct_t *data = (test_struct_t *)*state; - free_strarray(data->groups_array); - os_free(data); - - return 0; -} - -int teardown_wdb_global_helpers(void **state) { - test_mode = 0; - errno = 0; - return 0; -} - -/* Tests wdb_insert_agent */ - -void test_wdb_insert_agent_error_json(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - const char *ip = "192.168.0.101"; - const char *register_ip = "any"; - const char *internal_key = "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"; - const char *group = "default"; - int keep_date = 0; - - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating data JSON for Wazuh DB."); - - ret = wdb_insert_agent(id, name, ip, register_ip, internal_key, group, keep_date, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_insert_agent_error_socket(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - const char *ip = "192.168.0.101"; - const char *register_ip = "any"; - const char *internal_key = "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"; - const char *group = "default"; - int keep_date = 0; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"); - const char *query_str = "global insert-agent {\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - expect_string(__wrap_cJSON_AddStringToObject, name, "ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "192.168.0.101"); - expect_string(__wrap_cJSON_AddStringToObject, name, "register_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "any"); - expect_string(__wrap_cJSON_AddStringToObject, name, "internal_key"); - expect_string(__wrap_cJSON_AddStringToObject, string, "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group"); - expect_string(__wrap_cJSON_AddStringToObject, string, "default"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "date_add"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global insert-agent {\"id\":1,\ -\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"); - - ret = wdb_insert_agent(id, name, ip, register_ip, internal_key, group, keep_date, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_insert_agent_error_sql_execution(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - const char *ip = "192.168.0.101"; - const char *register_ip = "any"; - const char *internal_key = "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"; - const char *group = "default"; - int keep_date = 0; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"); - const char *query_str = "global insert-agent {\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - expect_string(__wrap_cJSON_AddStringToObject, name, "ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "192.168.0.101"); - expect_string(__wrap_cJSON_AddStringToObject, name, "register_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "any"); - expect_string(__wrap_cJSON_AddStringToObject, name, "internal_key"); - expect_string(__wrap_cJSON_AddStringToObject, string, "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group"); - expect_string(__wrap_cJSON_AddStringToObject, string, "default"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "date_add"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global insert-agent {\"id\":1,\ -\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"); - - ret = wdb_insert_agent(id, name, ip, register_ip, internal_key, group, keep_date, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_insert_agent_error_result(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - const char *ip = "192.168.0.101"; - const char *register_ip = "any"; - const char *internal_key = "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"; - const char *group = "default"; - int keep_date = 0; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"); - const char *query_str = "global insert-agent {\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - expect_string(__wrap_cJSON_AddStringToObject, name, "ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "192.168.0.101"); - expect_string(__wrap_cJSON_AddStringToObject, name, "register_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "any"); - expect_string(__wrap_cJSON_AddStringToObject, name, "internal_key"); - expect_string(__wrap_cJSON_AddStringToObject, string, "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group"); - expect_string(__wrap_cJSON_AddStringToObject, string, "default"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "date_add"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_insert_agent(id, name, ip, register_ip, internal_key, group, keep_date, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_insert_agent_success(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - const char *ip = "192.168.0.101"; - const char *register_ip = "any"; - const char *internal_key = "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"; - const char *group = "default"; - int keep_date = 0; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"); - const char *query_str = "global insert-agent {\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1}"; - const char *response = "ok"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - expect_string(__wrap_cJSON_AddStringToObject, name, "ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "192.168.0.101"); - expect_string(__wrap_cJSON_AddStringToObject, name, "register_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "any"); - expect_string(__wrap_cJSON_AddStringToObject, name, "internal_key"); - expect_string(__wrap_cJSON_AddStringToObject, string, "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group"); - expect_string(__wrap_cJSON_AddStringToObject, string, "default"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "date_add"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_insert_agent(id, name, ip, register_ip, internal_key, group, keep_date, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -void test_wdb_insert_agent_success_keep_date(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - const char *ip = "192.168.0.101"; - const char *register_ip = "any"; - const char *internal_key = "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"; - const char *group = "default"; - int keep_date = 1; - struct tm test_time; - time_t date_returned = 0; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1577851261}"); - const char *query_str = "global insert-agent {\"id\":1,\"name\":\"agent1\",\"ip\":\"192.168.0.101\",\"register_ip\":\"any\",\ -\"internal_key\":\"e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301\",\"group\":\"default\",\"date_add\":1577851261}"; - const char *response = "ok"; - - // Opening destination database file - expect_string(__wrap_wfopen, path, "queue/agents-timestamp"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 1); - - // Getting data - expect_value(__wrap_fgets, __stream, 1); - will_return(__wrap_fgets, "001 agent1 any 2020-01-01 01:01:01"); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, OS_SUCCESS); - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - // Transforming the date 2020-01-01 01:01:01 to a number - test_time.tm_year = 2020-1900; - test_time.tm_mon = 1-1; - test_time.tm_mday = 1; - test_time.tm_hour = 1; - test_time.tm_min = 1; - test_time.tm_sec = 1; - test_time.tm_isdst = -1; - - date_returned = mktime(&test_time); - - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - expect_string(__wrap_cJSON_AddStringToObject, name, "ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "192.168.0.101"); - expect_string(__wrap_cJSON_AddStringToObject, name, "register_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "any"); - expect_string(__wrap_cJSON_AddStringToObject, name, "internal_key"); - expect_string(__wrap_cJSON_AddStringToObject, string, "e6ecef1698e21e8fb160e81c722a0523d72554dc1fc3e4374e247f4baac52301"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group"); - expect_string(__wrap_cJSON_AddStringToObject, string, "default"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "date_add"); - expect_value(__wrap_cJSON_AddNumberToObject, number, date_returned); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_insert_agent(id, name, ip, register_ip, internal_key, group, keep_date, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_update_agent_name */ - -void test_wdb_update_agent_name_error_json(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating data JSON for Wazuh DB."); - - ret = wdb_update_agent_name(id, name, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_name_error_socket(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\"}"); - const char *query_str = "global update-agent-name {\"id\":1,\"name\":\"agent1\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-agent-name {\"id\":1,\"name\":\"agent1\"}"); - - ret = wdb_update_agent_name(id, name, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_name_error_sql_execution(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\"}"); - const char *query_str = "global update-agent-name {\"id\":1,\"name\":\"agent1\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-agent-name {\"id\":1,\"name\":\"agent1\"}"); - - ret = wdb_update_agent_name(id, name, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_name_error_result(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\"}"); - const char *query_str = "global update-agent-name {\"id\":1,\"name\":\"agent1\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_update_agent_name(id, name, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_name_success(void **state) -{ - int ret = 0; - int id = 1; - const char *name = "agent1"; - - const char *json_str = strdup("{\"id\":1,\"name\":\"agent1\"}"); - const char *query_str = "global update-agent-name {\"id\":1,\"name\":\"agent1\"}"; - const char *response = "ok"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agent1"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_update_agent_name(id, name, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_update_agent_data */ - -void test_wdb_update_agent_data_invalid_data(void **state) -{ - int ret = 0; - agent_info_data *agent_data = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid data provided to set in global.db."); - - ret = wdb_update_agent_data(agent_data, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_data_error_json(void **state) -{ - int ret = 0; - agent_info_data *agent_data = NULL; - - os_calloc(1, sizeof(agent_info_data), agent_data); - os_calloc(1, sizeof(os_data), agent_data->osd); - - agent_data->id = 1; - os_strdup("osname", agent_data->osd->os_name); - os_strdup("osversion", agent_data->osd->os_version); - os_strdup("osmajor", agent_data->osd->os_major); - os_strdup("osminor", agent_data->osd->os_minor); - os_strdup("oscodename", agent_data->osd->os_codename); - os_strdup("osplatform", agent_data->osd->os_platform); - os_strdup("osbuild", agent_data->osd->os_build); - os_strdup("osuname", agent_data->osd->os_uname); - os_strdup("osarch", agent_data->osd->os_arch); - os_strdup("version", agent_data->version); - os_strdup("csum", agent_data->config_sum); - os_strdup("msum", agent_data->merged_sum); - os_strdup("managerhost", agent_data->manager_host); - os_strdup("nodename", agent_data->node_name); - os_strdup("agentip", agent_data->agent_ip); - os_strdup("\"label1\":value1\n\"label2\":value2", agent_data->labels); - os_strdup("active", agent_data->connection_status); - os_strdup("syncreq", agent_data->sync_status); - - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating data JSON for Wazuh DB."); - - ret = wdb_update_agent_data(agent_data, NULL); - - assert_int_equal(OS_INVALID, ret); - - wdb_free_agent_info_data(agent_data); -} - -void test_wdb_update_agent_data_error_socket(void **state) -{ - int ret = 0; - agent_info_data *agent_data = NULL; - - os_calloc(1, sizeof(agent_info_data), agent_data); - os_calloc(1, sizeof(os_data), agent_data->osd); - - agent_data->id = 1; - os_strdup("osname", agent_data->osd->os_name); - os_strdup("osversion", agent_data->osd->os_version); - os_strdup("osmajor", agent_data->osd->os_major); - os_strdup("osminor", agent_data->osd->os_minor); - os_strdup("oscodename", agent_data->osd->os_codename); - os_strdup("osplatform", agent_data->osd->os_platform); - os_strdup("osbuild", agent_data->osd->os_build); - os_strdup("osuname", agent_data->osd->os_uname); - os_strdup("osarch", agent_data->osd->os_arch); - os_strdup("version", agent_data->version); - os_strdup("csum", agent_data->config_sum); - os_strdup("msum", agent_data->merged_sum); - os_strdup("managerhost", agent_data->manager_host); - os_strdup("nodename", agent_data->node_name); - os_strdup("agentip", agent_data->agent_ip); - os_strdup("\"label1\":value1\n\"label2\":value2", agent_data->labels); - os_strdup("active", agent_data->connection_status); - os_strdup("syncreq", agent_data->sync_status); - os_strdup("synced", agent_data->group_config_status); - - const char *json_str = strdup("{\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"); - const char *query_str = "global update-agent-data {\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"; - - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "version"); - expect_string(__wrap_cJSON_AddStringToObject, name, "config_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "csum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "merged_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "msum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "manager_host"); - expect_string(__wrap_cJSON_AddStringToObject, string, "managerhost"); - expect_string(__wrap_cJSON_AddStringToObject, name, "node_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "nodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "agent_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agentip"); - expect_string(__wrap_cJSON_AddStringToObject, name, "labels"); - expect_string(__wrap_cJSON_AddStringToObject, string, "\"label1\":value1\n\"label2\":value2"); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "syncreq"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group_config_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osversion"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_major"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osmajor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_minor"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osminor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_codename"); - expect_string(__wrap_cJSON_AddStringToObject, string, "oscodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_platform"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osplatform"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_build"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osbuild"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_uname"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osuname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_arch"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osarch"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-agent-data \ -{\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"); - - ret = wdb_update_agent_data(agent_data, NULL); - - assert_int_equal(OS_INVALID, ret); - - wdb_free_agent_info_data(agent_data); -} - -void test_wdb_update_agent_data_error_sql_execution(void **state) -{ - int ret = 0; - agent_info_data *agent_data = NULL; - - os_calloc(1, sizeof(agent_info_data), agent_data); - os_calloc(1, sizeof(os_data), agent_data->osd); - - agent_data->id = 1; - os_strdup("osname", agent_data->osd->os_name); - os_strdup("osversion", agent_data->osd->os_version); - os_strdup("osmajor", agent_data->osd->os_major); - os_strdup("osminor", agent_data->osd->os_minor); - os_strdup("oscodename", agent_data->osd->os_codename); - os_strdup("osplatform", agent_data->osd->os_platform); - os_strdup("osbuild", agent_data->osd->os_build); - os_strdup("osuname", agent_data->osd->os_uname); - os_strdup("osarch", agent_data->osd->os_arch); - os_strdup("version", agent_data->version); - os_strdup("csum", agent_data->config_sum); - os_strdup("msum", agent_data->merged_sum); - os_strdup("managerhost", agent_data->manager_host); - os_strdup("nodename", agent_data->node_name); - os_strdup("agentip", agent_data->agent_ip); - os_strdup("\"label1\":value1\n\"label2\":value2", agent_data->labels); - os_strdup("active", agent_data->connection_status); - os_strdup("syncreq", agent_data->sync_status); - os_strdup("synced", agent_data->group_config_status); - - const char *json_str = strdup("{\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"); - const char *query_str = "global update-agent-data {\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"; - - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "version"); - expect_string(__wrap_cJSON_AddStringToObject, name, "config_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "csum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "merged_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "msum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "manager_host"); - expect_string(__wrap_cJSON_AddStringToObject, string, "managerhost"); - expect_string(__wrap_cJSON_AddStringToObject, name, "node_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "nodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "agent_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agentip"); - expect_string(__wrap_cJSON_AddStringToObject, name, "labels"); - expect_string(__wrap_cJSON_AddStringToObject, string, "\"label1\":value1\n\"label2\":value2"); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "syncreq"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group_config_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osversion"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_major"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osmajor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_minor"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osminor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_codename"); - expect_string(__wrap_cJSON_AddStringToObject, string, "oscodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_platform"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osplatform"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_build"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osbuild"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_uname"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osuname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_arch"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osarch"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-agent-data \ -{\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"); - - ret = wdb_update_agent_data(agent_data, NULL); - - assert_int_equal(OS_INVALID, ret); - - wdb_free_agent_info_data(agent_data); -} - -void test_wdb_update_agent_data_error_result(void **state) -{ - int ret = 0; - agent_info_data *agent_data = NULL; - - os_calloc(1, sizeof(agent_info_data), agent_data); - os_calloc(1, sizeof(os_data), agent_data->osd); - - agent_data->id = 1; - os_strdup("osname", agent_data->osd->os_name); - os_strdup("osversion", agent_data->osd->os_version); - os_strdup("osmajor", agent_data->osd->os_major); - os_strdup("osminor", agent_data->osd->os_minor); - os_strdup("oscodename", agent_data->osd->os_codename); - os_strdup("osplatform", agent_data->osd->os_platform); - os_strdup("osbuild", agent_data->osd->os_build); - os_strdup("osuname", agent_data->osd->os_uname); - os_strdup("osarch", agent_data->osd->os_arch); - os_strdup("version", agent_data->version); - os_strdup("csum", agent_data->config_sum); - os_strdup("msum", agent_data->merged_sum); - os_strdup("managerhost", agent_data->manager_host); - os_strdup("nodename", agent_data->node_name); - os_strdup("agentip", agent_data->agent_ip); - os_strdup("\"label1\":value1\n\"label2\":value2", agent_data->labels); - os_strdup("active", agent_data->connection_status); - os_strdup("syncreq", agent_data->sync_status); - os_strdup("synced", agent_data->group_config_status); - - const char *json_str = strdup("{\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"); - const char *query_str = "global update-agent-data {\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"; - - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "version"); - expect_string(__wrap_cJSON_AddStringToObject, name, "config_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "csum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "merged_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "msum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "manager_host"); - expect_string(__wrap_cJSON_AddStringToObject, string, "managerhost"); - expect_string(__wrap_cJSON_AddStringToObject, name, "node_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "nodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "agent_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agentip"); - expect_string(__wrap_cJSON_AddStringToObject, name, "labels"); - expect_string(__wrap_cJSON_AddStringToObject, string, "\"label1\":value1\n\"label2\":value2"); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "syncreq"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group_config_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osversion"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_major"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osmajor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_minor"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osminor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_codename"); - expect_string(__wrap_cJSON_AddStringToObject, string, "oscodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_platform"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osplatform"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_build"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osbuild"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_uname"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osuname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_arch"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osarch"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_update_agent_data(agent_data, NULL); - - assert_int_equal(OS_INVALID, ret); - - wdb_free_agent_info_data(agent_data); -} - -void test_wdb_update_agent_data_success(void **state) -{ - int ret = 0; - agent_info_data *agent_data = NULL; - - os_calloc(1, sizeof(agent_info_data), agent_data); - os_calloc(1, sizeof(os_data), agent_data->osd); - - agent_data->id = 1; - os_strdup("osname", agent_data->osd->os_name); - os_strdup("osversion", agent_data->osd->os_version); - os_strdup("osmajor", agent_data->osd->os_major); - os_strdup("osminor", agent_data->osd->os_minor); - os_strdup("oscodename", agent_data->osd->os_codename); - os_strdup("osplatform", agent_data->osd->os_platform); - os_strdup("osbuild", agent_data->osd->os_build); - os_strdup("osuname", agent_data->osd->os_uname); - os_strdup("osarch", agent_data->osd->os_arch); - os_strdup("version", agent_data->version); - os_strdup("csum", agent_data->config_sum); - os_strdup("msum", agent_data->merged_sum); - os_strdup("managerhost", agent_data->manager_host); - os_strdup("nodename", agent_data->node_name); - os_strdup("agentip", agent_data->agent_ip); - os_strdup("\"label1\":value1\n\"label2\":value2", agent_data->labels); - os_strdup("active", agent_data->connection_status); - os_strdup("syncreq", agent_data->sync_status); - os_strdup("synced", agent_data->group_config_status); - - const char *json_str = strdup("{\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"); - const char *query_str = "global update-agent-data {\"id\": 1,\"os_name\":\"osname\",\"os_version\":\"osversion\",\ -\"os_major\":\"osmajor\",\"os_minor\":\"osminor\",\"os_codename\":\"oscodename\",\ -\"os_platform\":\"osplatform\",\"os_build\":\"osbuild\",\"os_uname\":\"osuname\",\ -\"os_arch\":\"osarch\",\"version\":\"version\",\"config_sum\":\"csum\",\"merged_sum\":\"msum\",\ -\"manager_host\":\"managerhost\",\"node_name\":\"nodename\",\"agent_ip\":\"agentip\",\"labels\":\ -\"\"label1\":value1\n\"label2\":value2\",\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\ -\"group_config_status\":\"synced\"}"; - const char *response = "ok"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "version"); - expect_string(__wrap_cJSON_AddStringToObject, name, "config_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "csum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "merged_sum"); - expect_string(__wrap_cJSON_AddStringToObject, string, "msum"); - expect_string(__wrap_cJSON_AddStringToObject, name, "manager_host"); - expect_string(__wrap_cJSON_AddStringToObject, string, "managerhost"); - expect_string(__wrap_cJSON_AddStringToObject, name, "node_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "nodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "agent_ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, "agentip"); - expect_string(__wrap_cJSON_AddStringToObject, name, "labels"); - expect_string(__wrap_cJSON_AddStringToObject, string, "\"label1\":value1\n\"label2\":value2"); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "syncreq"); - expect_string(__wrap_cJSON_AddStringToObject, name, "group_config_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_name"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osversion"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_major"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osmajor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_minor"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osminor"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_codename"); - expect_string(__wrap_cJSON_AddStringToObject, string, "oscodename"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_platform"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osplatform"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_build"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osbuild"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_uname"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osuname"); - expect_string(__wrap_cJSON_AddStringToObject, name, "os_arch"); - expect_string(__wrap_cJSON_AddStringToObject, string, "osarch"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_update_agent_data(agent_data, NULL); - - assert_int_equal(OS_SUCCESS, ret); - - wdb_free_agent_info_data(agent_data); -} - -/* Tests wdb_get_agent_info */ - -void test_wdb_get_agent_info_error_no_json_response(void **state) { - cJSON *root = NULL; - int id = 1; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get the agent's 1 information."); - - root = wdb_get_agent_info(id, NULL); - - assert_null(root); -} - -void test_wdb_get_agent_info_success(void **state) { - cJSON *root = NULL; - int id = 1; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, (cJSON *)1); - - root = wdb_get_agent_info(id, NULL); - - assert_ptr_equal(1, root); -} - -/* Tests wdb_get_agent_labels */ - -void test_wdb_get_agent_labels_error_no_json_response(void **state) { - cJSON *root = NULL; - int id = 1; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get the agent's 1 labels."); - - root = wdb_get_agent_labels(id, NULL); - - assert_null(root); -} - -void test_wdb_get_agent_labels_success(void **state) { - cJSON *root = NULL; - int id = 1; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, (cJSON *)1); - - root = wdb_get_agent_labels(id, NULL); - - assert_ptr_equal(1, root); -} - -/* Tests wdb_update_agent_keepalive */ - -void test_wdb_update_agent_keepalive_error_json(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating data JSON for Wazuh DB."); - - ret = wdb_update_agent_keepalive(id, connection_status, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_keepalive_error_socket(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"); - - ret = wdb_update_agent_keepalive(id, connection_status, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_keepalive_error_sql_execution(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"); - - ret = wdb_update_agent_keepalive(id, connection_status, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_keepalive_error_result(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_update_agent_keepalive(id, connection_status, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_keepalive_success(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\"}"; - const char *response = "ok"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_update_agent_keepalive(id, connection_status, sync_status, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_update_agent_connection_status */ - -void test_wdb_update_agent_connection_status_error_json(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating data JSON for Wazuh DB."); - - ret = wdb_update_agent_connection_status(id, connection_status, sync_status, NULL, 0); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_connection_status_error_socket(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"); - const char *query_str = "global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"); - - ret = wdb_update_agent_connection_status(id, connection_status, sync_status, NULL, 0); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_connection_status_error_sql_execution(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"); - const char *query_str = "global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"); - - ret = wdb_update_agent_connection_status(id, connection_status, sync_status, NULL, 0); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_connection_status_error_result(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"); - const char *query_str = "global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_update_agent_connection_status(id, connection_status, sync_status, NULL, 0); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_connection_status_success(void **state) -{ - int ret = 0; - int id = 1; - const char *connection_status = "active"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"); - const char *query_str = "global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"synced\",\"status_code\":0}"; - const char *response = "ok"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "connection_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "active"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 0); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_update_agent_connection_status(id, connection_status, sync_status, NULL, 0); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_update_agent_status_code */ - -void test_wdb_update_agent_status_code_error_json(void **state) -{ - int ret = 0; - int id = 1; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating data JSON for Wazuh DB."); - - ret = wdb_update_agent_status_code(id, 0, version, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_status_code_error_socket(void **state) -{ - int ret = 0; - int id = 1; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-status-code {\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, INVALID_VERSION); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "Wazuh v4.5.0"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-status-code {\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"); - - ret = wdb_update_agent_status_code(id, INVALID_VERSION, version, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_status_code_error_sql_execution(void **state) -{ - int ret = 0; - int id = 1; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-status-code {\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, INVALID_VERSION); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "Wazuh v4.5.0"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global update-status-code {\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"); - - ret = wdb_update_agent_status_code(id, INVALID_VERSION, version, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_status_code_error_result(void **state) -{ - int ret = 0; - int id = 1; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-status-code {\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, INVALID_VERSION); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "Wazuh v4.5.0"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_update_agent_status_code(id, INVALID_VERSION, version, sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_agent_status_code_success(void **state) -{ - int ret = 0; - int id = 1; - const char *version = "v4.5.0"; - const char *sync_status = "synced"; - - const char *json_str = strdup("{\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"); - const char *query_str = "global update-status-code {\"id\":1,\"status_code\":-1,\"version\":\"Wazuh v4.5.0\",\"sync_status\":\"synced\"}"; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, 1); - expect_string(__wrap_cJSON_AddNumberToObject, name, "status_code"); - expect_value(__wrap_cJSON_AddNumberToObject, number, INVALID_VERSION); - expect_string(__wrap_cJSON_AddStringToObject, name, "version"); - expect_string(__wrap_cJSON_AddStringToObject, string, "Wazuh v4.5.0"); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, "synced"); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_update_agent_status_code(id, INVALID_VERSION, version, sync_status, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_get_agent_name */ - -void test_wdb_get_agent_name_error_no_json_response(void **state) { - int id = 1; - char *name = NULL; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get the agent's 1 name."); - - name = wdb_get_agent_name(id, NULL); - - assert_null(name); -} - -void test_wdb_get_agent_name_success(void **state) { - cJSON *root = NULL; - cJSON *row = NULL; - cJSON *str = NULL; - int id = 1; - char *name = NULL; - - root = __real_cJSON_CreateArray(); - row = __real_cJSON_CreateObject(); - str = __real_cJSON_CreateString("agent1"); - __real_cJSON_AddItemToObject(row, "name", str); - __real_cJSON_AddItemToArray(root, row); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, str); - - expect_function_call(__wrap_cJSON_Delete); - - name = wdb_get_agent_name(id, NULL); - - assert_string_equal("agent1", name); - - __real_cJSON_Delete(root); - os_free(name); -} - -void test_wdb_get_agent_name_not_found(void **state) { - cJSON *root = NULL; - cJSON *row = NULL; - cJSON *str = NULL; - int id = 1; - char *name = NULL; - - root = __real_cJSON_CreateArray(); - __real_cJSON_AddItemToArray(root, row); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, str); - - expect_function_call(__wrap_cJSON_Delete); - - name = wdb_get_agent_name(id, NULL); - - assert_string_equal("", name); - - __real_cJSON_Delete(root); - os_free(name); -} - -/* Tests wdb_remove_agent */ - -void test_wdb_remove_agent_remove_db_error(void **state) -{ - int ret = 0; - int id = 1; - - char *query_str = "global delete-agent 1"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - // Error on removing DB files - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_remove_agent(id, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_remove_agent_error_socket(void **state) -{ - int ret = 0; - int id = 1; - - char *query_str = "global delete-agent 1"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global delete-agent 1"); - - ret = wdb_remove_agent(id, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_remove_agent_error_sql_execution(void **state) -{ - int ret = 0; - int id = 1; - - char *query_str = "global delete-agent 1"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global delete-agent 1"); - - ret = wdb_remove_agent(id, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_remove_agent_error_result(void **state) -{ - int ret = 0; - int id = 1; - - char *query_str = "global delete-agent 1"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_remove_agent(id, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_remove_agent_success(void **state) -{ - int ret = 0; - int id = 1; - - char *query_str = "global delete-agent 1"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_remove_agent(id, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_get_agent_group */ - -void test_wdb_get_agent_group_error_no_json_response(void **state) { - int id = 1; - char *name = NULL; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get the agent's 1 group."); - - name = wdb_get_agent_group(id, NULL); - - assert_null(name); -} - -void test_wdb_get_agent_group_success(void **state) { - cJSON *root = NULL; - cJSON *row = NULL; - cJSON *str = NULL; - int id = 1; - char *name = NULL; - - root = __real_cJSON_CreateArray(); - row = __real_cJSON_CreateObject(); - str = __real_cJSON_CreateString("default"); - __real_cJSON_AddItemToObject(row, "group", str); - __real_cJSON_AddItemToArray(root, row); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, str); - - expect_function_call(__wrap_cJSON_Delete); - - name = wdb_get_agent_group(id, NULL); - - assert_string_equal("default", name); - - __real_cJSON_Delete(root); - os_free(name); -} - -/* Tests wdb_find_agent */ - -void test_wdb_find_agent_error_invalid_parameters(void **state) -{ - int ret = 0; - char *name = NULL; - char *ip = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "Empty agent name or ip when trying to get agent ID."); - - ret = wdb_find_agent(name, ip, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_find_agent_error_json_input(void **state) -{ - int ret = 0; - char *name = "agent1"; - char *ip = "any"; - - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error creating data JSON for Wazuh DB."); - - ret = wdb_find_agent(name, ip, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_find_agent_error_json_output(void **state) -{ - int ret = 0; - const char *name_str = "agent1"; - const char *ip_str = "any"; - - const char *json_str = strdup("{\"name\":\"agent1\",\"ip\":\"any\"}"); - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, name_str); - expect_string(__wrap_cJSON_AddStringToObject, name, "ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, ip_str); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - // Handling result - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB for agent ID."); - - ret = wdb_find_agent(name_str, ip_str, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_find_agent_success(void **state) -{ - int ret = 0; - const char *name_str = "agent1"; - const char *ip_str = "any"; - cJSON *root = NULL; - cJSON *row = NULL; - - const char *json_str = strdup("{\"name\":\"agent1\",\"ip\":\"any\"}"); - - root = __real_cJSON_CreateArray(); - row = __real_cJSON_CreateObject(); - __real_cJSON_AddNumberToObject(row, "id", 1); - __real_cJSON_AddItemToArray(root, row); - - will_return(__wrap_cJSON_CreateObject, 1); - will_return_always(__wrap_cJSON_AddStringToObject, 1); - - // Adding data to JSON - expect_string(__wrap_cJSON_AddStringToObject, name, "name"); - expect_string(__wrap_cJSON_AddStringToObject, string, name_str); - expect_string(__wrap_cJSON_AddStringToObject, name, "ip"); - expect_string(__wrap_cJSON_AddStringToObject, string, ip_str); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, json_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, __real_cJSON_GetObjectItem(root->child, "id")); - - expect_function_call(__wrap_cJSON_Delete); - - ret = wdb_find_agent(name_str, ip_str, NULL); - - assert_int_equal(1, ret); - - __real_cJSON_Delete(root); -} - -/* Tests wdb_get_all_agents */ - -void test_wdb_get_all_agents_wdbc_query_error(void **state) { - const char *query_str = "global get-all-agents last_id 0"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - int *array = wdb_get_all_agents(false, NULL); - - assert_null(array); -} - -void test_wdb_get_all_agents_wdbc_parse_error(void **state) { - const char *query_str = "global get-all-agents last_id 0"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - int *array = wdb_get_all_agents(false, NULL); - - assert_null(array); -} - -void test_wdb_get_all_agents_success(void **state) { - const char *query_str = "global get-all-agents last_id 0"; - -// Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1},{\"id\":2},{\"id\":3}]"); - cJSON* test_json = __real_cJSON_Parse(test_payload+3); - cJSON* id1 = cJSON_CreateNumber(1); - cJSON* id2 = cJSON_CreateNumber(2); - cJSON* id3 = cJSON_CreateNumber(3); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, test_payload); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json); - will_return(__wrap_cJSON_GetObjectItem, id1); - will_return(__wrap_cJSON_GetObjectItem, id2); - will_return(__wrap_cJSON_GetObjectItem, id3); - expect_function_call(__wrap_cJSON_Delete); - - int *array = wdb_get_all_agents(false, NULL); - - assert_non_null(array); - assert_int_equal(1, array[0]); - assert_int_equal(2, array[1]); - assert_int_equal(3, array[2]); - assert_int_equal(-1, array[3]); - - os_free(array); - __real_cJSON_Delete(test_json); - __real_cJSON_Delete(id1); - __real_cJSON_Delete(id2); - __real_cJSON_Delete(id3); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -/* Tests wdb_get_all_agents_rbtree */ - -void test_wdb_get_all_agents_rbtree_wdbc_query_error(void **state) { - const char *query_str = "global get-all-agents last_id 0"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get agent's IDs."); - - rb_tree *tree = wdb_get_all_agents_rbtree(false, NULL); - - assert_null(tree); -} - -void test_wdb_get_all_agents_rbtree_wdbc_parse_error(void **state) { - const char *query_str = "global get-all-agents last_id 0"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get agent's IDs."); - - rb_tree *tree = wdb_get_all_agents_rbtree(false, NULL); - - assert_null(tree); -} - -void test_wdb_get_all_agents_rbtree_success(void **state) { - const char *query_str = "global get-all-agents last_id 0"; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1},{\"id\":2},{\"id\":3}]"); - cJSON* test_json = __real_cJSON_Parse(test_payload+3); - cJSON* id1 = cJSON_CreateNumber(1); - cJSON* id2 = cJSON_CreateNumber(2); - cJSON* id3 = cJSON_CreateNumber(3); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, test_payload); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json); - will_return(__wrap_cJSON_GetObjectItem, id1); - will_return(__wrap_cJSON_GetObjectItem, id2); - will_return(__wrap_cJSON_GetObjectItem, id3); - expect_function_call(__wrap_cJSON_Delete); - - rb_tree *tree = wdb_get_all_agents_rbtree(false, NULL); - - assert_non_null(tree); - - rbtree_destroy(tree); - __real_cJSON_Delete(test_json); - __real_cJSON_Delete(id1); - __real_cJSON_Delete(id2); - __real_cJSON_Delete(id3); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -/* Tests wdb_find_group */ - -void test_wdb_find_group_error_no_json_response(void **state) { - int id = 0; - char *name = "test_group"; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get the agent group id."); - - id = wdb_find_group(name, NULL); - - assert_int_equal(OS_INVALID, id); -} - -void test_wdb_find_group_success(void **state) { - int id = 0; - char *name = "test_group"; - - cJSON *root = __real_cJSON_CreateArray(); - cJSON *row = __real_cJSON_CreateObject(); - __real_cJSON_AddNumberToObject(row, "id", 1); - __real_cJSON_AddItemToArray(root, row); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, __real_cJSON_GetObjectItem(root->child, "id")); - - expect_function_call(__wrap_cJSON_Delete); - - id = wdb_find_group(name, NULL); - - assert_int_equal(1, id); - - __real_cJSON_Delete(root); -} - -/* Tests wdb_insert_group */ - -void test_wdb_insert_group_error_socket(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global insert-agent-group test_group"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global insert-agent-group test_group"); - - ret = wdb_insert_group(name, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_insert_group_error_sql_execution(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global insert-agent-group test_group"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global insert-agent-group test_group"); - - ret = wdb_insert_group(name, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_insert_group_error_result(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global insert-agent-group test_group"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_insert_group(name, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_insert_group_success(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global insert-agent-group test_group"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_insert_group(name, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_remove_group_db */ - -void test_wdb_remove_group_db_generic_error_sql_execution(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global delete-group test_group"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_TIMEOUT); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global delete-group test_group"); - - ret = wdb_remove_group_db(name, NULL); - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_remove_group_db_error_sql_execution(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global delete-group test_group"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global delete-group test_group"); - - ret = wdb_remove_group_db(name, NULL); - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_remove_group_db_error_result(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global delete-group test_group"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_remove_group_db(name, NULL); - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_remove_group_db_success(void **state) -{ - int ret = 0; - const char *name = "test_group"; - - const char *query_str = "global delete-group test_group"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_remove_group_db(name, NULL); - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_update_groups */ - -void test_wdb_update_groups_error_json(void **state) { - int ret = 0; - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to update groups."); - - ret = wdb_update_groups(SHAREDCFG_DIR, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_update_groups_error_max_path(void **state) { - cJSON *root = NULL; - cJSON *row1 = NULL; - cJSON *row2 = NULL; - cJSON *str1 = NULL; - cJSON *str2 = NULL; - char *very_long_name = NULL; - - // Generating a very long group name - os_calloc(PATH_MAX+1, sizeof(char), very_long_name); - for (int i = 0; i < PATH_MAX; ++i) {*(very_long_name + i) = 'A';} - - root = __real_cJSON_CreateArray(); - row1 = __real_cJSON_CreateObject(); - str1 = __real_cJSON_CreateString(very_long_name); - __real_cJSON_AddItemToObject(row1, "name", str1); - __real_cJSON_AddItemToArray(root, row1); - row2 = __real_cJSON_CreateObject(); - str2 = __real_cJSON_CreateString("test_group"); - __real_cJSON_AddItemToObject(row2, "name", str2); - __real_cJSON_AddItemToArray(root, row2); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, str1); - will_return(__wrap_cJSON_GetObjectItem, str2); - - expect_function_call(__wrap_cJSON_Delete); - - expect_string(__wrap__merror, formatted_msg, "At wdb_update_groups(): path too long."); - - // Opening directory - will_return(__wrap_opendir, 1); - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "error"); - expect_string(__wrap__merror, formatted_msg, "Couldn't open directory 'etc/shared': error."); - - wdb_update_groups(SHAREDCFG_DIR, NULL); - - __real_cJSON_Delete(root); - os_free(very_long_name); -} - -void test_wdb_update_groups_removing_group_db(void **state) { - int ret = 0; - cJSON *root = NULL; - cJSON *row = NULL; - cJSON *str = NULL; - - root = __real_cJSON_CreateArray(); - row = __real_cJSON_CreateObject(); - str = __real_cJSON_CreateString("test_group"); - __real_cJSON_AddItemToObject(row, "name", str); - __real_cJSON_AddItemToArray(root, row); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, str); - - expect_function_call(__wrap_cJSON_Delete); - - // Opening directory - will_return(__wrap_opendir, 0); - - //// Call to wdb_remove_group_db - const char *query_str = "global delete-group test_group"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - // Opening directory - will_return(__wrap_opendir, 1); - will_return(__wrap_readdir, 0); - - ret = wdb_update_groups(SHAREDCFG_DIR, NULL); - - assert_int_equal(OS_SUCCESS, ret); - - __real_cJSON_Delete(root); -} - -void test_wdb_update_groups_error_adding_new_groups(void **state) { - int ret = 0; - cJSON *root = NULL; - cJSON *row = NULL; - cJSON *str = NULL; - - root = __real_cJSON_CreateArray(); - row = __real_cJSON_CreateObject(); - str = __real_cJSON_CreateString("test_group"); - __real_cJSON_AddItemToObject(row, "name", str); - __real_cJSON_AddItemToArray(root, row); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, str); - - expect_function_call(__wrap_cJSON_Delete); - - // Opening directory - will_return(__wrap_opendir, 1); - - // Adding new groups - will_return(__wrap_opendir, 0); - will_return(__wrap_strerror, "error"); - expect_string(__wrap__merror, formatted_msg, "Couldn't open directory 'etc/shared': error."); - - ret = wdb_update_groups(SHAREDCFG_DIR, NULL); - - assert_int_equal(OS_INVALID, ret); - - __real_cJSON_Delete(root); -} - -void test_wdb_update_groups_success(void **state) { - int ret = 0; - cJSON *root = NULL; - cJSON *row = NULL; - cJSON *str = NULL; - - root = __real_cJSON_CreateArray(); - row = __real_cJSON_CreateObject(); - str = __real_cJSON_CreateString("test_group"); - __real_cJSON_AddItemToObject(row, "name", str); - __real_cJSON_AddItemToArray(root, row); - - struct dirent *dir_ent = NULL; - os_calloc(1, sizeof(struct dirent), dir_ent); - strncpy(dir_ent->d_name, "test_group\0", 11); - - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, root); - - // Getting JSON data - will_return(__wrap_cJSON_GetObjectItem, str); - - expect_function_call(__wrap_cJSON_Delete); - - // Opening directory - will_return(__wrap_opendir, 1); - - // Adding new groups - will_return(__wrap_opendir, 1); - will_return(__wrap_readdir, dir_ent); - expect_string(__wrap_IsDir, file, "etc/shared/test_group"); - will_return(__wrap_IsDir, 0); - - //// Call to wdb_find_group - // Calling Wazuh DB - will_return(__wrap_wdbc_query_parse_json, 0); - will_return(__wrap_wdbc_query_parse_json, NULL); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get the agent group id."); - - //// Call to wdb_insert_group - const char *query_str = "global insert-agent-group test_group"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_readdir, NULL); - - ret = wdb_update_groups(SHAREDCFG_DIR, NULL); - - assert_int_equal(OS_SUCCESS, ret); - - __real_cJSON_Delete(root); - os_free(dir_ent); -} - -/* Tests get_agent_date_added */ - -void test_get_agent_date_added_error_open_file(void **state) { - time_t date_add = 0; - int agent_id = 1; - - // Opening destination database file - expect_string(__wrap_wfopen, path, "queue/agents-timestamp"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 0); - - date_add = get_agent_date_added(agent_id); - - assert_int_equal(0, date_add); -} - -void test_get_agent_date_added_error_no_data(void **state) { - time_t date_add = 0; - int agent_id = 1; - - // Opening destination database file - expect_string(__wrap_wfopen, path, "queue/agents-timestamp"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 1); - - // Getting data - expect_value(__wrap_fgets, __stream, 1); - will_return(__wrap_fgets, "001 agent1"); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, OS_SUCCESS); - - date_add = get_agent_date_added(agent_id); - - assert_int_equal(0, date_add); -} - -void test_get_agent_date_added_error_no_date(void **state) { - time_t date_add = 0; - int agent_id = 1; - - // Opening destination database file - expect_string(__wrap_wfopen, path, "queue/agents-timestamp"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 1); - - // Getting data - expect_value(__wrap_fgets, __stream, 1); - will_return(__wrap_fgets, "001 agent1 any"); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, OS_SUCCESS); - - date_add = get_agent_date_added(agent_id); - - assert_int_equal(0, date_add); -} - -void test_get_agent_date_added_error_invalid_date(void **state) { - time_t date_add = 0; - int agent_id = 1; - - // Opening destination database file - expect_string(__wrap_wfopen, path, "queue/agents-timestamp"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 1); - - // Getting data - expect_value(__wrap_fgets, __stream, 1); - will_return(__wrap_fgets, "001 agent1 any 2020:01:01 01-01-01"); - - expect_string(__wrap__merror, formatted_msg, "Invalid date format in file 'queue/agents-timestamp' for agent '1'"); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, OS_SUCCESS); - - date_add = get_agent_date_added(agent_id); - - assert_int_equal(0, date_add); -} - -void test_get_agent_date_added_success(void **state) { - time_t date_add = 0; - int agent_id = 1; - struct tm test_time; - time_t date_returned = 0; - - // Opening destination database file - expect_string(__wrap_wfopen, path, "queue/agents-timestamp"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, 1); - - // Getting data - expect_value(__wrap_fgets, __stream, 1); - will_return(__wrap_fgets, "001 agent1 any 2020-08-01 01:01:01"); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, OS_SUCCESS); - - date_add = get_agent_date_added(agent_id); - - // The date_returned variable is the date 2020-01-01 01:01:01 transformed to INT - test_time.tm_year = 2020-1900; - test_time.tm_mon = 8-1; - test_time.tm_mday = 1; - test_time.tm_hour = 1; - test_time.tm_min = 1; - test_time.tm_sec = 1; - test_time.tm_isdst = -1; - - date_returned = mktime(&test_time); - - assert_int_equal(date_returned, date_add); -} - -/* Tests wdb_reset_agents_connection */ - -void test_wdb_reset_agents_connection_error_socket(void **state) -{ - int ret = 0; - const char *sync_status = "synced"; - const char *query_str = "global reset-agents-connection synced"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global reset-agents-connection synced"); - - ret = wdb_reset_agents_connection(sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_reset_agents_connection_error_sql_execution(void **state) -{ - int ret = 0; - const char *sync_status = "synced"; - const char *query_str = "global reset-agents-connection synced"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, -100); // Returning any error - - // Handling result - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global reset-agents-connection synced"); - - ret = wdb_reset_agents_connection(sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_reset_agents_connection_error_result(void **state) -{ - int ret = 0; - const char *sync_status = "synced"; - const char *query_str = "global reset-agents-connection synced"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - ret = wdb_reset_agents_connection(sync_status, NULL); - - assert_int_equal(OS_INVALID, ret); -} - -void test_wdb_reset_agents_connection_success(void **state) -{ - int ret = 0; - const char *sync_status = "synced"; - const char *query_str = "global reset-agents-connection synced"; - const char *response = "ok"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - ret = wdb_reset_agents_connection(sync_status, NULL); - - assert_int_equal(OS_SUCCESS, ret); -} - -/* Tests wdb_get_agents_by_connection_status */ - -void test_wdb_get_agents_by_connection_status_query_error(void **state) -{ - const char *query_str = "global get-agents-by-connection-status 0 active"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - int *array = wdb_get_agents_by_connection_status("active", NULL); - - assert_null(array); -} - -void test_wdb_get_agents_ids_of_current_node_query_error(void **state) -{ - const char *query_str = "global get-agents-by-connection-status 0 active node01 -1"; - const char *response = "err"; - char *cluster_node_name = NULL; - cluster_node_name = strdup("node01"); - - // Calling Wazuh DB - will_return(__wrap_get_node_name, cluster_node_name); - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - int *array = wdb_get_agents_ids_of_current_node("active", NULL, 0, -1); - - assert_null(array); -} - -void test_wdb_get_agents_by_connection_status_parse_error(void **state) -{ - const char *query_str = "global get-agents-by-connection-status 0 active"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - int *array = wdb_get_agents_by_connection_status("active", NULL); - - assert_null(array); -} - -void test_wdb_get_agents_ids_of_current_node_parse_error(void **state) -{ - const char *query_str = "global get-agents-by-connection-status 0 active node01 -1"; - const char *response = "err"; - char *cluster_node_name = NULL; - cluster_node_name = strdup("node01"); - - // Calling Wazuh DB - will_return(__wrap_get_node_name, cluster_node_name); - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - int *array = wdb_get_agents_ids_of_current_node("active", NULL, 0, -1); - - assert_null(array); -} - -void test_wdb_get_agents_by_connection_status_success(void **state) -{ - const char *query_str = "global get-agents-by-connection-status 0 active"; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1},{\"id\":2},{\"id\":3}]"); - cJSON* test_json = __real_cJSON_Parse(test_payload+3); - cJSON* id1 = cJSON_CreateNumber(1); - cJSON* id2 = cJSON_CreateNumber(2); - cJSON* id3 = cJSON_CreateNumber(3); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, test_payload); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json); - will_return(__wrap_cJSON_GetObjectItem, id1); - will_return(__wrap_cJSON_GetObjectItem, id2); - will_return(__wrap_cJSON_GetObjectItem, id3); - expect_function_call(__wrap_cJSON_Delete); - - int *array = wdb_get_agents_by_connection_status("active", NULL); - - assert_non_null(array); - assert_int_equal(1, array[0]); - assert_int_equal(2, array[1]); - assert_int_equal(3, array[2]); - assert_int_equal(-1, array[3]); - - os_free(array); - __real_cJSON_Delete(test_json); - __real_cJSON_Delete(id1); - __real_cJSON_Delete(id2); - __real_cJSON_Delete(id3); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_get_agents_ids_of_current_node_success(void **state) -{ - const char *query_str = "global get-agents-by-connection-status 0 active node01 -1"; - char *cluster_node_name = NULL; - cluster_node_name = strdup("node01"); - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1},{\"id\":2},{\"id\":3}]"); - cJSON* test_json = __real_cJSON_Parse(test_payload+3); - cJSON* id1 = cJSON_CreateNumber(1); - cJSON* id2 = cJSON_CreateNumber(2); - cJSON* id3 = cJSON_CreateNumber(3); - - // Calling Wazuh DB - will_return(__wrap_get_node_name, cluster_node_name); - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, test_payload); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json); - will_return(__wrap_cJSON_GetObjectItem, id1); - will_return(__wrap_cJSON_GetObjectItem, id2); - will_return(__wrap_cJSON_GetObjectItem, id3); - expect_function_call(__wrap_cJSON_Delete); - - int *array = wdb_get_agents_ids_of_current_node("active", NULL, 0, -1); - - assert_non_null(array); - assert_int_equal(1, array[0]); - assert_int_equal(2, array[1]); - assert_int_equal(3, array[2]); - assert_int_equal(-1, array[3]); - - os_free(array); - __real_cJSON_Delete(test_json); - __real_cJSON_Delete(id1); - __real_cJSON_Delete(id2); - __real_cJSON_Delete(id3); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -/* Tests wdb_disconnect_agents */ - -void test_wdb_disconnect_agents_wdbc_query_error(void **state) { - const char *query_str = "global disconnect-agents 0 100 syncreq"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - int *array = wdb_disconnect_agents(100, "syncreq", NULL); - - assert_null(array); -} - -void test_wdb_disconnect_agents_wdbc_parse_error(void **state) { - const char *query_str = "global disconnect-agents 0 100 syncreq"; - const char *response = "err"; - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - int *array = wdb_disconnect_agents(100, "syncreq", NULL); - - assert_null(array); -} - -void test_wdb_disconnect_agents_success(void **state) { - const char *query_str = "global disconnect-agents 0 100 syncreq"; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1},{\"id\":2},{\"id\":3}]"); - cJSON* test_json = __real_cJSON_Parse(test_payload+3); - cJSON* id1 = cJSON_CreateNumber(1); - cJSON* id2 = cJSON_CreateNumber(2); - cJSON* id3 = cJSON_CreateNumber(3); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, test_payload); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json); - will_return(__wrap_cJSON_GetObjectItem, id1); - will_return(__wrap_cJSON_GetObjectItem, id2); - will_return(__wrap_cJSON_GetObjectItem, id3); - expect_function_call(__wrap_cJSON_Delete); - - int *array = wdb_disconnect_agents(100, "syncreq", NULL); - - assert_non_null(array); - assert_int_equal(1, array[0]); - assert_int_equal(2, array[1]); - assert_int_equal(3, array[2]); - assert_int_equal(-1, array[3]); - - os_free(array); - __real_cJSON_Delete(test_json); - __real_cJSON_Delete(id1); - __real_cJSON_Delete(id2); - __real_cJSON_Delete(id3); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -/* Tests wdb_parse_chunk_to_int */ - -void test_wdb_parse_chunk_to_int_ok(void **state) { - int* array = NULL; - int last_item = 0; - int last_len = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1}]"); - cJSON* test_json = __real_cJSON_Parse(test_payload+3); - cJSON* id1 = cJSON_CreateNumber(1); - - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json); - will_return(__wrap_cJSON_GetObjectItem, id1); - expect_function_call(__wrap_cJSON_Delete); - - wdbc_result status = wdb_parse_chunk_to_int(test_payload, &array, "id", &last_item, &last_len); - - assert_int_equal(WDBC_OK, status); - assert_non_null(array); - assert_int_equal(1, array[0]); - - os_free(array); - __real_cJSON_Delete(test_json); - __real_cJSON_Delete(id1); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_parse_chunk_to_int_due(void **state) { - int* array = NULL; - int last_item = 0; - int last_len = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "due [{\"id\":1}]"); - cJSON* test_json1 = __real_cJSON_Parse(test_payload+4); - cJSON* id1 = cJSON_CreateNumber(1); - - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_DUE); - will_return(__wrap_cJSON_Parse, test_json1); - will_return(__wrap_cJSON_GetObjectItem, id1); - expect_function_call(__wrap_cJSON_Delete); - - wdbc_result status = wdb_parse_chunk_to_int(test_payload, &array, "id", &last_item, &last_len); - assert_int_equal(WDBC_DUE, status); - - // Setting second payload - strcpy(test_payload, "ok [{\"id\":2}]"); - cJSON* test_json2 = __real_cJSON_Parse(test_payload+3); - cJSON* id2 = cJSON_CreateNumber(2); - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json2); - will_return(__wrap_cJSON_GetObjectItem, id2); - expect_function_call(__wrap_cJSON_Delete); - - status = wdb_parse_chunk_to_int(test_payload, &array, "id", &last_item, &last_len); - assert_int_equal(WDBC_OK, status); - assert_non_null(array); - assert_int_equal(1, array[0]); - assert_int_equal(2, array[1]); - assert_int_equal(-1, array[2]); - - os_free(array); - __real_cJSON_Delete(test_json1); - __real_cJSON_Delete(id1); - __real_cJSON_Delete(test_json2); - __real_cJSON_Delete(id2); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_parse_chunk_to_int_err(void **state) { - int* array = NULL; - int last_item = 0; - int last_len = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1}]"); - - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, NULL); - - wdbc_result status = wdb_parse_chunk_to_int(test_payload, &array, "id", &last_item, &last_len); - - assert_int_equal(WDBC_ERROR, status); - assert_null(array); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -/* Tests wdb_parse_chunk_to_rbtree */ - -void test_wdb_parse_chunk_to_rbtree_ok(void **state) { - rb_tree* tree = (rb_tree*)1; - int last_item = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1}]"); - cJSON* test_json = __real_cJSON_Parse(test_payload+3); - cJSON* id1 = cJSON_CreateNumber(1); - - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json); - will_return(__wrap_cJSON_GetObjectItem, id1); - expect_function_call(__wrap_cJSON_Delete); - - wdbc_result status = wdb_parse_chunk_to_rbtree(test_payload, &tree, "id", &last_item); - - assert_int_equal(WDBC_OK, status); - - __real_cJSON_Delete(test_json); - __real_cJSON_Delete(id1); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_parse_chunk_to_rbtree_due(void **state) { - rb_tree* tree = (rb_tree*)1; - int last_item = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "due [{\"id\":1}]"); - cJSON* test_json1 = __real_cJSON_Parse(test_payload+4); - cJSON* id1 = cJSON_CreateNumber(1); - - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_DUE); - will_return(__wrap_cJSON_Parse, test_json1); - will_return(__wrap_cJSON_GetObjectItem, id1); - expect_function_call(__wrap_cJSON_Delete); - - wdbc_result status = wdb_parse_chunk_to_rbtree(test_payload, &tree, "id", &last_item); - assert_int_equal(WDBC_DUE, status); - - // Setting second payload - strcpy(test_payload, "ok [{\"id\":2}]"); - cJSON* test_json2 = __real_cJSON_Parse(test_payload+3); - cJSON* id2 = cJSON_CreateNumber(2); - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, test_json2); - will_return(__wrap_cJSON_GetObjectItem, id2); - expect_function_call(__wrap_cJSON_Delete); - - status = wdb_parse_chunk_to_rbtree(test_payload, &tree, "id", &last_item); - assert_int_equal(WDBC_OK, status); - - __real_cJSON_Delete(test_json1); - __real_cJSON_Delete(id1); - __real_cJSON_Delete(test_json2); - __real_cJSON_Delete(id2); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_parse_chunk_to_rbtree_err(void **state) { - rb_tree* tree = (rb_tree*)1; - int last_item = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1}]"); - - // Parsing result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - will_return(__wrap_cJSON_Parse, NULL); - - wdbc_result status = wdb_parse_chunk_to_rbtree(test_payload, &tree, "id", &last_item); - - assert_int_equal(WDBC_ERROR, status); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_parse_chunk_to_rbtree_err_no_item(void **state) { - rb_tree* tree = (rb_tree*)1; - int last_item = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1}]"); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid item."); - - wdbc_result status = wdb_parse_chunk_to_rbtree(test_payload, &tree, NULL, &last_item); - - assert_int_equal(WDBC_ERROR, status); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_parse_chunk_to_rbtree_err_no_output(void **state) { - rb_tree* tree = NULL; - int last_item = 0; - - // Setting the payload - set_payload = 1; - strcpy(test_payload, "ok [{\"id\":1}]"); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid RB tree."); - - wdbc_result status = wdb_parse_chunk_to_rbtree(test_payload, &tree, "id", &last_item); - - assert_int_equal(WDBC_ERROR, status); - - // Cleaning payload - set_payload = 0; - memset(test_payload, '\0', OS_MAXSTR); -} - -void test_wdb_set_agent_groups_csv_success(void **state) { - int res; - - test_struct_t *data = (test_struct_t*)* state; - - // filling Json Object - will_return(__wrap_cJSON_CreateObject, 1); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "mode"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->mode); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->sync_status); - expect_string(__wrap_cJSON_AddArrayToObject, name, "data"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - will_return(__wrap_cJSON_CreateObject, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, data->id); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - expect_string(__wrap_cJSON_AddArrayToObject, name, "groups"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - - // Json array items loop - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[0]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[1]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[2]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, data->data_in_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_value(__wrap_wdbc_query_ex, *sock, data->socket); - expect_string(__wrap_wdbc_query_ex, query, data->query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, data->response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - res = wdb_set_agent_groups_csv(data->id, data->groups_csv, data->mode, data->sync_status, &(data->socket)); - - assert_int_equal(OS_SUCCESS,res); -} - -void test_wdb_set_agent_groups_error_no_mode(void **state) { - char** groups_array = NULL; - char* mode = NULL; - char* sync_status = NULL; - int id = 1; - int socket = -1; - int res; - - // Debug message - expect_string(__wrap__mdebug1, formatted_msg, "Invalid params to set the agent groups 01"); - - res = wdb_set_agent_groups(id, groups_array, mode, sync_status, &socket); - - assert_int_equal(OS_INVALID,res); -} - -void test_wdb_set_agent_groups_socket_error(void **state) { - int res; - - test_struct_t *data = (test_struct_t*)* state; - - // filling Json Object - will_return(__wrap_cJSON_CreateObject, 1); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "mode"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->mode); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->sync_status); - expect_string(__wrap_cJSON_AddArrayToObject, name, "data"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - will_return(__wrap_cJSON_CreateObject, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, data->id); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - expect_string(__wrap_cJSON_AddArrayToObject, name, "groups"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - - // Json array items loop - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[0]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[1]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[2]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, data->data_in_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_value(__wrap_wdbc_query_ex, *sock, data->socket); - expect_string(__wrap_wdbc_query_ex, query, data->query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, data->response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - // Debug messages - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error in the response from socket"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: global set-agent-groups {\"mode\":\"mode_value\",\"sync_status\":\ - \"sync_status_value\",\"data\":[{\"id\":0,\"groups\":[\"default\",\"Group1\",\"Group2\"]}]}"); - - res = wdb_set_agent_groups(data->id, data->groups_array, data->mode, data->sync_status, &(data->socket)); - - assert_int_equal(OS_INVALID,res); -} - -void test_wdb_set_agent_groups_query_error(void **state) { - int res; - - test_struct_t *data = (test_struct_t*)* state; - - // filling Json Object - will_return(__wrap_cJSON_CreateObject, 1); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "mode"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->mode); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->sync_status); - expect_string(__wrap_cJSON_AddArrayToObject, name, "data"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - will_return(__wrap_cJSON_CreateObject, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, data->id); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - expect_string(__wrap_cJSON_AddArrayToObject, name, "groups"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - - // Json array items loop - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[0]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[1]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[2]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, data->data_in_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_value(__wrap_wdbc_query_ex, *sock, data->socket); - expect_string(__wrap_wdbc_query_ex, query, data->query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, data->response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - // Debug message - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Error reported in the result of the query"); - - res = wdb_set_agent_groups(data->id, data->groups_array, data->mode, data->sync_status, &(data->socket)); - - assert_int_equal(OS_INVALID,res); -} - -void test_wdb_set_agent_groups_success(void **state) { - int res; - - test_struct_t *data = (test_struct_t*)* state; - - // filling Json Object - will_return(__wrap_cJSON_CreateObject, 1); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "mode"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->mode); - will_return(__wrap_cJSON_AddStringToObject, 1); - expect_string(__wrap_cJSON_AddStringToObject, name, "sync_status"); - expect_string(__wrap_cJSON_AddStringToObject, string, data->sync_status); - expect_string(__wrap_cJSON_AddArrayToObject, name, "data"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - will_return(__wrap_cJSON_CreateObject, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_AddNumberToObject, name, "id"); - expect_value(__wrap_cJSON_AddNumberToObject, number, data->id); - will_return_always(__wrap_cJSON_AddNumberToObject, 1); - expect_string(__wrap_cJSON_AddArrayToObject, name, "groups"); - will_return(__wrap_cJSON_AddArrayToObject, 1); - - // Json array items loop - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[0]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[1]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - expect_string(__wrap_cJSON_CreateString, string, data->groups_array[2]); - will_return(__wrap_cJSON_CreateString, 1); - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - // Printing JSON - will_return(__wrap_cJSON_PrintUnformatted, data->data_in_str); - expect_function_call(__wrap_cJSON_Delete); - - // Calling Wazuh DB - expect_value(__wrap_wdbc_query_ex, *sock, data->socket); - expect_string(__wrap_wdbc_query_ex, query, data->query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, data->response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - // Parsing Wazuh DB result - expect_any(__wrap_wdbc_parse_result, result); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - res = wdb_set_agent_groups(data->id, data->groups_array, data->mode, data->sync_status, &(data->socket)); - - assert_int_equal(OS_SUCCESS,res); -} - -/* Tests wdb_get_distinct_agent_groups */ - -void test_wdb_get_distinct_agent_groups_error_no_json_response(void **state) { - cJSON *root = NULL; - const char *query_str = "global get-distinct-groups "; - const char *response = "err"; - - will_return(__wrap_cJSON_CreateArray, NULL); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get agent's groups."); - - expect_function_call(__wrap_cJSON_Delete); - - root = wdb_get_distinct_agent_groups(NULL); - - assert_null(root); -} - -void test_wdb_get_distinct_agent_groups_error_parse_chunk(void **state) { - cJSON *root = NULL; - const char *query_str = "global get-distinct-groups "; - const char *response = "ok []"; - - will_return(__wrap_cJSON_CreateArray, NULL); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid JSON array."); - - expect_string(__wrap__merror, formatted_msg, "Error querying Wazuh DB to get agent's groups."); - - expect_function_call(__wrap_cJSON_Delete); - - root = wdb_get_distinct_agent_groups(NULL); - - assert_null(root); -} - -void test_wdb_get_distinct_agent_groups_success(void **state) { - cJSON *root = NULL; - const char *query_str = "global get-distinct-groups "; - const char *response = "ok [{\"group\":\"group3,group4\",\"group_hash\":\"abcdef\"}]"; - cJSON *str_obj = __real_cJSON_CreateString("abcdef"); - cJSON *parse_json = __real_cJSON_Parse("[{\"group\":\"group3,group4\",\"group_hash\":\"abcdef\"}]"); - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - - // Calling Wazuh DB - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - expect_string(__wrap_wdbc_parse_result, result, response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, parse_json); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - will_return(__wrap_cJSON_GetObjectItem, str_obj); - - root = wdb_get_distinct_agent_groups(NULL); - - __real_cJSON_Delete(root); - __real_cJSON_Delete(parse_json); - __real_cJSON_Delete(str_obj); -} - -void test_wdb_get_distinct_agent_groups_success_due_ok(void **state) { - cJSON *root = NULL; - const char *query_str1 = "global get-distinct-groups "; - const char *query_str2 = "global get-distinct-groups ef48b4cd"; - const char *response1 = "ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"; - const char *response2 = "ok [{\"group\":\"group3,group4\",\"group_hash\":\"abcdef\"}]"; - cJSON *str_obj1 = __real_cJSON_CreateString("ef48b4cd"); - cJSON *str_obj2 = __real_cJSON_CreateString("abcdef"); - cJSON *parse_json1 = __real_cJSON_Parse("[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"); - cJSON *parse_json2 = __real_cJSON_Parse("[{\"group\":\"group3,group4\",\"group_hash\":\"abcdef\"}]"); - - will_return(__wrap_cJSON_CreateArray, __real_cJSON_CreateArray()); - - // Calling Wazuh DB 1 - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str1); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response1); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - expect_string(__wrap_wdbc_parse_result, result, response1); - will_return(__wrap_wdbc_parse_result, WDBC_DUE); - - will_return(__wrap_cJSON_Parse, parse_json1); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - will_return(__wrap_cJSON_GetObjectItem, str_obj1); - - // Calling Wazuh DB 2 - expect_any(__wrap_wdbc_query_ex, *sock); - expect_string(__wrap_wdbc_query_ex, query, query_str2); - expect_value(__wrap_wdbc_query_ex, len, WDBOUTPUT_SIZE); - will_return(__wrap_wdbc_query_ex, response2); - will_return(__wrap_wdbc_query_ex, OS_SUCCESS); - - expect_string(__wrap_wdbc_parse_result, result, response2); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, parse_json2); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - will_return(__wrap_cJSON_GetObjectItem, str_obj2); - - root = wdb_get_distinct_agent_groups(NULL); - - __real_cJSON_Delete(root); - __real_cJSON_Delete(parse_json1); - __real_cJSON_Delete(str_obj1); - __real_cJSON_Delete(parse_json2); - __real_cJSON_Delete(str_obj2); -} - -/* Tests wdb_parse_chunk_to_json_by_string_item */ - -void test_wdb_parse_chunk_to_json_by_string_item_output_json_null(void **state) { - char *input = "ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"; - char *last_item_value; - wdbc_result result; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid JSON array."); - - result = wdb_parse_chunk_to_json_by_string_item(input, NULL, "group_hash", &last_item_value); - - assert_int_equal(result, WDBC_ERROR); -} - -void test_wdb_parse_chunk_to_json_by_string_item_item_null(void **state) { - char *input = "ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"; - cJSON *output_json = __real_cJSON_CreateArray(); - char *last_item_value; - wdbc_result result; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid item."); - - result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, NULL, &last_item_value); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(output_json); -} - -void test_wdb_parse_chunk_to_json_by_string_item_output_json_no_array(void **state) { - char *input = "ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"; - cJSON *output_json = __real_cJSON_CreateString("wrong object"); - char *last_item_value; - wdbc_result result; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid JSON array."); - - result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", &last_item_value); - - assert_int_equal(result, WDBC_ERROR); - __real_cJSON_Delete(output_json); -} - -void test_wdb_parse_chunk_to_json_by_string_item_parse_result_error(void **state) { - char *input = NULL; - os_strdup("ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]", input); - cJSON *output_json = __real_cJSON_CreateArray(); - char *last_item_value; - wdbc_result exc_result; - - expect_string(__wrap_wdbc_parse_result, result, input); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - exc_result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", &last_item_value); - - assert_int_equal(exc_result, WDBC_ERROR); - __real_cJSON_Delete(output_json); - os_free(input); -} - -void test_wdb_parse_chunk_to_json_by_string_item_cjson_parse_error(void **state) { - char *input = NULL; - os_strdup("ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]", input); - cJSON *output_json = __real_cJSON_CreateArray(); - char *last_item_value; - wdbc_result exc_result; - - expect_string(__wrap_wdbc_parse_result, result, input); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, NULL); - - exc_result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", &last_item_value); - - assert_int_equal(exc_result, WDBC_ERROR); - __real_cJSON_Delete(output_json); - os_free(input); -} - -void test_wdb_parse_chunk_to_json_by_string_item_empty_array(void **state) { - char *input = NULL; - os_strdup("ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]", input); - cJSON *output_json = __real_cJSON_CreateArray(); - cJSON *parse_json = __real_cJSON_CreateArray(); - char *last_item_value; - wdbc_result exc_result; - - expect_string(__wrap_wdbc_parse_result, result, input); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, parse_json); - - expect_function_call(__wrap_cJSON_Delete); - - exc_result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", &last_item_value); - - assert_int_equal(exc_result, WDBC_OK); - __real_cJSON_Delete(output_json); - __real_cJSON_Delete(parse_json); - os_free(input); -} - -void test_wdb_parse_chunk_to_json_by_string_item_last_item_json_null(void **state) { - char *input = NULL; - os_strdup("ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]", input); - cJSON *output_json = __real_cJSON_CreateArray(); - cJSON *parse_json = __real_cJSON_Parse("[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"); - char *last_item_value = NULL; - wdbc_result exc_result; - - expect_string(__wrap_wdbc_parse_result, result, input); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, parse_json); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - exc_result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", &last_item_value); - - assert_int_equal(exc_result, WDBC_OK); - assert_null(last_item_value); - __real_cJSON_Delete(output_json); - __real_cJSON_Delete(parse_json); - os_free(input); -} - -void test_wdb_parse_chunk_to_json_by_string_item_string_value_fail(void **state) { - char *input = NULL; - os_strdup("ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]", input); - cJSON *output_json = __real_cJSON_CreateArray(); - cJSON *parse_json = __real_cJSON_Parse("[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"); - char *last_item_value = NULL; - wdbc_result exc_result; - cJSON *int_obj = cJSON_CreateNumber(1); - - expect_string(__wrap_wdbc_parse_result, result, input); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, parse_json); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - will_return(__wrap_cJSON_GetObjectItem, int_obj); - - exc_result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", &last_item_value); - - assert_int_equal(exc_result, WDBC_OK); - assert_null(last_item_value); - __real_cJSON_Delete(output_json); - __real_cJSON_Delete(parse_json); - __real_cJSON_Delete(int_obj); - os_free(input); -} - -void test_wdb_parse_chunk_to_json_by_string_last_item_value_null(void **state) { - char *input = NULL; - os_strdup("ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]", input); - cJSON *output_json = __real_cJSON_CreateArray(); - cJSON *parse_json = __real_cJSON_Parse("[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"); - char *last_item_value = NULL; - wdbc_result exc_result; - cJSON *str_obj = __real_cJSON_CreateString("ef48b4cd"); - - expect_string(__wrap_wdbc_parse_result, result, input); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, parse_json); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - will_return(__wrap_cJSON_GetObjectItem, str_obj); - - exc_result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", NULL); - - assert_int_equal(exc_result, WDBC_OK); - assert_null(last_item_value); - __real_cJSON_Delete(output_json); - __real_cJSON_Delete(parse_json); - __real_cJSON_Delete(str_obj); - os_free(input); -} - -void test_wdb_parse_chunk_to_json_by_string_item_success(void **state) { - char *input = NULL; - os_strdup("ok [{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]", input); - cJSON *output_json = __real_cJSON_CreateArray(); - cJSON *parse_json = __real_cJSON_Parse("[{\"group\":\"group1,group2\",\"group_hash\":\"ef48b4cd\"}]"); - char *last_item_value; - wdbc_result exc_result; - cJSON *str_obj = __real_cJSON_CreateString("ef48b4cd"); - - expect_string(__wrap_wdbc_parse_result, result, input); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - will_return(__wrap_cJSON_Parse, parse_json); - - expect_function_call(__wrap_cJSON_AddItemToArray); - will_return(__wrap_cJSON_AddItemToArray, true); - - will_return(__wrap_cJSON_GetObjectItem, str_obj); - - exc_result = wdb_parse_chunk_to_json_by_string_item(input, &output_json, "group_hash", &last_item_value); - - assert_int_equal(exc_result, WDBC_OK); - assert_string_equal(last_item_value, "ef48b4cd"); - __real_cJSON_Delete(output_json); - __real_cJSON_Delete(parse_json); - __real_cJSON_Delete(str_obj); - os_free(input); - os_free(last_item_value); -} - -int main() -{ - const struct CMUnitTest tests[] = - { - /* Tests wdb_insert_agent */ - cmocka_unit_test_setup_teardown(test_wdb_insert_agent_error_json, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_agent_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_agent_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_agent_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_agent_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_agent_success_keep_date, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_update_agent_name */ - cmocka_unit_test_setup_teardown(test_wdb_update_agent_name_error_json, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_name_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_name_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_name_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_name_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_update_agent_data */ - cmocka_unit_test_setup_teardown(test_wdb_update_agent_data_invalid_data, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_data_error_json, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_data_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_data_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_data_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_data_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_agent_info */ - cmocka_unit_test_setup_teardown(test_wdb_get_agent_info_error_no_json_response, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agent_info_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_agent_labels */ - cmocka_unit_test_setup_teardown(test_wdb_get_agent_labels_error_no_json_response, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agent_labels_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_update_agent_keepalive */ - cmocka_unit_test_setup_teardown(test_wdb_update_agent_keepalive_error_json, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_keepalive_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_keepalive_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_keepalive_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_keepalive_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_update_agent_connection_status */ - cmocka_unit_test_setup_teardown(test_wdb_update_agent_connection_status_error_json, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_connection_status_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_connection_status_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_connection_status_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_connection_status_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_update_agent_status_code */ - cmocka_unit_test_setup_teardown(test_wdb_update_agent_status_code_error_json, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_status_code_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_status_code_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_status_code_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_agent_status_code_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_agent_name */ - cmocka_unit_test_setup_teardown(test_wdb_get_agent_name_error_no_json_response, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agent_name_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agent_name_not_found, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_remove_agent */ - cmocka_unit_test_setup_teardown(test_wdb_remove_agent_remove_db_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_remove_agent_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_remove_agent_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_remove_agent_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_remove_agent_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_get_agent_group_error_no_json_response, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agent_group_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_find_agent */ - cmocka_unit_test_setup_teardown(test_wdb_find_agent_error_invalid_parameters, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_find_agent_error_json_input, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_find_agent_error_json_output, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_find_agent_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_all_agents */ - cmocka_unit_test_setup_teardown(test_wdb_get_all_agents_wdbc_query_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_all_agents_wdbc_parse_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_all_agents_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_all_agents_rbtree */ - cmocka_unit_test_setup_teardown(test_wdb_get_all_agents_rbtree_wdbc_query_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_all_agents_rbtree_wdbc_parse_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_all_agents_rbtree_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_find_group */ - cmocka_unit_test_setup_teardown(test_wdb_find_group_error_no_json_response, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_find_group_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_insert_group */ - cmocka_unit_test_setup_teardown(test_wdb_insert_group_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_group_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_group_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_insert_group_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_remove_group_db */ - cmocka_unit_test_setup_teardown(test_wdb_remove_group_db_generic_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_remove_group_db_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_remove_group_db_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_remove_group_db_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - - cmocka_unit_test_setup_teardown(test_wdb_remove_group_db_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_update_groups */ - cmocka_unit_test_setup_teardown(test_wdb_update_groups_error_json, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_groups_error_max_path, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_groups_removing_group_db, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_groups_error_adding_new_groups, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_update_groups_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests get_agent_date_added */ - cmocka_unit_test_setup_teardown(test_get_agent_date_added_error_open_file, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_get_agent_date_added_error_no_data, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_get_agent_date_added_error_no_date, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_get_agent_date_added_error_invalid_date, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_get_agent_date_added_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_reset_agents_connection */ - cmocka_unit_test_setup_teardown(test_wdb_reset_agents_connection_error_socket, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_reset_agents_connection_error_sql_execution, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_reset_agents_connection_error_result, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_reset_agents_connection_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_agents_by_connection_status */ - cmocka_unit_test_setup_teardown(test_wdb_get_agents_by_connection_status_query_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agents_by_connection_status_parse_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agents_by_connection_status_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_get_agents_ids_of_current_node */ - cmocka_unit_test_setup_teardown(test_wdb_get_agents_ids_of_current_node_query_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agents_ids_of_current_node_parse_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_agents_ids_of_current_node_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_disconnect_agents */ - cmocka_unit_test_setup_teardown(test_wdb_disconnect_agents_wdbc_query_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_disconnect_agents_wdbc_parse_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_disconnect_agents_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_parse_chunk_to_int */ - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_int_ok, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_int_due, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_int_err, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_parse_chunk_to_rbtree */ - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_rbtree_ok, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_rbtree_due, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_rbtree_err, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_rbtree_err_no_item, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_rbtree_err_no_output, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_set_agent_groups */ - cmocka_unit_test_setup_teardown(test_wdb_set_agent_groups_csv_success, setup_wdb_global_helpers_add_agent, teardown_wdb_global_helpers_add_agent), - cmocka_unit_test_setup_teardown(test_wdb_set_agent_groups_success, setup_wdb_global_helpers_add_agent, teardown_wdb_global_helpers_add_agent), - cmocka_unit_test_setup_teardown(test_wdb_set_agent_groups_error_no_mode, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_set_agent_groups_query_error, setup_wdb_global_helpers_add_agent, teardown_wdb_global_helpers_add_agent), - cmocka_unit_test_setup_teardown(test_wdb_set_agent_groups_socket_error, setup_wdb_global_helpers_add_agent, teardown_wdb_global_helpers_add_agent), - /* Tests wdb_get_distinct_agent_groups */ - cmocka_unit_test_setup_teardown(test_wdb_get_distinct_agent_groups_error_no_json_response, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_distinct_agent_groups_error_parse_chunk, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_distinct_agent_groups_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_get_distinct_agent_groups_success_due_ok, setup_wdb_global_helpers, teardown_wdb_global_helpers), - /* Tests wdb_parse_chunk_to_json_by_string_item */ - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_output_json_null, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_item_null, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_output_json_no_array, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_parse_result_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_cjson_parse_error, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_empty_array, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_last_item_json_null, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_string_value_fail, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_last_item_value_null, setup_wdb_global_helpers, teardown_wdb_global_helpers), - cmocka_unit_test_setup_teardown(test_wdb_parse_chunk_to_json_by_string_item_success, setup_wdb_global_helpers, teardown_wdb_global_helpers), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_global_parser.c b/src/unit_tests/wazuh_db/test_wdb_global_parser.c deleted file mode 100644 index 1b54423d76a..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_global_parser.c +++ /dev/null @@ -1,5357 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include "hash_op.h" -#include "os_err.h" -#include "../wazuh_db/wdb.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_global_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "wazuhdb_op.h" - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -/** - * @brief Function that generates a random string of 'length' characters long. - * - * @param [in] length Length of the string to be generated. - * @return Response with the generated group name string. - */ -char* group_name_generator(int length) { - char *group_name = NULL; - os_calloc(MAX_GROUP_NAME+1, sizeof(char), group_name); - const char characters [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; - srand(time(NULL)); - for (int i = 0; i < length; ++i) { - group_name[i] = characters[rand() % (int)sizeof(characters-1)]; - } - return group_name; -} - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("global",init_data->wdb->id); - os_calloc(OS_MAXSTR,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - init_data->wdb->enabled=true; - *state = init_data; - return 0; -} - -static int test_teardown(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - -void test_wdb_parse_global_open_global_fail(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global "; - - will_return(__wrap_wdb_open_global, NULL); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: "); - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't open DB global: queue/db/global.db"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Couldn't open DB global"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_no_space(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global"; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB query: global"); - - expect_function_call(__wrap_w_inc_queries_total); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'global'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_substr_fail(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global error"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: error"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: error"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'error'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sql_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sql"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sql"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: sql"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_sql); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'sql'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sql_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sql TEST QUERY"; - cJSON *root = NULL; - cJSON *j_object = NULL; - - root = cJSON_CreateArray(); - j_object = cJSON_CreateObject(); - cJSON_AddStringToObject(j_object, "test_field", "test_value"); - cJSON_AddItemToArray(root, j_object); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sql TEST QUERY"); - will_return(__wrap_wdb_exec,root); - expect_string(__wrap_wdb_exec, sql, "TEST QUERY"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_sql); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_sql_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"test_field\":\"test_value\"}]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_sql_fail(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sql TEST QUERY"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap_wdb_exec, sql, "TEST QUERY"); - will_return(__wrap_wdb_exec, NULL); - - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sql TEST QUERY"); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB SQL query: TEST QUERY"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_sql); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_sql_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_actor_fail(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "error "; - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid DB query actor: error"); - - expect_function_call(__wrap_w_inc_queries_total); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query actor: 'error'"); - assert_int_equal(ret, OS_INVALID); -} - -/* Tests wdb_parse_global_insert_agent */ - -void test_wdb_parse_global_insert_agent_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for insert-agent."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: insert-agent"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_insert_agent); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'insert-agent'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_insert_agent_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when inserting agent."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_insert_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_insert_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_insert_agent_compliant_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent {\"id\":1,\"name\":\"test_name\",\"date_add\":null}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent {\"id\":1,\"name\":\"test_name\",\"date_add\":null}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON data when inserting agent. Not compliant with constraints defined in the database."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_insert_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_insert_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, near '{\"id\":1,\"name\":\"test_name\",\"date'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_insert_agent_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent {\"id\":1,\"name\":\"test_name\",\"date_add\":123}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent {\"id\":1,\"name\":\"test_name\",\"date_add\":123}"); - - expect_value(__wrap_wdb_global_insert_agent, id, 1); - expect_string(__wrap_wdb_global_insert_agent, name, "test_name"); - expect_value(__wrap_wdb_global_insert_agent, ip, NULL); - expect_value(__wrap_wdb_global_insert_agent, register_ip, NULL); - expect_value(__wrap_wdb_global_insert_agent, internal_key, NULL); - expect_value(__wrap_wdb_global_insert_agent, group, NULL); - expect_value(__wrap_wdb_global_insert_agent, date_add, 123); - will_return(__wrap_wdb_global_insert_agent, OS_INVALID); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_insert_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_insert_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_insert_agent_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent {\"id\":1,\"name\":\"test_name\",\"date_add\":123,\ - \"ip\":\"0.0.0.0\",\"register_ip\":\"1.1.1.1\",\"internal_key\":\"test_key\",\"group\":\"test_group\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent {\"id\":1,\"name\":\"test_name\",\"date_add\":123,\ - \"ip\":\"0.0.0.0\",\"register_ip\":\"1.1.1.1\",\"internal_key\":\"test_key\",\"group\":\"test_group\"}"); - - expect_value(__wrap_wdb_global_insert_agent, id, 1); - expect_string(__wrap_wdb_global_insert_agent, name, "test_name"); - expect_string(__wrap_wdb_global_insert_agent, ip, "0.0.0.0"); - expect_string(__wrap_wdb_global_insert_agent, register_ip, "1.1.1.1"); - expect_string(__wrap_wdb_global_insert_agent, internal_key, "test_key"); - expect_string(__wrap_wdb_global_insert_agent, group, "test_group"); - expect_value(__wrap_wdb_global_insert_agent, date_add, 123); - will_return(__wrap_wdb_global_insert_agent, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_insert_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_insert_agent_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_update_agent_name */ - -void test_wdb_parse_global_update_agent_name_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-name"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-agent-name"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for update-agent-name."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: update-agent-name"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'update-agent-name'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_name_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-name {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-agent-name {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when updating agent name."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_name_invalid_data(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-name {\"id\":1,\"name\":null}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-agent-name {\"id\":1,\"name\":null}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON data when updating agent name."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, near '{\"id\":1,\"name\":null}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_name_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-name {\"id\":1,\"name\":\"test_name\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-agent-name {\"id\":1,\"name\":\"test_name\"}"); - expect_value(__wrap_wdb_global_update_agent_name, id, 1); - expect_string(__wrap_wdb_global_update_agent_name, name, "test_name"); - will_return(__wrap_wdb_global_update_agent_name, OS_INVALID); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_name_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-name {\"id\":1,\"name\":\"test_name\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-agent-name {\"id\":1,\"name\":\"test_name\"}"); - expect_value(__wrap_wdb_global_update_agent_name, id, 1); - expect_string(__wrap_wdb_global_update_agent_name, name, "test_name"); - will_return(__wrap_wdb_global_update_agent_name, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_name_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_update_agent_data */ - -void test_wdb_parse_global_update_agent_data_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-data"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-agent-data"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for update-agent-data."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: update-agent-data"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'update-agent-data'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_data_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-data {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-agent-data {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when updating agent version."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_data_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-data {\"id\":1,\"os_name\":\"test_name\",\"os_version\":\"test_version\",\ - \"os_major\":\"test_major\",\"os_minor\":\"test_minor\",\"os_codename\":\"test_codename\",\"os_platform\":\"test_platform\",\ - \"os_build\":\"test_build\",\"os_uname\":\"test_uname\",\"os_arch\":\"test_arch\",\"version\":\"test_version\",\"config_sum\":\ - \"test_config\",\"merged_sum\":\"test_merged\",\"manager_host\":\"test_manager\",\"node_name\":\"test_node\",\"agent_ip\":\"test_ip\",\ - \"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"group_config_status\":\"synced\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, - "Global query: update-agent-data {\"id\":1,\"os_name\":\"test_name\",\"os_version\":\"test_version\",\ - \"os_major\":\"test_major\",\"os_minor\":\"test_minor\",\"os_codename\":\"test_codename\",\"os_platform\":\"test_platform\",\ - \"os_build\":\"test_build\",\"os_uname\":\"test_uname\",\"os_arch\":\"test_arch\",\"version\":\"test_version\",\"config_sum\":\ - \"test_config\",\"merged_sum\":\"test_merged\",\"manager_host\":\"test_manager\",\"node_name\":\"test_node\",\"agent_ip\":\"test_ip\",\ - \"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"group_config_status\":\"synced\"}"); - - expect_value(__wrap_wdb_global_update_agent_version, id, 1); - expect_string(__wrap_wdb_global_update_agent_version, os_name, "test_name"); - expect_string(__wrap_wdb_global_update_agent_version, os_version, "test_version"); - expect_string(__wrap_wdb_global_update_agent_version, os_major, "test_major"); - expect_string(__wrap_wdb_global_update_agent_version, os_minor, "test_minor"); - expect_string(__wrap_wdb_global_update_agent_version, os_codename, "test_codename"); - expect_string(__wrap_wdb_global_update_agent_version, os_platform, "test_platform"); - expect_string(__wrap_wdb_global_update_agent_version, os_build, "test_build"); - expect_string(__wrap_wdb_global_update_agent_version, os_uname, "test_uname"); - expect_string(__wrap_wdb_global_update_agent_version, os_arch, "test_arch"); - expect_string(__wrap_wdb_global_update_agent_version, version, "test_version"); - expect_string(__wrap_wdb_global_update_agent_version, config_sum, "test_config"); - expect_string(__wrap_wdb_global_update_agent_version, merged_sum, "test_merged"); - expect_string(__wrap_wdb_global_update_agent_version, manager_host, "test_manager"); - expect_string(__wrap_wdb_global_update_agent_version, node_name, "test_node"); - expect_string(__wrap_wdb_global_update_agent_version, agent_ip, "test_ip"); - expect_string(__wrap_wdb_global_update_agent_version, connection_status, "active"); - expect_string(__wrap_wdb_global_update_agent_version, sync_status, "syncreq"); - expect_string(__wrap_wdb_global_update_agent_version, group_config_status, "synced"); - - will_return(__wrap_wdb_global_update_agent_version, OS_INVALID); - - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_data_invalid_data(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-data {\"os_name\":\"test_name\",\"os_version\":\"test_version\",\ - \"os_major\":\"test_major\",\"os_minor\":\"test_minor\",\"os_codename\":\"test_codename\",\"os_platform\":\"test_platform\",\ - \"os_build\":\"test_build\",\"os_uname\":\"test_uname\",\"os_arch\":\"test_arch\",\"version\":\"test_version\",\"config_sum\":\ - \"test_config\",\"merged_sum\":\"test_merged\",\"manager_host\":\"test_manager\",\"node_name\":\"test_node\",\"agent_ip\":\"test_ip\",\ - \"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"group_config_status\":\"synced\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, - "Global query: update-agent-data {\"os_name\":\"test_name\",\"os_version\":\"test_version\",\ - \"os_major\":\"test_major\",\"os_minor\":\"test_minor\",\"os_codename\":\"test_codename\",\"os_platform\":\"test_platform\",\ - \"os_build\":\"test_build\",\"os_uname\":\"test_uname\",\"os_arch\":\"test_arch\",\"version\":\"test_version\",\"config_sum\":\ - \"test_config\",\"merged_sum\":\"test_merged\",\"manager_host\":\"test_manager\",\"node_name\":\"test_node\",\"agent_ip\":\"test_ip\",\ - \"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"group_config_status\":\"synced\"}"); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON data when updating agent version."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, near '{\"os_name\":\"test_name\",\"os_versi'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_data_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-agent-data {\"id\":1,\"os_name\":\"test_name\",\"os_version\":\"test_version\",\ - \"os_major\":\"test_major\",\"os_minor\":\"test_minor\",\"os_codename\":\"test_codename\",\"os_platform\":\"test_platform\",\ - \"os_build\":\"test_build\",\"os_uname\":\"test_uname\",\"os_arch\":\"test_arch\",\"version\":\"test_version\",\"config_sum\":\ - \"test_config\",\"merged_sum\":\"test_merged\",\"manager_host\":\"test_manager\",\"node_name\":\"test_node\",\"agent_ip\":\"test_ip\",\ - \"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"group_config_status\":\"not synced\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, - "Global query: update-agent-data {\"id\":1,\"os_name\":\"test_name\",\"os_version\":\"test_version\",\ - \"os_major\":\"test_major\",\"os_minor\":\"test_minor\",\"os_codename\":\"test_codename\",\"os_platform\":\"test_platform\",\ - \"os_build\":\"test_build\",\"os_uname\":\"test_uname\",\"os_arch\":\"test_arch\",\"version\":\"test_version\",\"config_sum\":\ - \"test_config\",\"merged_sum\":\"test_merged\",\"manager_host\":\"test_manager\",\"node_name\":\"test_node\",\"agent_ip\":\"test_ip\",\ - \"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"group_config_status\":\"not synced\"}"); - - expect_value(__wrap_wdb_global_update_agent_version, id, 1); - expect_string(__wrap_wdb_global_update_agent_version, os_name, "test_name"); - expect_string(__wrap_wdb_global_update_agent_version, os_version, "test_version"); - expect_string(__wrap_wdb_global_update_agent_version, os_major, "test_major"); - expect_string(__wrap_wdb_global_update_agent_version, os_minor, "test_minor"); - expect_string(__wrap_wdb_global_update_agent_version, os_codename, "test_codename"); - expect_string(__wrap_wdb_global_update_agent_version, os_platform, "test_platform"); - expect_string(__wrap_wdb_global_update_agent_version, os_build, "test_build"); - expect_string(__wrap_wdb_global_update_agent_version, os_uname, "test_uname"); - expect_string(__wrap_wdb_global_update_agent_version, os_arch, "test_arch"); - expect_string(__wrap_wdb_global_update_agent_version, version, "test_version"); - expect_string(__wrap_wdb_global_update_agent_version, config_sum, "test_config"); - expect_string(__wrap_wdb_global_update_agent_version, merged_sum, "test_merged"); - expect_string(__wrap_wdb_global_update_agent_version, manager_host, "test_manager"); - expect_string(__wrap_wdb_global_update_agent_version, node_name, "test_node"); - expect_string(__wrap_wdb_global_update_agent_version, agent_ip, "test_ip"); - expect_string(__wrap_wdb_global_update_agent_version, connection_status, "active"); - expect_string(__wrap_wdb_global_update_agent_version, sync_status, "syncreq"); - expect_string(__wrap_wdb_global_update_agent_version, group_config_status, "not synced"); - - will_return(__wrap_wdb_global_update_agent_version, OS_SUCCESS); - - expect_value(__wrap_wdb_global_del_agent_labels, id, 1); - will_return(__wrap_wdb_global_del_agent_labels, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_agent_data_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_get_agent_labels */ - -void test_wdb_parse_global_get_agent_labels_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-labels"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-labels"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for get-labels."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: get-labels"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_labels_get_labels); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'get-labels'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agent_labels_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-labels 1"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-labels 1"); - expect_value(__wrap_wdb_global_get_agent_labels, id, 1); - will_return(__wrap_wdb_global_get_agent_labels, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agent labels from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_labels_get_labels); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_labels_get_labels_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agent labels from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agent_labels_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-labels 1"; - cJSON *root = NULL; - cJSON *j_object = NULL; - - root = cJSON_CreateArray(); - j_object = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_object, "id", 1); - cJSON_AddStringToObject(j_object, "key", "test_key"); - cJSON_AddStringToObject(j_object, "value", "test_value"); - cJSON_AddItemToArray(root, j_object); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-labels 1"); - expect_value(__wrap_wdb_global_get_agent_labels, id, 1); - will_return(__wrap_wdb_global_get_agent_labels, root); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_labels_get_labels); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_labels_get_labels_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]"); - assert_int_equal(ret, OS_SUCCESS); - -} - -/* Tests wdb_parse_global_update_agent_keepalive */ - -void test_wdb_parse_global_update_agent_keepalive_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-keepalive"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-keepalive"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for update-keepalive."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: update-keepalive"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'update-keepalive'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_keepalive_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-keepalive {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-keepalive {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when updating agent keepalive."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_keepalive_invalid_data(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":null}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":null}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON data when updating agent keepalive."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, near '{\"id\":1,\"connection_status\":\"act'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_keepalive_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_value(__wrap_wdb_global_update_agent_keepalive, id, 1); - expect_string(__wrap_wdb_global_update_agent_keepalive, connection_status, "active"); - expect_string(__wrap_wdb_global_update_agent_keepalive, status, "syncreq"); - will_return(__wrap_wdb_global_update_agent_keepalive, OS_INVALID); - - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\"}"); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_agent_keepalive_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_value(__wrap_wdb_global_update_agent_keepalive, id, 1); - expect_string(__wrap_wdb_global_update_agent_keepalive, connection_status, "active"); - expect_string(__wrap_wdb_global_update_agent_keepalive, status, "syncreq"); - will_return(__wrap_wdb_global_update_agent_keepalive, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-keepalive {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\"}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_keepalive_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_update_connection_status */ - -void test_wdb_parse_global_update_connection_status_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-connection-status"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-connection-status"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for update-connection-status."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: update-connection-status"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'update-connection-status'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_connection_status_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-connection-status {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-connection-status {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when updating agent connection status."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_connection_status_invalid_data(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-connection-status {\"id\":1,\"connection_status\":null}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-connection-status {\"id\":1,\"connection_status\":null}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON data when updating agent connection status."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, near '{\"id\":1,\"connection_status\":null'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_connection_status_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"status_code\":0}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_value(__wrap_wdb_global_update_agent_connection_status, id, 1); - expect_string(__wrap_wdb_global_update_agent_connection_status, connection_status, "active"); - expect_string(__wrap_wdb_global_update_agent_connection_status, sync_status, "syncreq"); - expect_value(__wrap_wdb_global_update_agent_connection_status, status_code, 0); - will_return(__wrap_wdb_global_update_agent_connection_status, OS_INVALID); - - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"status_code\":0}"); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_connection_status_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"status_code\":0}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_value(__wrap_wdb_global_update_agent_connection_status, id, 1); - expect_string(__wrap_wdb_global_update_agent_connection_status, connection_status, "active"); - expect_string(__wrap_wdb_global_update_agent_connection_status, sync_status, "syncreq"); - expect_value(__wrap_wdb_global_update_agent_connection_status, status_code, 0); - will_return(__wrap_wdb_global_update_agent_connection_status, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-connection-status {\"id\":1,\"connection_status\":\"active\",\"sync_status\":\"syncreq\",\"status_code\":0}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_connection_status_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_update_status_code */ - -void test_wdb_parse_global_update_status_code_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-status-code"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-status-code"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for update-status-code."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: update-status-code"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_status_code); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'update-status-code'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_status_code_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-status-code {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-status-code {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when updating agent status code."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_status_code); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_status_code_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_status_code_invalid_data(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-status-code {\"id\":1,\"sync_status\":null}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-status-code {\"id\":1,\"sync_status\":null}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON data when updating agent status code."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_status_code); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_status_code_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, near '{\"id\":1,\"sync_status\":null}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_status_code_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-status-code {\"id\":1,\"status_code\":0,\"version\":\"v4.5.0\",\"sync_status\":\"syncreq\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_value(__wrap_wdb_global_update_agent_status_code, id, 1); - expect_value(__wrap_wdb_global_update_agent_status_code, status_code, 0); - expect_string(__wrap_wdb_global_update_agent_status_code, version, "v4.5.0"); - expect_string(__wrap_wdb_global_update_agent_status_code, sync_status, "syncreq"); - will_return(__wrap_wdb_global_update_agent_status_code, OS_INVALID); - - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-status-code {\"id\":1,\"status_code\":0,\"version\":\"v4.5.0\",\"sync_status\":\"syncreq\"}"); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_status_code); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_status_code_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_update_status_code_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global update-status-code {\"id\":1,\"status_code\":0,\"version\":\"v4.5.0\",\"sync_status\":\"syncreq\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_value(__wrap_wdb_global_update_agent_status_code, id, 1); - expect_value(__wrap_wdb_global_update_agent_status_code, status_code, 0); - expect_string(__wrap_wdb_global_update_agent_status_code, version, "v4.5.0"); - expect_string(__wrap_wdb_global_update_agent_status_code, sync_status, "syncreq"); - will_return(__wrap_wdb_global_update_agent_status_code, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Global query: update-status-code {\"id\":1,\"status_code\":0,\"version\":\"v4.5.0\",\"sync_status\":\"syncreq\"}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_update_status_code); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_update_status_code_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_delete_agent */ - -void test_wdb_parse_global_delete_agent_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global delete-agent"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: delete-agent"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for delete-agent."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: delete-agent"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_delete_agent); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'delete-agent'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_delete_agent_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global delete-agent 1"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: delete-agent 1"); - expect_value(__wrap_wdb_global_delete_agent, id, 1); - will_return(__wrap_wdb_global_delete_agent, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Error deleting agent from agent table in global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_delete_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_delete_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error deleting agent from agent table in global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_delete_agent_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global delete-agent 1"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: delete-agent 1"); - expect_value(__wrap_wdb_global_delete_agent, id, 1); - will_return(__wrap_wdb_global_delete_agent, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_delete_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_delete_agent_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_select_agent_name */ - -void test_wdb_parse_global_select_agent_name_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-agent-name"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-agent-name"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for select-agent-name."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: select-agent-name"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_select_agent_name); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'select-agent-name'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_select_agent_name_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-agent-name 1"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-agent-name 1"); - expect_value(__wrap_wdb_global_select_agent_name, id, 1); - will_return(__wrap_wdb_global_select_agent_name, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agent name from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_select_agent_name); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_select_agent_name_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agent name from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_select_agent_name_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-agent-name 1"; - cJSON *j_object = NULL; - - j_object = cJSON_CreateObject(); - cJSON_AddStringToObject(j_object, "name", "test_name"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-agent-name 1"); - expect_value(__wrap_wdb_global_select_agent_name, id, 1); - will_return(__wrap_wdb_global_select_agent_name, j_object); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_select_agent_name); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_select_agent_name_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"name\":\"test_name\"}"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_select_agent_group */ - -void test_wdb_parse_global_select_agent_group_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-agent-group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-agent-group"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for select-agent-group."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: select-agent-group"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_select_agent_group); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'select-agent-group'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_select_agent_group_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-agent-group 1"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-agent-group 1"); - expect_value(__wrap_wdb_global_select_agent_group, id, 1); - will_return(__wrap_wdb_global_select_agent_group, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agent group from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_select_agent_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_select_agent_group_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agent group from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_select_agent_group_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-agent-group 1"; - cJSON *j_object = NULL; - - j_object = cJSON_CreateObject(); - cJSON_AddStringToObject(j_object, "name", "test_name"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-agent-group 1"); - expect_value(__wrap_wdb_global_select_agent_group, id, 1); - will_return(__wrap_wdb_global_select_agent_group, j_object); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_select_agent_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_select_agent_group_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"name\":\"test_name\"}"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_find_agent */ - -void test_wdb_parse_global_find_agent_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-agent"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-agent"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for find-agent."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: find-agent"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_find_agent); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'find-agent'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_find_agent_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-agent {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-agent {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when finding agent id."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_find_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_find_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_find_agent_invalid_data(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-agent {\"ip\":null,\"name\":\"test_name\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-agent {\"ip\":null,\"name\":\"test_name\"}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON data when finding agent id."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_find_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_find_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, near '{\"ip\":null,\"name\":\"test_name\"}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_find_agent_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-agent {\"ip\":\"0.0.0.0\",\"name\":\"test_name\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-agent {\"ip\":\"0.0.0.0\",\"name\":\"test_name\"}"); - expect_string(__wrap_wdb_global_find_agent, ip, "0.0.0.0"); - expect_string(__wrap_wdb_global_find_agent, name, "test_name"); - will_return(__wrap_wdb_global_find_agent, NULL); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_find_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_find_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_find_agent_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-agent {\"ip\":\"0.0.0.0\",\"name\":\"test_name\"}"; - cJSON *j_object = NULL; - - j_object = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_object, "id", 1); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-agent {\"ip\":\"0.0.0.0\",\"name\":\"test_name\"}"); - expect_string(__wrap_wdb_global_find_agent, ip, "0.0.0.0"); - expect_string(__wrap_wdb_global_find_agent, name, "test_name"); - will_return(__wrap_wdb_global_find_agent, j_object); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_find_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_find_agent_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"id\":1}"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_find_group */ - -void test_wdb_parse_global_find_group_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-group"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for find-group."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: find-group"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_find_group); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'find-group'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_find_group_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-group test_group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-group test_group"); - expect_string(__wrap_wdb_global_find_group, group_name, "test_group"); - will_return(__wrap_wdb_global_find_group, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting group id from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_find_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_find_group_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting group id from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_find_group_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global find-group test_group"; - cJSON *j_object = NULL; - - j_object = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_object, "id", 1); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: find-group test_group"); - expect_string(__wrap_wdb_global_find_group, group_name, "test_group"); - will_return(__wrap_wdb_global_find_group, j_object); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_find_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_find_group_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"id\":1}"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_insert_agent_group */ - -void test_wdb_parse_global_insert_agent_group_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent-group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent-group"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for insert-agent-group."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: insert-agent-group"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_insert_agent_group); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'insert-agent-group'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_insert_agent_group_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent-group test_group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent-group test_group"); - expect_string(__wrap_wdb_global_insert_agent_group, group_name, "test_group"); - will_return(__wrap_wdb_global_insert_agent_group, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Error inserting group in global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_insert_agent_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_insert_agent_group_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error inserting group in global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_insert_agent_group_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global insert-agent-group test_group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: insert-agent-group test_group"); - expect_string(__wrap_wdb_global_insert_agent_group, group_name, "test_group"); - will_return(__wrap_wdb_global_insert_agent_group, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_insert_agent_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_insert_agent_group_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_select_group_belong */ - -void test_wdb_parse_global_select_group_belong_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-group-belong"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-group-belong"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for select-group-belong."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: select-group-belong"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_select_group_belong); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'select-group-belong'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_select_group_belong_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-group-belong 1"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-group-belong 1"); - expect_value(__wrap_wdb_global_select_group_belong, id_agent, 1); - will_return(__wrap_wdb_global_select_group_belong, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agent groups information from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_select_group_belong); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_belongs_select_group_belong_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agent groups information from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_select_group_belong_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-group-belong 1"; - cJSON *j_response = NULL; - - j_response = cJSON_Parse("[\"default\",\"new_group\"]"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-group-belong 1"); - expect_value(__wrap_wdb_global_select_group_belong, id_agent, 1); - will_return(__wrap_wdb_global_select_group_belong, j_response); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_select_group_belong); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_belongs_select_group_belong_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [\"default\",\"new_group\"]"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_get_group_agents */ - -void test_wdb_parse_global_get_group_agents_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-group-agents"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-group-agents"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for get-group-agents."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: get-group-agents"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'get-group-agents'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_group_agents_group_missing(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-group-agents "; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-group-agents "); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments, group name not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments, group name not found."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_group_agents_last_id_missing(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-group-agents group_name"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-group-agents group_name"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments, 'last_id' not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments, 'last_id' not found."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_group_agents_last_id_value_missing(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-group-agents group_name last_id"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-group-agents group_name last_id"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments, last agent id not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments, last agent id not found."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_group_agents_failed(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-group-agents group_name last_id 0"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-group-agents group_name last_id 0"); - - expect_string(__wrap_wdb_global_get_group_agents, group_name, "group_name"); - expect_value(__wrap_wdb_global_get_group_agents, last_agent_id, 0); - will_return(__wrap_wdb_global_get_group_agents, WDBC_ERROR); - will_return(__wrap_wdb_global_get_group_agents, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting group agents from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting group agents from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_group_agents_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-group-agents group_name last_id 0"; - cJSON *result = cJSON_Parse("[1,2,3]"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-group-agents group_name last_id 0"); - - expect_string(__wrap_wdb_global_get_group_agents, group_name, "group_name"); - expect_value(__wrap_wdb_global_get_group_agents, last_agent_id, 0); - will_return(__wrap_wdb_global_get_group_agents, WDBC_OK); - will_return(__wrap_wdb_global_get_group_agents, result); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_belongs_get_group_agent_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [1,2,3]"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_delete_group */ - -void test_wdb_parse_global_delete_group_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global delete-group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: delete-group"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for delete-group."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: delete-group"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_delete_group); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'delete-group'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_delete_group_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global delete-group test_group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: delete-group test_group"); - expect_string(__wrap_wdb_global_delete_group, group_name, "test_group"); - will_return(__wrap_wdb_global_delete_group, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Error deleting group in global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_delete_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_delete_group_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error deleting group in global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_delete_group_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global delete-group test_group"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: delete-group test_group"); - expect_string(__wrap_wdb_global_delete_group, group_name, "test_group"); - will_return(__wrap_wdb_global_delete_group, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_delete_group); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_delete_group_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_select_groups */ - -void test_wdb_parse_global_select_groups_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-groups"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-groups"); - will_return(__wrap_wdb_global_select_groups, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting groups from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_select_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_select_groups_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting groups from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_select_groups_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global select-groups"; - cJSON *j_object = NULL; - - j_object = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_object, "id", 1); - cJSON_AddNumberToObject(j_object, "id", 2); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: select-groups"); - will_return(__wrap_wdb_global_select_groups, j_object); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_group_select_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_group_select_groups_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"id\":1,\"id\":2}"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_sync_agent_info_get */ - -void test_wdb_parse_global_sync_agent_info_get_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-get"; - char *sync_info = "{SYNC INFO}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-get"); - expect_value(__wrap_wdb_global_sync_agent_info_get, *last_agent_id, 0); - will_return(__wrap_wdb_global_sync_agent_info_get, sync_info); - will_return(__wrap_wdb_global_sync_agent_info_get, WDBC_OK); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_get_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {SYNC INFO}"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_sync_agent_info_get_last_id_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-get last_id 1"; - char *sync_info = "{SYNC INFO}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-get last_id 1"); - expect_value(__wrap_wdb_global_sync_agent_info_get, *last_agent_id, 1); - will_return(__wrap_wdb_global_sync_agent_info_get, sync_info); - will_return(__wrap_wdb_global_sync_agent_info_get, WDBC_OK); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_get_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {SYNC INFO}"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_sync_agent_info_get_size_limit(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-get"; - char sync_info[WDB_MAX_RESPONSE_SIZE + 1] = {0}; - char content = 'A'; - for (size_t i = 0; i < WDB_MAX_RESPONSE_SIZE; i++) { - sync_info[i] = content; - content = content <= 'z' ? content+1 : 'A'; - } - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-get"); - expect_value(__wrap_wdb_global_sync_agent_info_get, *last_agent_id, 0); - will_return(__wrap_wdb_global_sync_agent_info_get, sync_info); - will_return(__wrap_wdb_global_sync_agent_info_get, WDBC_OK); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_get_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - char delims[] = " "; - char* payload = NULL; - char* status = NULL; - status = strtok_r(data->output, delims, &payload); - - assert_string_equal(status, "ok"); - assert_string_equal(payload, sync_info); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_sync_agent_info_set */ - -void test_wdb_parse_global_sync_agent_info_set_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-set"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-set"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for sync-agent-info-set."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: sync-agent-info-set"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'sync-agent-info-set'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_info_set_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-set {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-set {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax updating unsynced agents."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_info_set_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"); - expect_string(__wrap_wdb_global_sync_agent_info_set, str_agent, - "{\"id\":1,\"name\":\"test_name\",\"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}"); - will_return(__wrap_wdb_global_sync_agent_info_set, OS_INVALID); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_info_set_id_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-set [{\"id\":null,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-set [{\"id\":null,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"); - expect_string(__wrap_wdb_global_sync_agent_info_set, str_agent, - "{\"id\":null,\"name\":\"test_name\",\"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}"); - will_return(__wrap_wdb_global_sync_agent_info_set, OS_SUCCESS); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; incorrect agent id in labels array."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot update labels due to invalid id."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_info_set_del_label_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"); - expect_string(__wrap_wdb_global_sync_agent_info_set, str_agent, - "{\"id\":1,\"name\":\"test_name\",\"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}"); - will_return(__wrap_wdb_global_sync_agent_info_set, OS_SUCCESS); - - expect_value(__wrap_wdb_global_del_agent_labels, id, 1); - will_return(__wrap_wdb_global_del_agent_labels, OS_INVALID); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_info_set_set_label_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"); - expect_string(__wrap_wdb_global_sync_agent_info_set, str_agent, - "{\"id\":1,\"name\":\"test_name\",\"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}"); - will_return(__wrap_wdb_global_sync_agent_info_set, OS_SUCCESS); - expect_value(__wrap_wdb_global_del_agent_labels, id, 1); - will_return(__wrap_wdb_global_del_agent_labels, OS_SUCCESS); - - expect_value(__wrap_wdb_global_set_agent_label, id, 1); - expect_string(__wrap_wdb_global_set_agent_label, key, "test_key"); - expect_string(__wrap_wdb_global_set_agent_label, value, "test_value"); - will_return(__wrap_wdb_global_set_agent_label, OS_INVALID); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_info_set_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-info-set [{\"id\":1,\"name\":\"test_name\",\ - \"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}]"); - expect_string(__wrap_wdb_global_sync_agent_info_set, str_agent, - "{\"id\":1,\"name\":\"test_name\",\"labels\":[{\"id\":1,\"key\":\"test_key\",\"value\":\"test_value\"}]}"); - will_return(__wrap_wdb_global_sync_agent_info_set, OS_SUCCESS); - expect_value(__wrap_wdb_global_del_agent_labels, id, 1); - will_return(__wrap_wdb_global_del_agent_labels, OS_SUCCESS); - - expect_value(__wrap_wdb_global_set_agent_label, id, 1); - expect_string(__wrap_wdb_global_set_agent_label, key, "test_key"); - expect_string(__wrap_wdb_global_set_agent_label, value, "test_value"); - will_return(__wrap_wdb_global_set_agent_label, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_info_set_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_set_agent_groups */ - -void test_wdb_parse_global_set_agent_groups_syntax_error(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global set-agent-groups"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: set-agent-groups"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for set-agent-groups."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: set-agent-groups"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'set-agent-groups'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_set_agent_groups_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global set-agent-groups {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: set-agent-groups {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when parsing set_agent_groups"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_set_agent_groups_missing_field(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global set-agent-groups {\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: set-agent-groups {\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"); - expect_string(__wrap__mdebug1, formatted_msg, "Missing mandatory fields in set_agent_groups command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, missing required fields"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_set_agent_groups_invalid_mode(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global set-agent-groups {\"mode\":\"invalid_mode\",\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: set-agent-groups {\"mode\":\"invalid_mode\",\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid mode 'invalid_mode' in set_agent_groups command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid mode 'invalid_mode' in set_agent_groups command"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_set_agent_groups_fail(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global set-agent-groups {\"mode\":\"override\",\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: set-agent-groups {\"mode\":\"override\",\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"); - expect_value(__wrap_wdb_global_set_agent_groups, mode, WDB_GROUP_OVERRIDE); - expect_string(__wrap_wdb_global_set_agent_groups, sync_status, "synced"); - expect_string(__wrap_wdb_global_set_agent_groups, agents_group_info, "[{\"id\":1,\"groups\":[\"default\"]}]"); - will_return(__wrap_wdb_global_set_agent_groups, WDBC_ERROR); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err An error occurred during the set of the groups"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_set_agent_groups_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global set-agent-groups {\"mode\":\"append\",\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: set-agent-groups {\"mode\":\"append\",\"sync_status\":\"synced\",\"data\":[{\"id\":1,\"groups\":[\"default\"]}]}"); - expect_value(__wrap_wdb_global_set_agent_groups, mode, WDB_GROUP_APPEND); - expect_string(__wrap_wdb_global_set_agent_groups, sync_status, "synced"); - expect_string(__wrap_wdb_global_set_agent_groups, agents_group_info, "[{\"id\":1,\"groups\":[\"default\"]}]"); - will_return(__wrap_wdb_global_set_agent_groups, WDBC_OK); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_set_agent_groups_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_sync_agent_groups_get */ - -void test_wdb_parse_global_sync_agent_groups_get_syntax_error(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for sync-agent-groups-get."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: sync-agent-groups-get"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'sync-agent-groups-get'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_json(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {INVALID_JSON}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {INVALID_JSON}"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid JSON syntax when parsing sync-agent-groups-get"); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_without_condition_field_succes(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"get_global_hash\":true}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"get_global_hash\":true}"); - - cJSON *output = cJSON_CreateArray(); - cJSON *j_response = cJSON_CreateObject(); - cJSON *j_data = cJSON_CreateArray(); - cJSON_AddItemToArray(output, j_response); - cJSON_AddItemToObject(j_response, "data", j_data); - cJSON_AddStringToObject(j_response, "hash", "random_hash"); - - expect_value(__wrap_wdb_global_sync_agent_groups_get, condition, WDB_GROUP_NO_CONDITION); - expect_value(__wrap_wdb_global_sync_agent_groups_get, last_agent_id, 0); - expect_value(__wrap_wdb_global_sync_agent_groups_get, set_synced, false); - expect_value(__wrap_wdb_global_sync_agent_groups_get, get_hash, true); - expect_value(__wrap_wdb_global_sync_agent_groups_get, agent_registration_delta, 0); - will_return(__wrap_wdb_global_sync_agent_groups_get, output); - will_return(__wrap_wdb_global_sync_agent_groups_get, WDBC_OK); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"data\":[],\"hash\":\"random_hash\"}]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_last_id_data_type(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"sync_status\",\"last_id\":\"1_string\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"sync_status\",\"last_id\":\"1_string\"}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid alternative fields data in sync-agent-groups-get command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, invalid alternative fields data"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_last_id_negative(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"sync_status\",\"last_id\":-1}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"sync_status\",\"last_id\":-1}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid alternative fields data in sync-agent-groups-get command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, invalid alternative fields data"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_condition_data_type(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":10}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":10}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid alternative fields data in sync-agent-groups-get command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, invalid alternative fields data"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_set_synced_data_type(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"sync_status\",\"set_synced\":\"true_string\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"sync_status\",\"set_synced\":\"true_string\"}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid alternative fields data in sync-agent-groups-get command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, invalid alternative fields data"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_get_hash_data_type(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"sync_status\",\"get_global_hash\":\"true_string\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"sync_status\",\"get_global_hash\":\"true_string\"}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid alternative fields data in sync-agent-groups-get command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, invalid alternative fields data"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_agent_registration_delta_data_type(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"sync_status\",\"agent_registration_delta\":\"0_string\"}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"sync_status\",\"agent_registration_delta\":\"0_string\"}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid alternative fields data in sync-agent-groups-get command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, invalid alternative fields data"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_agent_registration_delta_negative(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"sync_status\",\"agent_registration_delta\":-1}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"sync_status\",\"agent_registration_delta\":-1}"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid alternative fields data in sync-agent-groups-get command."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON data, invalid alternative fields data"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_null_response(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"sync_status\",\"last_id\":3,\"set_synced\":true,\"get_global_hash\":true}"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"sync_status\",\"last_id\":3,\"set_synced\":true,\"get_global_hash\":true}"); - expect_value(__wrap_wdb_global_sync_agent_groups_get, condition, WDB_GROUP_SYNC_STATUS); - expect_value(__wrap_wdb_global_sync_agent_groups_get, last_agent_id, 3); - expect_value(__wrap_wdb_global_sync_agent_groups_get, set_synced, true); - expect_value(__wrap_wdb_global_sync_agent_groups_get, get_hash, true); - expect_value(__wrap_wdb_global_sync_agent_groups_get, agent_registration_delta, 0); - will_return(__wrap_wdb_global_sync_agent_groups_get, NULL); - will_return(__wrap_wdb_global_sync_agent_groups_get, WDBC_ERROR); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Could not obtain a response from wdb_global_sync_agent_groups_get"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_sync_agent_groups_get_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"all\",\"last_id\":3,\"set_synced\":true,\"get_global_hash\":true," - "\"agent_registration_delta\":10}"; - cJSON *output = cJSON_CreateArray(); - cJSON *j_response = cJSON_CreateObject(); - cJSON *j_data = cJSON_CreateArray(); - cJSON_AddItemToArray(output, j_response); - cJSON_AddItemToObject(j_response, "data", j_data); - cJSON_AddStringToObject(j_response, "hash", "random_hash"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"all\",\"last_id\":3,\"set_synced\":true," - "\"get_global_hash\":true,\"agent_registration_delta\":10}"); - expect_value(__wrap_wdb_global_sync_agent_groups_get, condition, WDB_GROUP_ALL); - expect_value(__wrap_wdb_global_sync_agent_groups_get, last_agent_id, 3); - expect_value(__wrap_wdb_global_sync_agent_groups_get, set_synced, true); - expect_value(__wrap_wdb_global_sync_agent_groups_get, get_hash, true); - expect_value(__wrap_wdb_global_sync_agent_groups_get, agent_registration_delta, 10); - will_return(__wrap_wdb_global_sync_agent_groups_get, output); - will_return(__wrap_wdb_global_sync_agent_groups_get, WDBC_OK); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"data\":[],\"hash\":\"random_hash\"}]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_sync_agent_groups_get_invalid_response(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global sync-agent-groups-get {\"condition\":\"all\",\"last_id\":3,\"set_synced\":true,\"get_global_hash\":true," - "\"agent_registration_delta\":15}"; - - cJSON *output = cJSON_CreateArray(); - cJSON *j_response = cJSON_CreateObject(); - cJSON *j_data = cJSON_CreateArray(); - cJSON_AddItemToArray(output, j_response); - cJSON_AddItemToObject(j_response, "data", j_data); - cJSON_AddStringToObject(j_response, "hash", "random_hash"); - - cJSON *j_data_object_1 = cJSON_CreateObject(); - cJSON *j_groups = cJSON_CreateArray(); - cJSON_AddNumberToObject(j_data_object_1, "id", 1); - cJSON_AddItemToObject(j_data_object_1, "groups", j_groups); - - for (int i = 0; i < MAX_GROUPS_PER_MULTIGROUP; ++i) { - char *group_name = group_name_generator(MAX_GROUP_NAME); - cJSON_AddItemToArray(j_groups, cJSON_CreateString(group_name)); - os_free(group_name); - } - - cJSON_AddItemToArray(j_data, j_data_object_1); - - cJSON *j_data_object_2 = cJSON_CreateObject(); - cJSON_AddNumberToObject(j_data_object_2, "id", 2); - cJSON_AddItemToObject(j_data_object_2, "groups", cJSON_Duplicate(j_groups, true)); - cJSON_AddItemToArray(j_data, j_data_object_2); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: sync-agent-groups-get {\"condition\":\"all\",\"last_id\":3,\"set_synced\":true," - "\"get_global_hash\":true,\"agent_registration_delta\":15}"); - expect_value(__wrap_wdb_global_sync_agent_groups_get, condition, WDB_GROUP_ALL); - expect_value(__wrap_wdb_global_sync_agent_groups_get, last_agent_id, 3); - expect_value(__wrap_wdb_global_sync_agent_groups_get, set_synced, true); - expect_value(__wrap_wdb_global_sync_agent_groups_get, get_hash, true); - expect_value(__wrap_wdb_global_sync_agent_groups_get, agent_registration_delta, 15); - will_return(__wrap_wdb_global_sync_agent_groups_get, output); - will_return(__wrap_wdb_global_sync_agent_groups_get, WDBC_OK); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_sync_agent_groups_get_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid response from wdb_global_sync_agent_groups_get"); - assert_int_equal(ret, OS_INVALID); -} - -/* Tests wdb_parse_global_get_groups_integrity */ - -void test_wdb_parse_global_get_groups_integrity_syntax_error(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-groups-integrity"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-groups-integrity"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for get-groups-integrity."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: get-groups-integrity"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'get-groups-integrity'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_groups_integrity_hash_length_expected_fail(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-groups-integrity small_hash"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-groups-integrity small_hash"); - // Expected hash should be OS_SHA1_HEXDIGEST_SIZE (40) characters long, and the received hash, "small_hash", is 10 characters long. - expect_string(__wrap__mdebug1, formatted_msg, "Hash hex-digest does not have the expected length. Expected (40) got (10)"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Hash hex-digest does not have the expected length. Expected (40) got (10)"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_groups_integrity_query_error(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - expect_string(__wrap_wdb_global_get_groups_integrity, hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - will_return(__wrap_wdb_global_get_groups_integrity, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting groups integrity information from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting groups integrity information from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_groups_integrity_success_syncreq(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; - cJSON* j_response = cJSON_Parse("[\"syncreq\"]"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - expect_string(__wrap_wdb_global_get_groups_integrity, hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - will_return(__wrap_wdb_global_get_groups_integrity, j_response); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [\"syncreq\"]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_get_groups_integrity_success_synced(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; - cJSON* j_response = cJSON_Parse("[\"synced\"]"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - expect_string(__wrap_wdb_global_get_groups_integrity, hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - will_return(__wrap_wdb_global_get_groups_integrity, j_response); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [\"synced\"]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_get_groups_integrity_success_hash_mismatch(void **state) -{ - int ret = OS_SUCCESS; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; - cJSON* j_response = cJSON_Parse("[\"hash_mismatch\"]"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-groups-integrity xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - expect_string(__wrap_wdb_global_get_groups_integrity, hash, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - will_return(__wrap_wdb_global_get_groups_integrity, j_response); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_groups_integrity_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [\"hash_mismatch\"]"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_disconnect_agents */ - -void test_wdb_parse_global_disconnect_agents_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global disconnect-agents"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: disconnect-agents"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for disconnect-agents."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: disconnect-agents"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'disconnect-agents'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_disconnect_agents_last_id_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global disconnect-agents "; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: disconnect-agents "); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments last id not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments last id not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_disconnect_agents_keepalive_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global disconnect-agents 0"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: disconnect-agents 0"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments keepalive not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments keepalive not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_disconnect_agents_sync_status_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global disconnect-agents 0 100"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: disconnect-agents 0 100"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments sync_status not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments sync_status not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_disconnect_agents_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global disconnect-agents 0 100 syncreq"; - cJSON* root = cJSON_CreateArray(); - cJSON* json_agent = cJSON_CreateObject(); - cJSON_AddItemToObject(json_agent, "id", cJSON_CreateNumber(10)); - cJSON_AddItemToArray(root, json_agent); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: disconnect-agents 0 100 syncreq"); - expect_value(__wrap_wdb_global_get_agents_to_disconnect, last_agent_id, 0); - expect_value(__wrap_wdb_global_get_agents_to_disconnect, keep_alive, 100); - expect_string(__wrap_wdb_global_get_agents_to_disconnect, sync_status, "syncreq"); - will_return(__wrap_wdb_global_get_agents_to_disconnect, WDBC_OK); - will_return(__wrap_wdb_global_get_agents_to_disconnect, root); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_disconnect_agents_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"id\":10}]"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_get_all_agents */ - -void test_wdb_parse_global_get_all_agents_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-all-agents"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-all-agents"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for get-all-agents."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: get-all-agents"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'get-all-agents'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_all_agents_argument_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-all-agents invalid"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-all-agents invalid"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments 'last_id' or 'context' not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments 'last_id' or 'context' not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_all_agents_argument2_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-all-agents last_id"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-all-agents last_id"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments 'last_id' not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments 'last_id' not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_all_agents_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-all-agents last_id 1"; - cJSON* root = cJSON_CreateArray(); - cJSON* json_agent = cJSON_CreateObject(); - cJSON_AddItemToObject(json_agent, "id", cJSON_CreateNumber(10)); - cJSON_AddItemToArray(root, json_agent); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-all-agents last_id 1"); - expect_value(__wrap_wdb_global_get_all_agents, last_agent_id, 1); - will_return(__wrap_wdb_global_get_all_agents, WDBC_OK); - will_return(__wrap_wdb_global_get_all_agents, root); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"id\":10}]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_get_all_agents_context_argument2_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-all-agents context"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-all-agents context"); - will_return(__wrap_wdb_global_get_all_agents_context, OS_INVALID); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agents from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_all_agents_context_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-all-agents context"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-all-agents context"); - will_return(__wrap_wdb_global_get_all_agents_context, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_all_agents_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok []"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_get_agent_info */ - -void test_wdb_parse_global_get_agent_info_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agent-info"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agent-info"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for get-agent-info."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: get-agent-info"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agent_info); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'get-agent-info'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agent_info_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agent-info 1"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agent-info 1"); - expect_value(__wrap_wdb_global_get_agent_info, id, 1); - will_return(__wrap_wdb_global_get_agent_info, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agent information from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agent_info); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agent_info_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agent information from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agent_info_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agent-info 1"; - cJSON *j_object = NULL; - - j_object = cJSON_CreateObject(); - cJSON_AddStringToObject(j_object, "name", "test_name"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agent-info 1"); - expect_value(__wrap_wdb_global_get_agent_info, id, 1); - will_return(__wrap_wdb_global_get_agent_info, j_object); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agent_info); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agent_info_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"name\":\"test_name\"}"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_reset_agents_connection */ - -void test_wdb_parse_reset_agents_connection_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global reset-agents-connection"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: reset-agents-connection"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for reset-agents-connection."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: reset-agents-connection"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_reset_agents_connection); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'reset-agents-connection'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_reset_agents_connection_query_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global reset-agents-connection syncreq"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: reset-agents-connection syncreq"); - expect_string(__wrap_wdb_global_reset_agents_connection, sync_status, "syncreq"); - will_return(__wrap_wdb_global_reset_agents_connection, OS_INVALID); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot execute SQL query; err database queue/db/global.db: ERROR MESSAGE"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_reset_agents_connection); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_reset_agents_connection_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute Global database query; ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_reset_agents_connection_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global reset-agents-connection syncreq"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: reset-agents-connection syncreq"); - expect_string(__wrap_wdb_global_reset_agents_connection, sync_status, "syncreq"); - will_return(__wrap_wdb_global_reset_agents_connection, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_reset_agents_connection); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_reset_agents_connection_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -/* Tests wdb_parse_global_get_agents_by_connection_status */ - -void test_wdb_parse_global_get_agents_by_connection_status_syntax_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agents-by-connection-status"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agents-by-connection-status"); - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for get-agents-by-connection-status."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: get-agents-by-connection-status"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'get-agents-by-connection-status'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agents_by_connection_status_status_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agents-by-connection-status 0 "; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agents-by-connection-status 0 "); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments 'connection_status' not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments 'connection_status' not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agents_by_connection_status_last_id_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agents-by-connection-status "; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agents-by-connection-status "); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments 'last_id' not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments 'last_id' not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agents_by_connection_status_limit_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agents-by-connection-status 0 active node01"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agents-by-connection-status 0 active node01"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid arguments 'limit' not found."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid arguments 'limit' not found"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_agents_by_connection_status_limit_succes(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agents-by-connection-status 0 active node01 -1"; - cJSON* root = cJSON_CreateArray(); - cJSON* json_agent = cJSON_CreateObject(); - cJSON_AddItemToObject(json_agent, "id", cJSON_CreateNumber(10)); - cJSON_AddItemToArray(root, json_agent); - - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agents-by-connection-status 0 active node01 -1"); - expect_value(__wrap_wdb_global_get_agents_by_connection_status, last_agent_id, 0); - expect_string(__wrap_wdb_global_get_agents_by_connection_status, connection_status, "active"); - expect_string(__wrap_wdb_global_get_agents_by_connection_status, node_name, "node01"); - expect_value(__wrap_wdb_global_get_agents_by_connection_status, limit, -1); - will_return(__wrap_wdb_global_get_agents_by_connection_status, WDBC_OK); - will_return(__wrap_wdb_global_get_agents_by_connection_status, root); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"id\":10}]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_get_agents_by_connection_status_query_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agents-by-connection-status 0 active"; - cJSON* root = cJSON_CreateArray(); - cJSON* json_agent = cJSON_CreateObject(); - cJSON_AddItemToObject(json_agent, "id", cJSON_CreateNumber(10)); - cJSON_AddItemToArray(root, json_agent); - - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agents-by-connection-status 0 active"); - expect_value(__wrap_wdb_global_get_agents_by_connection_status, last_agent_id, 0); - expect_string(__wrap_wdb_global_get_agents_by_connection_status, connection_status, "active"); - will_return(__wrap_wdb_global_get_agents_by_connection_status, WDBC_OK); - will_return(__wrap_wdb_global_get_agents_by_connection_status, root); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [{\"id\":10}]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_get_agents_by_connection_status_query_fail(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-agents-by-connection-status 0 active"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-agents-by-connection-status 0 active"); - expect_value(__wrap_wdb_global_get_agents_by_connection_status, last_agent_id, 0); - expect_string(__wrap_wdb_global_get_agents_by_connection_status, connection_status, "active"); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agents by connection status from global.db."); - will_return(__wrap_wdb_global_get_agents_by_connection_status, WDBC_UNKNOWN); - will_return(__wrap_wdb_global_get_agents_by_connection_status, NULL); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_agents_by_connection_status_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agents by connection status from global.db."); - assert_int_equal(ret, OS_INVALID); -} - - -/* wdb_parse_global_get_backup */ - -void test_wdb_parse_global_get_backup_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup get", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup get"); - - will_return(__wrap_wdb_global_get_backups, NULL); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_backup); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_backup_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot execute backup get command, unable to open 'backup/db' folder"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_get_backup_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - cJSON* j_backup = cJSON_Parse("[\"global.db-backup-TIMESTAMP\"]"); - - os_strdup("global backup get", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup get"); - - will_return(__wrap_wdb_global_get_backups, j_backup); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_backup); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_backup_time); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [\"global.db-backup-TIMESTAMP\"]"); - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -/* wdb_parse_global_restore_backup */ - -void test_wdb_parse_global_restore_backup_invalid_syntax(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup restore {INVALID_JSON}", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup restore {INVALID_JSON}"); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid backup JSON syntax when restoring snapshot."); - expect_string(__wrap__mdebug2, formatted_msg, "JSON error near: NVALID_JSON}"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_backup); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_backup_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid JSON syntax, near '{INVALID_JSON}'"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_restore_backup_success_missing_snapshot(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup restore", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup restore"); - - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_backup); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_backup_time); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -void test_wdb_parse_global_restore_backup_success_pre_restore_true(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup restore {\"snapshot\":\"global.db-backup-TIMESTAMP\",\"save_pre_restore_state\":true}", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup restore {\"snapshot\":\"global.db-backup-TIMESTAMP\",\"save_pre_restore_state\":true}"); - - expect_string(__wrap_wdb_global_restore_backup, snapshot, "global.db-backup-TIMESTAMP"); - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, true); - will_return(__wrap_wdb_global_restore_backup, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_backup); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_backup_time); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -void test_wdb_parse_global_restore_backup_success_pre_restore_false(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup restore {\"snapshot\":\"global.db-backup-TIMESTAMP\",\"save_pre_restore_state\":false}", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup restore {\"snapshot\":\"global.db-backup-TIMESTAMP\",\"save_pre_restore_state\":false}"); - - expect_string(__wrap_wdb_global_restore_backup, snapshot, "global.db-backup-TIMESTAMP"); - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_backup); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_backup_time); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -void test_wdb_parse_global_restore_backup_success_pre_restore_missing(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup restore {\"snapshot\":\"global.db-backup-TIMESTAMP\"}", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup restore {\"snapshot\":\"global.db-backup-TIMESTAMP\"}"); - - expect_string(__wrap_wdb_global_restore_backup, snapshot, "global.db-backup-TIMESTAMP"); - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_backup); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_backup_time); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -/* wdb_parse_global_vacuum */ - -void test_wdb_parse_global_vacuum_commit_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global vacuum", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_vacuum); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: vacuum"); - will_return(__wrap_wdb_commit2, OS_INVALID); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot end transaction."); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_vacuum_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot end transaction"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_vacuum_vacuum_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global vacuum", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_vacuum); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot vacuum database."); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_vacuum_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot vacuum database"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_vacuum_success_get_db_state_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global vacuum", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_vacuum); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_SUCCESS); - - will_return(__wrap_wdb_get_db_state, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Couldn't get fragmentation after vacuum for the database."); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_vacuum_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Vacuum performed, but couldn't get fragmentation information after vacuum"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_vacuum_success_update_vacuum_data_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global vacuum", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_vacuum); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_SUCCESS); - - will_return(__wrap_wdb_get_db_state, 10); - - expect_string(__wrap_wdb_update_last_vacuum_data, last_vacuum_value, "10"); - will_return(__wrap_wdb_update_last_vacuum_data, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Couldn't update last vacuum info for the database."); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_vacuum_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Vacuum performed, but last vacuum information couldn't be updated in the metadata table"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_vacuum_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global vacuum", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_vacuum); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_SUCCESS); - - will_return(__wrap_wdb_get_db_state, 10); - - expect_string(__wrap_wdb_update_last_vacuum_data, last_vacuum_value, "10"); - will_return(__wrap_wdb_update_last_vacuum_data, OS_SUCCESS); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_vacuum_time); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"fragmentation_after_vacuum\":10}"); - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -/* wdb_parse_global_get_fragmentation */ - -void test_wdb_parse_global_get_fragmentation_db_state_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global get_fragmentation", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_get_fragmentation); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get_fragmentation"); - - will_return(__wrap_wdb_get_db_state, OS_INVALID); - will_return(__wrap_wdb_get_db_free_pages_percentage, 10); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot get database fragmentation."); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_get_fragmentation_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot get database fragmentation"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_get_fragmentation_free_pages_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global get_fragmentation", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_get_fragmentation); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get_fragmentation"); - - will_return(__wrap_wdb_get_db_state, 10); - will_return(__wrap_wdb_get_db_free_pages_percentage, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Cannot get database fragmentation."); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_get_fragmentation_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot get database fragmentation"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_get_fragmentation_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global get_fragmentation", query); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_function_call(__wrap_w_inc_global_get_fragmentation); - will_return(__wrap_gettimeofday, NULL); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get_fragmentation"); - - will_return(__wrap_wdb_get_db_state, 50); - will_return(__wrap_wdb_get_db_free_pages_percentage, 10); - - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_get_fragmentation_time); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"fragmentation\":50,\"free_pages_percentage\":10}"); - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -/* Tests wdb_parse_global_get_distinct_agent_groups */ - -void test_wdb_parse_global_get_distinct_agent_groups_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-distinct-groups"; - cJSON *group_info = cJSON_Parse("[\"GROUP INFO\"]"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-distinct-groups"); - expect_value(__wrap_wdb_global_get_distinct_agent_groups, group_hash, NULL); - will_return(__wrap_wdb_global_get_distinct_agent_groups, WDBC_OK); - will_return(__wrap_wdb_global_get_distinct_agent_groups, group_info); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [\"GROUP INFO\"]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_get_distinct_agent_groups_success_with_last_hash(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-distinct-groups abcdef"; - cJSON *group_info = cJSON_Parse("[\"GROUP INFO\"]"); - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-distinct-groups abcdef"); - expect_string(__wrap_wdb_global_get_distinct_agent_groups, group_hash, "abcdef"); - will_return(__wrap_wdb_global_get_distinct_agent_groups, WDBC_OK); - will_return(__wrap_wdb_global_get_distinct_agent_groups, group_info); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok [\"GROUP INFO\"]"); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_parse_global_get_distinct_agent_groups_result_null(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-distinct-groups"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-distinct-groups"); - expect_value(__wrap_wdb_global_get_distinct_agent_groups, group_hash, NULL); - will_return(__wrap_wdb_global_get_distinct_agent_groups, WDBC_ERROR); - will_return(__wrap_wdb_global_get_distinct_agent_groups, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agent groups from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agent groups from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_get_distinct_agent_groups_result_null_with_last_hash(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global get-distinct-groups abcdef"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: get-distinct-groups abcdef"); - expect_string(__wrap_wdb_global_get_distinct_agent_groups, group_hash, "abcdef"); - will_return(__wrap_wdb_global_get_distinct_agent_groups, WDBC_ERROR); - will_return(__wrap_wdb_global_get_distinct_agent_groups, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "Error getting agent groups from global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_get_distinct_groups_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error getting agent groups from global.db."); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_delete_db_file (void **state) { - - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("global non-query", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: non-query"); - expect_string(__wrap__mdebug1, formatted_msg, "Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: non-query"); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - //DB file deleted manually - will_return(__wrap_w_is_file, 0); - - expect_string(__wrap__mwarn, formatted_msg, "DB(queue/db/global.db) not found. This behavior is unexpected, the database will be recreated."); - will_return(__wrap_wdb_close, NULL); - will_return(__wrap_wdb_close, OS_SUCCESS); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'non-query'"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -/* Tests wdb_parse_global_recalculate_agent_group_hashes */ - -void test_wdb_parse_global_recalculate_agent_group_hashes_error(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global recalculate-agent-group-hashes"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: recalculate-agent-group-hashes"); - will_return(__wrap_wdb_global_recalculate_all_agent_groups_hash, OS_INVALID); - expect_string(__wrap__mwarn, formatted_msg, "Error recalculating group hash of agents in global.db."); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_recalculate_agent_group_hashes); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_recalculate_agent_group_hashes_time); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Error recalculating group hash of agents in global.db"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_global_recalculate_agent_group_hashes_success(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "global recalculate-agent-group-hashes"; - - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: recalculate-agent-group-hashes"); - will_return(__wrap_wdb_global_recalculate_all_agent_groups_hash, OS_SUCCESS); - - expect_function_call(__wrap_w_inc_queries_total); - expect_function_call(__wrap_w_inc_global); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_open_time); - expect_function_call(__wrap_w_inc_global_agent_recalculate_agent_group_hashes); - will_return(__wrap_gettimeofday, NULL); - will_return(__wrap_gettimeofday, NULL); - expect_function_call(__wrap_w_inc_global_agent_recalculate_agent_group_hashes_time); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); -} - -int main() -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_wdb_parse_global_open_global_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_no_space, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_substr_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sql_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sql_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_actor_fail, test_setup, test_teardown), - /* Tests wdb_parse_global_insert_agent */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_compliant_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_success, test_setup, test_teardown), - /* Tests wdb_parse_global_update_agent_name */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_name_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_name_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_name_invalid_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_name_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_name_success, test_setup, test_teardown), - /* Tests wdb_parse_global_update_agent_data */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_data_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_data_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_data_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_data_invalid_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_data_success, test_setup, test_teardown), - /* Tests wdb_parse_global_get_agent_labels */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agent_labels_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agent_labels_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agent_labels_success, test_setup, test_teardown), - /* Tests wdb_parse_global_update_agent_keepalive */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_keepalive_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_keepalive_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_keepalive_invalid_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_keepalive_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_agent_keepalive_success, test_setup, test_teardown), - /* Tests wdb_parse_global_update_connection_status */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_connection_status_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_connection_status_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_connection_status_invalid_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_connection_status_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_connection_status_success, test_setup, test_teardown), - /* Tests wdb_parse_global_update_status_code */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_status_code_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_status_code_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_status_code_invalid_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_status_code_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_update_status_code_success, test_setup, test_teardown), - /* Tests wdb_parse_global_delete_agent */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_delete_agent_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_delete_agent_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_delete_agent_success, test_setup, test_teardown), - /* Tests wdb_parse_global_select_agent_name */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_agent_name_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_agent_name_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_agent_name_success, test_setup, test_teardown), - /* Tests wdb_parse_global_select_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_agent_group_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_agent_group_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_agent_group_success, test_setup, test_teardown), - /* Tests wdb_parse_global_find_agent */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_agent_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_agent_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_agent_invalid_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_agent_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_agent_success, test_setup, test_teardown), - /* Tests wdb_parse_global_find_group */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_group_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_group_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_find_group_success, test_setup, test_teardown), - /* Tests wdb_parse_global_insert_agent_group */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_group_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_group_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_insert_agent_group_success, test_setup, test_teardown), - /* Tests wdb_parse_global_select_group_belong */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_group_belong_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_group_belong_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_group_belong_success, test_setup, test_teardown), - /* Tests wdb_parse_global_get_group_agents */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_group_agents_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_group_agents_group_missing, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_group_agents_last_id_missing, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_group_agents_last_id_value_missing, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_group_agents_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_group_agents_success, test_setup, test_teardown), - /* Tests wdb_parse_global_delete_group */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_delete_group_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_delete_group_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_delete_group_success, test_setup, test_teardown), - /* Tests wdb_parse_global_select_groups */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_groups_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_select_groups_success, test_setup, test_teardown), - /* Tests wdb_parse_global_sync_agent_info_get */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_get_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_get_last_id_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_get_size_limit, test_setup, test_teardown), - /* Tests wdb_parse_global_sync_agent_info_set */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_set_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_set_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_set_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_set_id_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_set_del_label_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_set_set_label_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_info_set_success, test_setup, test_teardown), - /* Tests wdb_parse_global_set_agent_groups */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_set_agent_groups_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_set_agent_groups_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_set_agent_groups_missing_field, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_set_agent_groups_invalid_mode, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_set_agent_groups_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_set_agent_groups_success, test_setup, test_teardown), - /* Tests wdb_parse_global_sync_agent_groups_get */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_without_condition_field_succes, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_last_id_data_type, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_last_id_negative, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_condition_data_type, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_set_synced_data_type, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_get_hash_data_type, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_agent_registration_delta_data_type, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_agent_registration_delta_negative, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_null_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_sync_agent_groups_get_invalid_response, test_setup, test_teardown), - /* Tests wdb_parse_global_get_groups_integrity */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_groups_integrity_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_groups_integrity_hash_length_expected_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_groups_integrity_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_groups_integrity_success_syncreq, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_groups_integrity_success_synced, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_groups_integrity_success_hash_mismatch, test_setup, test_teardown), - /* Tests wdb_parse_global_disconnect_agents */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_disconnect_agents_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_disconnect_agents_last_id_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_disconnect_agents_keepalive_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_disconnect_agents_sync_status_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_disconnect_agents_success, test_setup, test_teardown), - /* Tests wdb_parse_global_get_all_agents */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_all_agents_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_all_agents_argument_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_all_agents_argument2_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_all_agents_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_all_agents_context_argument2_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_all_agents_context_success, test_setup, test_teardown), - /* Tests wdb_parse_global_get_agent_info */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agent_info_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agent_info_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agent_info_success, test_setup, test_teardown), - /* Tests wdb_parse_reset_agents_connection */ - cmocka_unit_test_setup_teardown(test_wdb_parse_reset_agents_connection_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_reset_agents_connection_query_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_reset_agents_connection_success, test_setup, test_teardown), - /* Tests wdb_parse_global_get_agent_info */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agents_by_connection_status_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agents_by_connection_status_status_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agents_by_connection_status_last_id_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agents_by_connection_status_limit_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agents_by_connection_status_limit_succes, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agents_by_connection_status_query_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_agents_by_connection_status_query_fail, test_setup, test_teardown), - /* Tests wdb_parse_global_get_backup */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_backup_failed, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_backup_success, test_setup, test_teardown), - /* Tests wdb_parse_global_restore_backup */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_restore_backup_invalid_syntax, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_restore_backup_success_missing_snapshot, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_restore_backup_success_pre_restore_true, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_restore_backup_success_pre_restore_false, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_restore_backup_success_pre_restore_missing, test_setup, test_teardown), - /* Tests wdb_parse_global_vacuum */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_vacuum_commit_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_vacuum_vacuum_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_vacuum_success_get_db_state_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_vacuum_success_update_vacuum_data_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_vacuum_success, test_setup, test_teardown), - /* Tests wdb_parse_global_get_fragmentation */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_fragmentation_db_state_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_fragmentation_free_pages_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_fragmentation_success, test_setup, test_teardown), - /* Tests wdb_parse_global_get_distinct_agent_groups */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_distinct_agent_groups_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_distinct_agent_groups_result_null, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_distinct_agent_groups_success_with_last_hash, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_distinct_agent_groups_result_null_with_last_hash, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_delete_db_file, test_setup, test_teardown), - /* Tests wdb_parse_global_recalculate_agent_group_hashes */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_recalculate_agent_group_hashes_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_recalculate_agent_group_hashes_success, test_setup, test_teardown), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_integrity.c b/src/unit_tests/wazuh_db/test_wdb_integrity.c deleted file mode 100644 index 90799a79c9d..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_integrity.c +++ /dev/null @@ -1,2049 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../headers/shared.h" -#include "../os_crypto/sha1/sha1_op.h" -#include "../external/sqlite/sqlite3.h" -#include "utils/flatbuffers/include/syscollector_deltas_schema.h" - -#include "../wrappers/externals/openssl/digest_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "cJSON.h" -#include "os_err.h" - -int wdb_calculate_stmt_checksum(wdb_t * wdb, sqlite3_stmt * stmt, wdb_component_t component, os_sha1 hexdigest, const char * pk_value); -extern os_sha1 global_group_hash; - -/* setup/teardown */ -static int setup_wdb_t(void **state) { - wdb_t *data = calloc(1, sizeof(wdb_t)); - - if(!data) { - return -1; - } - - //Initializing dummy statements pointers - for (int i = 0; i < WDB_STMT_SIZE; ++i) { - data->stmt[i] = (sqlite3_stmt *)1; - } - - test_mode = 1; - *state = data; - return 0; -} - -static int teardown_wdb_t(void **state) { - wdb_t *data = *state; - - if(data) { - os_free(data->id); - os_free(data); - } - - test_mode = 0; - return 0; -} - -/* tests */ - -// Tests wdb_calculate_stmt_checksum -static void test_wdb_calculate_stmt_checksum_wdb_null(void **state) { - expect_assert_failure(wdb_calculate_stmt_checksum(NULL, NULL, WDB_FIM, NULL, NULL)); -} - -static void test_wdb_calculate_stmt_checksum_stmt_null(void **state) { - wdb_t *data = *state; - - expect_assert_failure(wdb_calculate_stmt_checksum(data, NULL, WDB_FIM, NULL, NULL)); -} - -static void test_wdb_calculate_stmt_checksum_cks_null(void **state) { - wdb_t *data = *state; - sqlite3_stmt *stmt = (sqlite3_stmt *)1; - - expect_assert_failure(wdb_calculate_stmt_checksum(data, stmt, WDB_FIM, NULL, NULL)); -} - -static void test_wdb_calculate_stmt_checksum_no_row(void **state) { - int ret; - - wdb_t *data = *state; - sqlite3_stmt *stmt = (sqlite3_stmt *)1; - os_sha1 test_hex = ""; - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - - ret = wdb_calculate_stmt_checksum(data, stmt, WDB_FIM, test_hex, NULL); - - assert_int_equal(ret, 0); -} - -static void test_wdb_calculate_stmt_checksum_success(void **state) { - int ret; - - wdb_t *data = *state; - data->id = strdup("000"); - sqlite3_stmt *stmt = (sqlite3_stmt *)1; - os_sha1 test_hex = {5,5,0,8,6,'c','e','f',9,'c',8,7,'d',6,'d',0,3,1,'c','d',5,'d','b',2,9,'c','d',0,3,'a',2,'e','d',0,2,5,2,'b',4,5}; - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) has a NULL fim checksum."); - - ret = wdb_calculate_stmt_checksum(data, stmt, WDB_FIM, test_hex, NULL); - - assert_int_equal(ret, 1); -} - -static void test_wdb_calculate_stmt_checksum_duplicate_entries_found(void **state) { - int ret; - - wdb_t *data = *state; - data->id = strdup("001"); - sqlite3_stmt *stmt = (sqlite3_stmt *)1; - os_sha1 test_hex = {5,5,0,8,6,'c','e','f',9,'c',8,7,'d',6,'d',0,3,1,'c','d',5,'d','b',2,9,'c','d',0,3,'a',2,'e','d',0,2,5,2,'b',4,5}; - const char* pk_value = "test_pk_value"; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - // For loop - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "test_checksum"); - expect_string(__wrap_EVP_DigestUpdate, data, "test_checksum"); - expect_value(__wrap_EVP_DigestUpdate, count, 13); - will_return(__wrap_EVP_DigestUpdate, 0); - // Next iteration - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "test_checksum"); - expect_string(__wrap_EVP_DigestUpdate, data, "test_checksum"); - expect_value(__wrap_EVP_DigestUpdate, count, 13); - will_return(__wrap_EVP_DigestUpdate, 0); - // No more rows - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - - expect_string(__wrap__mwarn, formatted_msg, "DB(001) syscollector-packages component has more than one element with the same PK value 'test_pk_value'."); - - // wdbi_remove_by_pk - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, pk_value); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - ret = wdb_calculate_stmt_checksum(data, stmt, component, test_hex, pk_value); - - assert_int_equal(ret, 1); -} - -// Tests wdbi_checksum -static void test_wdbi_checksum_wdb_null(void **state) { - expect_assert_failure(wdbi_checksum(NULL, 0, "")); -} - -static void test_wdbi_checksum_hexdigest_null(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - - expect_assert_failure(wdbi_checksum(data, 0, NULL)); -} - -static void test_wdbi_checksum_stmt_cache_fail(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - os_sha1 test_hex = ""; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - ret = wdbi_checksum(data, 0, test_hex); - - assert_int_equal(ret, -1); -} - -static void test_wdbi_checksum_success(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - os_sha1 test_hex = {5,5,0,8,6,'c','e','f',9,'c',8,7,'d',6,'d',0,3,1,'c','d',5,'d','b',2,9,'c','d',0,3,'a',2,'e','d',0,2,5,2,'b',4,5}; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) has a NULL fim checksum."); - - ret = wdbi_checksum(data, 0, test_hex); - - assert_int_equal(ret, 1); -} - -// Tests wdbi_remove_by_pk -static void test_wdbi_remove_by_pk_wdb_null(void **state) { - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - const char* pk_value = NULL; - expect_assert_failure(wdbi_remove_by_pk(NULL, component, pk_value)); -} - -static void test_wdbi_remove_by_pk_null(void **state) { - wdb_t *data = *state; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - const char* pk_value = NULL; - - expect_string(__wrap__mwarn, formatted_msg, "PK value is NULL during the removal of the component 'syscollector-packages'"); - - wdbi_remove_by_pk(data, component, pk_value); -} - -static void test_wdbi_remove_by_pk_stmt_cache_fail(void **state) { - wdb_t *data = *state; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - const char* pk_value = "test_pk_value"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - wdbi_remove_by_pk(data, component, pk_value); -} - -static void test_wdbi_remove_by_pk_sqlite_bind_fail(void **state) { - wdb_t *data = *state; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - const char* pk_value = "test_pk_value"; - data->id = strdup("001"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, pk_value); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "DB(001) sqlite3_bind_text(): ERROR"); - - wdbi_remove_by_pk(data, component, pk_value); -} - -static void test_wdbi_remove_by_pk_sqlite_step_fail(void **state) { - wdb_t *data = *state; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - - const char* pk_value = "test_pk_value"; - data->id = strdup("001"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, pk_value); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(001) SQLite: ERROR"); - - wdbi_remove_by_pk(data, component, pk_value); -} - -static void test_wdbi_remove_by_pk_success(void **state) { - wdb_t *data = *state; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - - const char* pk_value = "test_pk_value"; - data->id = strdup("001"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_value(__wrap_sqlite3_bind_text, buffer, pk_value); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - wdbi_remove_by_pk(data, component, pk_value); -} - -// Tests wdbi_checksum_range -static void test_wdbi_checksum_range_wdb_null(void **state) { - expect_assert_failure(wdbi_checksum_range(NULL, 0, "test_begin", "test_end", "")); -} - -static void test_wdbi_checksum_range_hexdigest_null(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - - expect_assert_failure(wdbi_checksum_range(data, 0, "test_begin", "test_end", NULL)); -} - -static void test_wdbi_checksum_range_stmt_cache_fail(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - os_sha1 test_hex = ""; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - ret = wdbi_checksum_range(data, 0, "test_begin", "test_end", test_hex); - - assert_int_equal(ret, -1); -} - -static void test_wdbi_checksum_range_begin_null(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - - const char* begin = NULL; - const char* end = "test_end"; - os_sha1 test_hex = ""; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - - ret = wdbi_checksum_range(data, 0, begin, end, test_hex); - - assert_int_equal(ret, 0); -} - -static void test_wdbi_checksum_range_end_null(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - - const char* begin = "test_begin"; - const char* end = NULL; - os_sha1 test_hex = ""; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - - ret = wdbi_checksum_range(data, 0, begin, end, test_hex); - - assert_int_equal(ret, 0); -} - -static void test_wdbi_checksum_range_success(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - const char* begin = "test_begin"; - const char* end = "test_end"; - os_sha1 test_hex = {5,5,0,8,6,'c','e','f',9,'c',8,7,'d',6,'d',0,3,1,'c','d',5,'d','b',2,9,'c','d',0,3,'a',2,'e','d',0,2,5,2,'b',4,5}; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) has a NULL fim checksum."); - - ret = wdbi_checksum_range(data, 0, begin, end, test_hex); - - assert_int_equal(ret, 1); -} - -// Test wdbi_delete -static void test_wdbi_delete_wdb_null(void **state) { - expect_assert_failure(wdbi_delete(NULL, 0, "test_begin", "test_end","test_tail")); -} - -static void test_wdbi_delete_begin_null(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - const char* begin = NULL; - const char* end = "test_end"; - const char* tail = NULL; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_errmsg, "test_begin_null"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_begin_null"); - - ret = wdbi_delete(data, 0, begin, end, tail); - - assert_int_equal(ret, -1); -} - -static void test_wdbi_delete_end_null(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - const char* begin = "test_begin"; - const char* end = NULL; - const char* tail = "test_tail"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, tail); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_errmsg, "test_end_null"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_end_null"); - - ret = wdbi_delete(data, 0, begin, end, tail); - - assert_int_equal(ret, -1); -} - -static void test_wdbi_delete_tail_null(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - const char* begin = "test_begin"; - const char* end = "test_end"; - const char* tail = NULL; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_errmsg, "test_tail_null"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_tail_null"); - - ret = wdbi_delete(data, 0, begin, end, tail); - - assert_int_equal(ret, -1); -} - -static void test_wdbi_delete_stmt_cache_fail(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - ret = wdbi_delete(data, 0, "test_begin", "test_end","test_tail"); - - assert_int_equal(ret, -1); -} - -static void test_wdbi_delete_sql_no_done(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - const char* begin = "test_begin"; - const char* end = "test_end"; - const char* tail = "test_fail"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, tail); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_errmsg, "test_sql_no_done"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_sql_no_done"); - - ret = wdbi_delete(data, 0, begin, end, tail); - - assert_int_equal(ret, -1); -} - -static void test_wdbi_delete_success(void **state) { - int ret; - - wdb_t * data = *state; - data->id = strdup("000"); - const char* begin = "test_begin"; - const char* end = "test_end"; - const char* tail = "test_fail"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, tail); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - - ret = wdbi_delete(data, 0, begin, end, tail); - - assert_int_equal(ret, 0); -} - -// Test wdbi_update_attempt -static void test_wdbi_update_attempt_wdb_null(void **state) { - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - - expect_assert_failure(wdbi_update_attempt(NULL, 0, 1, agent_checksum, manager_checksum, FALSE)); -} - -static void test_wdbi_update_attempt_stmt_cache_fail(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - wdbi_update_attempt(data, 0, 0, agent_checksum, manager_checksum, FALSE); -} - -static void test_wdbi_update_attempt_no_sql_done(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - const char *component = "fim"; - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, agent_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, manager_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 1); - will_return(__wrap_sqlite3_errmsg, "test_no_sql_done"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_no_sql_done"); - - wdbi_update_attempt(data, WDB_FIM, 0, agent_checksum, manager_checksum, FALSE); -} - -static void test_wdbi_update_attempt_success(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - const char *component = "fim"; - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, agent_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, manager_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - - wdbi_update_attempt(data, WDB_FIM, 0, agent_checksum, manager_checksum, FALSE); -} - -// Test wdbi_update_completion -static void test_wdbi_update_completion_wdb_null(void **state) { - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - expect_assert_failure(wdbi_update_completion(NULL, 0, 0, agent_checksum, manager_checksum)); -} - -static void test_wdbi_update_completion_stmt_cache_fail(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - wdbi_update_completion(data, 0, 0, agent_checksum, manager_checksum); -} - -static void test_wdbi_update_completion_no_sql_done(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - const char *component = "fim"; - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 2); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, agent_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, manager_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 1); - will_return(__wrap_sqlite3_errmsg, "test_no_sql_done"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_no_sql_done"); - - wdbi_update_completion(data, WDB_FIM, 0, agent_checksum, manager_checksum); -} - -static void test_wdbi_update_completion_success(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - const char *component = "fim"; - os_sha1 agent_checksum = "ebccd0d055bfd85fecc7fe612f3ecfc14d679b1a"; - os_sha1 manager_checksum = "a1b976d41cfce3f216ef7ccef58dfb550d0dccbe"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 2); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, agent_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, manager_checksum); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - - wdbi_update_completion(data, WDB_FIM, 0, agent_checksum, manager_checksum); -} - -// Test wdbi_query_clear -void test_wdbi_query_clear_null_payload(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - char * payload = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000): cannot parse checksum range payload: '(null)'"); - - ret = wdbi_query_clear(data, WDB_FIM, payload); - - assert_int_equal(ret, -1); -} - -void test_wdbi_query_clear_invalid_payload(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - char payload[] = "This is some test"; - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000): cannot parse checksum range payload: 'This is some test'"); - - ret = wdbi_query_clear(data, WDB_FIM, payload); - - assert_int_equal(ret, -1); -} - -void test_wdbi_query_clear_no_id(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - char payload[] = "{\"Key\":\"Value\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "No such string 'id' in JSON payload."); - - ret = wdbi_query_clear(data, WDB_FIM, payload); - - assert_int_equal(ret, -1); -} - -void test_wdbi_query_clear_stmt_cache_error(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *payload = "{\"id\":5678}"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - ret = wdbi_query_clear(data, WDB_FIM, payload); - - assert_int_equal(ret, -1); -} - -void test_wdbi_query_clear_sql_step_error(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *payload = "{\"id\":5678}"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_errmsg, "test_error"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: test_error"); - - ret = wdbi_query_clear(data, WDB_FIM, payload); - - assert_int_equal(ret, -1); -} - -void test_wdbi_query_clear_ok(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *component = "fim"; - const char *payload = "{\"id\":5678}"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, 5678); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 2); - expect_value(__wrap_sqlite3_bind_int64, value, 5678); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - - ret = wdbi_query_clear(data, WDB_FIM, payload); - - assert_int_equal(ret, 0); -} - -// Test wdbi_query_checksum -void test_wdbi_query_checksum_null_payload(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - char * payload = NULL; - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000): cannot parse checksum range payload: '(null)'"); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_ERR); -} - -void test_wdbi_query_checksum_no_begin(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char * payload = "{\"Bad\":\"Payload\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "No such string 'begin' in JSON payload."); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_ERR); -} - -void test_wdbi_query_checksum_no_end(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char * payload = "{\"begin\":\"something\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "No such string 'end' in JSON payload."); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_ERR); -} - -void test_wdbi_query_checksum_no_checksum(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char * payload = "{\"begin\":\"something\",\"end\":\"something\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "No such string 'checksum' in JSON payload."); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_ERR); -} - -void test_wdbi_query_checksum_no_id(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"something\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "No such string 'id' in JSON payload."); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_ERR); -} - -void test_wdbi_query_checksum_range_fail(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"something\",\"id\":1234}"; - - // wdbi_get_last_manager_checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_ERR); -} - -void test_wdbi_query_checksum_range_no_data(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *begin = "something"; - const char *end = "something"; - const char *component = "fim"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"something\",\"id\":1234}"; - - // wdbi_get_last_manager_checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); //predelete - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); //pre attemps - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - - // wdbi_checksum_range - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - // wdbi_delete - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - // wdbi_update_attempt - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, 1234); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, ""); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_NO_DATA); -} - -void test_wdbi_query_checksum_diff_hexdigest(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *begin = "something"; - const char *end = "something"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"something\",\"id\":1234}"; - - // wdbi_get_last_manager_checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, NULL); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - // wdbi_checksum_range - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) has a NULL fim checksum."); - expect_any(__wrap__mdebug2, formatted_msg); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_CKS_FAIL); -} - -void test_wdbi_query_checksum_equal_hexdigest(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *begin = "something"; - const char *end = "something"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"id\":1234}"; - - // wdbi_get_last_manager_checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - expect_string(__wrap_EVP_DigestUpdate, data, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - expect_value(__wrap_EVP_DigestUpdate, count, 40); - will_return(__wrap_EVP_DigestUpdate, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - // wdbi_checksum_range - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_any(__wrap__mdebug2, formatted_msg); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_CKS_OK); -} - -void test_wdbi_query_checksum_bad_action(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *begin = "something"; - const char *end = "something"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"something\",\"id\":1234}"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, NULL); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - - // wdbi_checksum_range - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) has a NULL fim checksum."); - expect_any(__wrap__mdebug2, formatted_msg); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CLEAR, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_CKS_FAIL); -} - -void test_wdbi_query_checksum_check_left_no_tail(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *begin = "something"; - const char *end = "something"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"something\",\"id\":1234}"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "something"); - expect_string(__wrap_EVP_DigestUpdate, data, "something"); - expect_value(__wrap_EVP_DigestUpdate, count, 9); - will_return(__wrap_EVP_DigestUpdate, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - // wdbi_checksum_range - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_any(__wrap__mdebug2, formatted_msg); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_LEFT, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_CKS_FAIL); -} - -void test_wdbi_query_checksum_check_left_ok(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - - const char *begin = "something"; - const char *end = "something"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"something\",\"id\":1234,\"tail\":\"something\"}"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "something"); - expect_string(__wrap_EVP_DigestUpdate, data, "something"); - expect_value(__wrap_EVP_DigestUpdate, count, 9); - will_return(__wrap_EVP_DigestUpdate, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - // wdbi_checksum_range - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_any(__wrap__mdebug2, formatted_msg); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_LEFT, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_CKS_FAIL); -} - -void test_wdbi_query_checksum_last_manager_success(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *component = "fim"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"id\":1234}"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - cJSON_AddStringToObject(j_object, "last_manager_checksum", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - cJSON_AddItemToArray(j_data, j_object); - - // wdbi_get_last_manager_checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_string(__wrap__mdebug2, formatted_msg, "Agent '000' fim range checksum avoided."); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_CKS_OK); -} - -void test_wdbi_query_checksum_last_manager_diff(void **state) { - wdb_t *data = *state; - int ret; - os_strdup("000", data->id); - const char *component = "fim"; - const char *begin = "something"; - const char *end = "something"; - const char * payload = "{\"begin\":\"something\",\"end\":\"something\",\"checksum\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"id\":1234}"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - cJSON_AddStringToObject(j_object, "last_manager_checksum", ""); - cJSON_AddItemToArray(j_data, j_object); - - // wdbi_get_last_manager_checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - // wdbi_checksum_range - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, begin); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, end); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 100); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - expect_string(__wrap_EVP_DigestUpdate, data, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - expect_value(__wrap_EVP_DigestUpdate, count, 40); - will_return(__wrap_EVP_DigestUpdate, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 101); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug2, formatted_msg); - - ret = wdbi_query_checksum(data, WDB_FIM, INTEGRITY_CHECK_GLOBAL, payload); - - assert_int_equal(ret, INTEGRITY_SYNC_CKS_OK); -} - -// Test wdbi_get_last_manager_checksum -void test_wdbi_get_last_manager_checksum_success(void **state) { - wdb_t *data = *state; - const char *component = "fim_file"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - - cJSON_AddStringToObject(j_object, "last_manager_checksum", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - cJSON_AddItemToArray(j_data, j_object); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - os_sha1 manager_checksum = {0}; - int ret_val = wdbi_get_last_manager_checksum(data, WDB_FIM_FILE, manager_checksum); - - assert_int_equal (ret_val, OS_SUCCESS); - assert_string_equal(manager_checksum, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); -} - -void test_wdbi_get_last_manager_stmt_cache_fail(void **state) { - wdb_t *data = *state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - os_sha1 manager_checksum = {0}; - int ret_val = wdbi_get_last_manager_checksum(data, WDB_FIM_FILE, manager_checksum); - - assert_int_equal (ret_val, OS_INVALID); -} - -void test_wdbi_get_last_manager_exec_stmt_fail(void **state) { - wdb_t *data = *state; - const char *component = "fim_file"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "test_err"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): test_err"); - - os_sha1 manager_checksum = {0}; - int ret_val = wdbi_get_last_manager_checksum(data, WDB_FIM_FILE, manager_checksum); - - assert_int_equal (ret_val, OS_INVALID); -} - -// Test wdbi_array_hash -void test_wdbi_array_hash_success(void **state) { - const char** test_words = NULL; - int ret_val = -1; - os_sha1 hexdigest; - - os_malloc(6 * sizeof(char*),test_words); - - test_words[0] = "FirstWord"; - test_words[1] = "SecondWord"; - test_words[2] = "Word number 3"; - test_words[3] = ""; - test_words[4] = " "; - test_words[5]= NULL; - - // Using real EVP_DigestUpdate - test_mode = 0; - - ret_val = wdbi_array_hash(test_words, hexdigest); - - assert_int_equal (ret_val, 0); - assert_string_equal(hexdigest, "159a9a6e19ff891a8560376df65a078e064bd0ce"); - - os_free(test_words); -} - -void test_wdbi_array_hash_null(void **state) { - int ret_val = -1; - os_sha1 hexdigest; - - // Using real EVP_DigestUpdate - test_mode = 0; - - ret_val = wdbi_array_hash(NULL, hexdigest); - - assert_int_equal (ret_val, 0); - assert_string_equal(hexdigest, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); -} - -// Test wdbi_strings_hash -void test_wdbi_strings_hash_success(void **state) { - int ret_val = -1; - os_sha1 hexdigest; - - // Using real EVP_DigestUpdate - test_mode = 0; - - ret_val = wdbi_strings_hash(hexdigest, "FirstWord", "SecondWord", "Word number 3", "", " ", NULL); - - assert_int_equal (ret_val, 0); - assert_string_equal(hexdigest, "159a9a6e19ff891a8560376df65a078e064bd0ce"); -} - -void test_wdbi_strings_hash_null(void **state) { - int ret_val = -1; - os_sha1 hexdigest; - - // Using real EVP_DigestUpdate - test_mode = 0; - - ret_val = wdbi_strings_hash(hexdigest, NULL); - - assert_int_equal (ret_val, 0); - assert_string_equal(hexdigest, "da39a3ee5e6b4b0d3255bfef95601890afd80709"); -} - -// Test wdbi_check_sync_status -void test_wdbi_check_sync_status_cache_failed(void **state) { - int ret_val = OS_INVALID; - wdb_t * data = *state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - - assert_int_equal (ret_val, OS_INVALID); -} - -void test_wdbi_check_sync_status_exec_failed(void **state) { - int ret_val = OS_INVALID; - wdb_t * data = *state; - const char *component = "syscollector-packages"; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_exec_stmt, NULL); - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "wdb_exec_stmt(): ERROR_MESSAGE"); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - assert_int_equal (ret_val, OS_INVALID); -} - -void test_wdbi_check_sync_status_data_failed(void **state) { - int ret_val = OS_INVALID; - wdb_t * data = *state; - const char *component = "syscollector-packages"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "last_attempt", 123456); - cJSON_AddItemToArray(j_data, j_object); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "Failed to get agent's sync status data"); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - - assert_int_equal (ret_val, OS_INVALID); -} - -void test_wdbi_check_sync_status_data_synced(void **state) { - int ret_val = OS_INVALID; - wdb_t * data = *state; - const char *component = "syscollector-packages"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "last_attempt", 123456); - cJSON_AddNumberToObject(j_object, "last_completion", 123456); - cJSON_AddStringToObject(j_object, "last_agent_checksum", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - cJSON_AddItemToArray(j_data, j_object); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - - assert_int_equal (ret_val, 1); -} - -void test_wdbi_check_sync_status_data_never_synced_without_checksum(void **state) { - int ret_val = OS_INVALID; - wdb_t * data = *state; - const char *component = "syscollector-packages"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "last_attempt", 123456); - cJSON_AddNumberToObject(j_object, "last_completion", 0); - cJSON_AddStringToObject(j_object, "last_agent_checksum", ""); - cJSON_AddItemToArray(j_data, j_object); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - - assert_int_equal (ret_val, 0); -} - -void test_wdbi_check_sync_status_data_not_synced_error_checksum(void **state) { - int ret_val = OS_INVALID; - wdb_t * data = *state; - const char *component = "syscollector-packages"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "last_attempt", 123456); - cJSON_AddNumberToObject(j_object, "last_completion", 123455); - cJSON_AddStringToObject(j_object, "last_agent_checksum", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - cJSON_AddItemToArray(j_data, j_object); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - // Error calling to calculate checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot cache statement"); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - - assert_int_equal (ret_val, -1); -} - -void test_wdbi_check_sync_status_data_not_synced_checksum_no_data(void **state) { - int ret_val = -1; - wdb_t * data = *state; - data->id = strdup("000"); - const char *component = "syscollector-packages"; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "last_attempt", 123456); - cJSON_AddNumberToObject(j_object, "last_completion", 123455); - cJSON_AddStringToObject(j_object, "last_agent_checksum", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - cJSON_AddItemToArray(j_data, j_object); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - // Calling to calculate checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - - assert_int_equal (ret_val, 0); -} - -void test_wdbi_check_sync_status_data_not_synced_checksum_valid(void **state) { - int ret_val = -1; - wdb_t * data = *state; - data->id = strdup("000"); - const char *component = "syscollector-packages"; - unsigned int timestamp = 10000; - cJSON* j_data = cJSON_CreateArray(); - cJSON* j_object = cJSON_CreateObject(); - - cJSON_AddNumberToObject(j_object, "last_attempt", 123456); - cJSON_AddNumberToObject(j_object, "last_completion", 123455); - cJSON_AddStringToObject(j_object, "last_agent_checksum", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); - cJSON_AddItemToArray(j_data, j_object); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_exec_stmt, j_data); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, component); - will_return(__wrap_sqlite3_bind_text, 0); - - // Calling to calculate checksum - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, 0); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "da39a3ee5eda39a3ee5eda39a3ee5eda39a3ee5e"); - expect_string(__wrap_EVP_DigestUpdate, data, "da39a3ee5eda39a3ee5eda39a3ee5eda39a3ee5e"); - expect_value(__wrap_EVP_DigestUpdate, count, 40); - will_return(__wrap_EVP_DigestUpdate, 0); - - will_return(__wrap_time, timestamp); - - // wdbi_set_last_completion - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, timestamp); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "syscollector-packages"); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - ret_val = wdbi_check_sync_status(data, WDB_SYSCOLLECTOR_PACKAGES); - - assert_int_equal (ret_val, 1); -} - -// Test wdbi_last_completion -void test_wdbi_last_completion_step_fail(void **state) { - wdb_t * data = *state; - data->id = strdup("000"); - unsigned int timestamp = 10000; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 1); - expect_value(__wrap_sqlite3_bind_int64, value, timestamp); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "syscollector-packages"); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: ERROR_MESSAGE"); - - wdbi_set_last_completion(data, WDB_SYSCOLLECTOR_PACKAGES, timestamp); -} - -// Test wdb_global_group_hash_cache - -void test_wdb_global_group_hash_cache_clear_success(void **state) -{ - wdb_global_group_hash_operations_t operation = WDB_GLOBAL_GROUP_HASH_CLEAR; - os_sha1 hexdigest; - int ret; - - /* Storing a dummy hash value before clearing it */ - snprintf(global_group_hash, sizeof(global_group_hash), "bd612e9ae2faf8a44b387eeb9f3d5a5e577c8c64"); - - ret = wdb_global_group_hash_cache(operation, hexdigest); - - assert_int_equal(global_group_hash[0], 0); - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_global_group_hash_cache_read_fail(void **state) -{ - wdb_global_group_hash_operations_t operation = WDB_GLOBAL_GROUP_HASH_READ; - os_sha1 hexdigest; - int ret; - - /* Clearing the variable before reading it */ - global_group_hash[0] = 0; - - ret = wdb_global_group_hash_cache(operation, hexdigest); - - assert_int_equal(global_group_hash[0], 0); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_global_group_hash_cache_write_success(void **state) -{ - wdb_global_group_hash_operations_t operation = WDB_GLOBAL_GROUP_HASH_WRITE; - os_sha1 hexdigest = "bd612e9ae2faf8a44b387eeb9f3d5a5e577c8c64"; - int ret; - - ret = wdb_global_group_hash_cache(operation, hexdigest); - - assert_string_equal(global_group_hash, hexdigest); - assert_int_equal(ret, OS_SUCCESS); - - /* Clearing the variable after writing it */ - global_group_hash[0] = 0; -} - -void test_wdb_global_group_hash_cache_read_success(void **state) -{ - wdb_global_group_hash_operations_t operation = WDB_GLOBAL_GROUP_HASH_READ; - os_sha1 hexdigest; - int ret; - - /* Storing a dummy hash value before reading it */ - snprintf(global_group_hash, sizeof(global_group_hash), "bd612e9ae2faf8a44b387eeb9f3d5a5e577c8c64"); - - ret = wdb_global_group_hash_cache(operation, hexdigest); - - assert_string_equal(hexdigest, "bd612e9ae2faf8a44b387eeb9f3d5a5e577c8c64"); - assert_int_equal(ret, OS_SUCCESS); - - /* Clearing the variable after reading it */ - global_group_hash[0] = 0; -} - -void test_wdb_global_group_hash_cache_invalid_mode(void **state) -{ - wdb_global_group_hash_operations_t operation = 3; - os_sha1 hexdigest; - int ret; - - expect_string(__wrap__mdebug2, formatted_msg, "Invalid mode for global group hash operation."); - - ret = wdb_global_group_hash_cache(operation, hexdigest); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_get_global_group_hash - -void wdb_get_global_group_hash_read_success(void **state) -{ - wdb_t * data = *state; - os_sha1 hexdigest; - int ret; - - /* Storing a dummy hash value before reading it */ - snprintf(global_group_hash, sizeof(global_group_hash), "bd612e9ae2faf8a44b387eeb9f3d5a5e577c8c64"); - - expect_string(__wrap__mdebug2, formatted_msg, "Using global group hash from cache"); - - ret = wdb_get_global_group_hash(data, hexdigest); - - assert_int_equal(ret, OS_SUCCESS); - - /* Clearing the variable after reading it */ - global_group_hash[0] = 0; -} - -void wdb_get_global_group_hash_invalid_db_structure(void **state) -{ - os_sha1 hexdigest; - int ret; - - /* Clearing the variable before reading it */ - global_group_hash[0] = 0; - - expect_string(__wrap__mdebug1, formatted_msg, "Database structure not initialized. Unable to calculate global group hash."); - - ret = wdb_get_global_group_hash(NULL, hexdigest); - - assert_int_equal(ret, OS_INVALID); -} - -void wdb_get_global_group_hash_invalid_statement(void **state) -{ - wdb_t * data = *state; - os_sha1 hexdigest; - int ret; - - /* Clearing the variable before reading it */ - global_group_hash[0] = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_HASH_GET); - will_return(__wrap_wdb_init_stmt_in_cache, NULL); - - ret = wdb_get_global_group_hash(data, hexdigest); - - assert_int_equal(ret, OS_INVALID); -} - -void wdb_get_global_group_hash_calculate_success_no_group_hash_information(void **state) -{ - wdb_t * data = *state; - os_sha1 hexdigest; - int ret; - - /* Clearing the variable before reading it */ - global_group_hash[0] = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_HASH_GET); - will_return(__wrap_wdb_init_stmt_in_cache, 1); - - will_return(__wrap_sqlite3_step, SQLITE_OK); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - expect_string(__wrap__mdebug2, formatted_msg, "No group hash was found to calculate the global group hash."); - - ret = wdb_get_global_group_hash(data, hexdigest); - - assert_int_equal(ret, OS_SUCCESS); -} - -void wdb_get_global_group_hash_calculate_success(void **state) -{ - wdb_t * data = *state; - data->id = strdup("000"); - os_sha1 hexdigest; - int ret; - - /* Clearing the variable before reading it */ - global_group_hash[0] = 0; - - expect_value(__wrap_wdb_init_stmt_in_cache, statement_index, WDB_STMT_GLOBAL_GROUP_HASH_GET); - will_return(__wrap_wdb_init_stmt_in_cache, 1); - - will_return(__wrap_sqlite3_step, SQLITE_OK); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - will_return(__wrap_sqlite3_step, SQLITE_OK); - will_return(__wrap_sqlite3_step, SQLITE_OK); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, NULL); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) has a NULL checksum."); - expect_string(__wrap__mdebug2, formatted_msg, "New global group hash calculated and stored in cache."); - - ret = wdb_get_global_group_hash(data, hexdigest); - - assert_int_equal(ret, OS_SUCCESS); -} - -// Tests wdbi_report_removed - -void test_wdbi_report_removed_no_handle(void **state) { - const char* agent_id = "001"; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - sqlite3_stmt* stmt = NULL; - router_agent_events_handle = NULL; - - expect_string(__wrap__mdebug2, formatted_msg, "Router handle not available."); - - wdbi_report_removed(agent_id, component, stmt); -} - -void test_wdbi_report_removed_packages_success(void **state) { - const char* agent_id = "001"; - wdb_component_t component = WDB_SYSCOLLECTOR_PACKAGES; - sqlite3_stmt* stmt = NULL; - router_agent_events_handle = (ROUTER_PROVIDER_HANDLE)1; - const char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\"},\"action\":\"deletePackage\"," - "\"data\":{\"name\":\"name\",\"version\":\"version\",\"architecture\":\"architecture\",\"format\":\"format\",\"location\":\"location\",\"item_id\":\"item_id\"}}"; - - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "name"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "version"); - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "architecture"); - expect_value(__wrap_sqlite3_column_text, iCol, 3); - will_return(__wrap_sqlite3_column_text, "format"); - expect_value(__wrap_sqlite3_column_text, iCol, 4); - will_return(__wrap_sqlite3_column_text, "location"); - expect_value(__wrap_sqlite3_column_text, iCol, 5); - will_return(__wrap_sqlite3_column_text, "item_id"); - - expect_string(__wrap_router_provider_send, message, expected_message); - expect_value(__wrap_router_provider_send, message_size, strlen(expected_message)); - will_return(__wrap_router_provider_send, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - wdbi_report_removed(agent_id, component, stmt); -} - -void test_wdbi_report_removed_hotfixes_success(void **state) { - const char* agent_id = "001"; - wdb_component_t component = WDB_SYSCOLLECTOR_HOTFIXES; - sqlite3_stmt* stmt = NULL; - router_agent_events_handle = (ROUTER_PROVIDER_HANDLE)1; - const char* expected_message = "{\"agent_info\":{\"agent_id\":\"001\"},\"action\":\"deleteHotfix\"," - "\"data\":{\"hotfix\":\"hotfix\"}}"; - - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "hotfix"); - - expect_string(__wrap_router_provider_send, message, expected_message); - expect_value(__wrap_router_provider_send, message_size, strlen(expected_message)); - will_return(__wrap_router_provider_send, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - wdbi_report_removed(agent_id, component, stmt); -} - -void test_wdbi_report_removed_hotfixes_success_multiple_steps(void **state) { - const char* agent_id = "001"; - wdb_component_t component = WDB_SYSCOLLECTOR_HOTFIXES; - sqlite3_stmt* stmt = NULL; - router_agent_events_handle = (ROUTER_PROVIDER_HANDLE)1; - const char* expected_message_1 = "{\"agent_info\":{\"agent_id\":\"001\"},\"action\":\"deleteHotfix\"," - "\"data\":{\"hotfix\":\"hotfix1\"}}"; - - const char* expected_message_2 = "{\"agent_info\":{\"agent_id\":\"001\"},\"action\":\"deleteHotfix\"," - "\"data\":{\"hotfix\":\"hotfix2\"}}"; - - // First hotfix - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "hotfix1"); - - expect_string(__wrap_router_provider_send, message, expected_message_1); - expect_value(__wrap_router_provider_send, message_size, strlen(expected_message_1)); - will_return(__wrap_router_provider_send, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - - // Second hotfix - - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "hotfix2"); - - expect_string(__wrap_router_provider_send, message, expected_message_2); - expect_value(__wrap_router_provider_send, message_size, strlen(expected_message_2)); - will_return(__wrap_router_provider_send, 0); - - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_DONE); - - wdbi_report_removed(agent_id, component, stmt); -} - -int main(void) { - const struct CMUnitTest tests[] = { - //Test wdb_calculate_stmt_checksum - cmocka_unit_test(test_wdb_calculate_stmt_checksum_wdb_null), - cmocka_unit_test_setup_teardown(test_wdb_calculate_stmt_checksum_stmt_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdb_calculate_stmt_checksum_cks_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdb_calculate_stmt_checksum_no_row, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdb_calculate_stmt_checksum_success, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdb_calculate_stmt_checksum_duplicate_entries_found, setup_wdb_t, teardown_wdb_t), - //Test wdbi_checksum_range - cmocka_unit_test(test_wdbi_checksum_wdb_null), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_hexdigest_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_stmt_cache_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_success, setup_wdb_t, teardown_wdb_t), - // wdbi_remove_by_pk - cmocka_unit_test(test_wdbi_remove_by_pk_wdb_null), - cmocka_unit_test_setup_teardown(test_wdbi_remove_by_pk_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_remove_by_pk_stmt_cache_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_remove_by_pk_sqlite_bind_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_remove_by_pk_sqlite_step_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_remove_by_pk_success, setup_wdb_t, teardown_wdb_t), - //Test wdbi_checksum_range - cmocka_unit_test(test_wdbi_checksum_range_wdb_null), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_range_hexdigest_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_range_stmt_cache_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_range_begin_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_range_end_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_checksum_range_success, setup_wdb_t, teardown_wdb_t), - //Test wdbi_delete - cmocka_unit_test(test_wdbi_delete_wdb_null), - cmocka_unit_test_setup_teardown(test_wdbi_delete_begin_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_delete_end_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_delete_tail_null, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_delete_stmt_cache_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_delete_sql_no_done, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_delete_success, setup_wdb_t, teardown_wdb_t), - //Test wdbi_update_attempt - cmocka_unit_test(test_wdbi_update_attempt_wdb_null), - cmocka_unit_test_setup_teardown(test_wdbi_update_attempt_stmt_cache_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_update_attempt_no_sql_done, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_update_attempt_success, setup_wdb_t, teardown_wdb_t), - //Test wdbi_update_completion - cmocka_unit_test(test_wdbi_update_completion_wdb_null), - cmocka_unit_test_setup_teardown(test_wdbi_update_completion_stmt_cache_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_update_completion_no_sql_done, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_update_completion_success, setup_wdb_t, teardown_wdb_t), - //Test wdbi_query_clear - cmocka_unit_test_setup_teardown(test_wdbi_query_clear_null_payload, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_clear_invalid_payload, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_clear_no_id, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_clear_stmt_cache_error, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_clear_sql_step_error, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_clear_ok, setup_wdb_t, teardown_wdb_t), - //Test wdbi_query_checksum - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_null_payload, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_no_begin, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_no_end, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_no_checksum, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_no_id, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_range_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_range_no_data, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_diff_hexdigest, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_equal_hexdigest, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_bad_action, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_check_left_no_tail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_check_left_ok, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_last_manager_success, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_query_checksum_last_manager_diff, setup_wdb_t, teardown_wdb_t), - // Test wdbi_get_last_manager_checksum - cmocka_unit_test_setup_teardown(test_wdbi_get_last_manager_checksum_success, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_get_last_manager_stmt_cache_fail, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_get_last_manager_exec_stmt_fail, setup_wdb_t, teardown_wdb_t), - //Test wdbi_array_hash - cmocka_unit_test_setup_teardown(test_wdbi_array_hash_success, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_array_hash_null, setup_wdb_t, teardown_wdb_t), - //Test wdbi_strings_hash - cmocka_unit_test_setup_teardown(test_wdbi_strings_hash_success, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_strings_hash_null, setup_wdb_t, teardown_wdb_t), - // Test wdbi_check_sync_status - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_cache_failed, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_exec_failed, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_data_failed, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_data_synced, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_data_never_synced_without_checksum, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_data_not_synced_error_checksum, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_data_not_synced_checksum_no_data, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(test_wdbi_check_sync_status_data_not_synced_checksum_valid, setup_wdb_t, teardown_wdb_t), - // Test wdbi_last_completion - cmocka_unit_test_setup_teardown(test_wdbi_last_completion_step_fail, setup_wdb_t, teardown_wdb_t), - - // Test wdb_global_group_hash_cache - cmocka_unit_test(test_wdb_global_group_hash_cache_clear_success), - cmocka_unit_test(test_wdb_global_group_hash_cache_read_fail), - cmocka_unit_test(test_wdb_global_group_hash_cache_write_success), - cmocka_unit_test(test_wdb_global_group_hash_cache_read_success), - cmocka_unit_test(test_wdb_global_group_hash_cache_invalid_mode), - - // Test wdb_get_global_group_hash - cmocka_unit_test_setup_teardown(wdb_get_global_group_hash_read_success, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(wdb_get_global_group_hash_invalid_db_structure, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(wdb_get_global_group_hash_invalid_statement, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(wdb_get_global_group_hash_calculate_success_no_group_hash_information, setup_wdb_t, teardown_wdb_t), - cmocka_unit_test_setup_teardown(wdb_get_global_group_hash_calculate_success, setup_wdb_t, teardown_wdb_t), - - // Tests wdbi_report_removed - cmocka_unit_test(test_wdbi_report_removed_no_handle), - cmocka_unit_test(test_wdbi_report_removed_packages_success), - cmocka_unit_test(test_wdbi_report_removed_hotfixes_success), - cmocka_unit_test(test_wdbi_report_removed_hotfixes_success_multiple_steps), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_metadata.c b/src/unit_tests/wazuh_db/test_wdb_metadata.c deleted file mode 100644 index a251449a62f..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_metadata.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * September, 2020. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("000",init_data->wdb->id); - os_calloc(256,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - *state = init_data; - return 0; -} - -static int test_teardown(void **state){ - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - -void test_wdb_count_tables_with_name_prepare_fail(void **state) -{ - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "DB(000) sqlite3_prepare_v2(): ERROR MESSAGE"); - - int count = 0; - ret = wdb_count_tables_with_name(data->wdb, "metadata", &count); - - assert_int_equal(ret, OS_INVALID); - assert_int_equal(count, 0); -} - -void test_wdb_count_tables_with_name_bind_fail(void **state) -{ - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "metadata"); - will_return(__wrap_sqlite3_bind_text, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap__merror, formatted_msg, "DB(000) sqlite3_bind_text(): ERROR MESSAGE"); - - int count = 0; - ret = wdb_count_tables_with_name(data->wdb, "metadata", &count); - - assert_int_equal(ret, OS_INVALID); - assert_int_equal(count, 0); -} - -void test_wdb_count_tables_with_name_step_fail(void **state) -{ - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "metadata"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) SQLite: ERROR MESSAGE"); - - int count = 0; - ret = wdb_count_tables_with_name(data->wdb, "metadata", &count); - - assert_int_equal(ret, OS_INVALID); - assert_int_equal(count, 0); -} - -void test_wdb_count_tables_with_name_success(void **state) -{ - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "metadata"); - will_return(__wrap_sqlite3_bind_text, SQLITE_OK); - will_return(__wrap_sqlite3_step, 0); - will_return(__wrap_sqlite3_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int,iCol, 0); - will_return(__wrap_sqlite3_column_int, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - int count = 0; - ret = wdb_count_tables_with_name(data->wdb, "metadata", &count); - - assert_int_equal(ret, OS_SUCCESS); - assert_int_equal(count, 1); -} - -int main() -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_wdb_count_tables_with_name_prepare_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_count_tables_with_name_bind_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_count_tables_with_name_step_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_count_tables_with_name_success, test_setup, test_teardown) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_parser.c b/src/unit_tests/wazuh_db/test_wdb_parser.c deleted file mode 100644 index 53468de185d..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_parser.c +++ /dev/null @@ -1,2750 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_syscollector_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_agents_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_delta_event_wrappers.h" - - -#include "os_err.h" -#include "../wazuh_db/wdb.h" - -typedef struct test_struct { - wdb_t *wdb; - wdb_t *wdb_global; - char *output; -} test_struct_t; - -static int test_setup(void **state) { - test_struct_t *init_data; - - init_data = malloc(sizeof(test_struct_t)); - init_data->wdb = malloc(sizeof(wdb_t)); - init_data->wdb_global = malloc(sizeof(wdb_t)); - init_data->wdb->id = strdup("000"); - init_data->output = calloc(256, sizeof(char)); - init_data->wdb->peer = 1234; - init_data->wdb->enabled = true; - - *state = init_data; - - return 0; -} - -static int test_teardown(void **state){ - test_struct_t *data = (test_struct_t *)*state; - - free(data->output); - free(data->wdb->id); - free(data->wdb); - free(data->wdb_global); - free(data); - - return 0; -} - -static int test_setup_global(void **state) { - test_struct_t *init_data; - - init_data = malloc(sizeof(test_struct_t)); - init_data->wdb = malloc(sizeof(wdb_t)); - init_data->wdb_global = malloc(sizeof(wdb_t)); - init_data->wdb->id = strdup("global"); - init_data->output = calloc(256, sizeof(char)); - init_data->wdb->peer = 1234; - init_data->wdb->enabled = true; - - *state = init_data; - - return 0; -} - -void test_wdb_parse_syscheck_no_space(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) Invalid FIM query syntax: badquery_nospace"); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, "badquery_nospace", data->output); - - assert_string_equal(data->output, "err Invalid FIM query syntax, near \'badquery_nospace\'"); - assert_int_equal(ret, -1); -} - -void test_scan_info_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("scan_info_get "); - - will_return(__wrap_wdb_scan_info_get, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot get FIM scan info."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot get fim scan info."); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_scan_info_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("scan_info_get "); - - - will_return(__wrap_wdb_scan_info_get, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok 0"); - assert_int_equal(ret, 1); - - os_free(query); -} - - -void test_update_info_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("updatedate "); - - will_return(__wrap_wdb_fim_update_date_entry, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot update fim date field."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot update fim date field."); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_update_info_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("updatedate "); - - will_return(__wrap_wdb_fim_update_date_entry, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 1); - - os_free(query); -} - - -void test_clean_old_entries_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("cleandb "); - - will_return(__wrap_wdb_fim_clean_old_entries, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot clean fim database."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot clean fim database."); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_clean_old_entries_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("cleandb "); - - will_return(__wrap_wdb_fim_clean_old_entries, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 1); - - os_free(query); -} - -void test_scan_info_update_noarg(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("scan_info_update "); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid scan_info fim query syntax."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Invalid Syscheck query syntax, near \'\'"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_scan_info_update_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("scan_info_update \"191919\" "); - - will_return(__wrap_wdb_scan_info_update, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot save fim control message."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot save fim control message"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_scan_info_update_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("scan_info_update \"191919\" "); - - will_return(__wrap_wdb_scan_info_update, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 1); - - os_free(query); -} - -void test_scan_info_fim_check_control_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("control "); - - will_return(__wrap_wdb_scan_info_fim_checks_control, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot save fim check_control message."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot save fim control message"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_scan_info_fim_check_control_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("control "); - - will_return(__wrap_wdb_scan_info_fim_checks_control, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 1); - - os_free(query); -} - -void test_syscheck_load_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("load "); - - will_return(__wrap_wdb_syscheck_load, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot load FIM."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot load Syscheck"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_syscheck_load_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("load "); - - will_return(__wrap_wdb_syscheck_load, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok TEST STRING"); - assert_int_equal(ret, 1); - - os_free(query); -} - -void test_fim_delete_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("delete "); - - will_return(__wrap_wdb_fim_delete, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot delete FIM entry."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot delete Syscheck"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_fim_delete_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("delete "); - - will_return(__wrap_wdb_fim_delete, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 1); - - os_free(query); -} - -void test_syscheck_save_noarg(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save "); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid FIM query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) FIM query: "); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Invalid Syscheck query syntax, near \'\'"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_syscheck_save_invalid_type(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save invalid_type "); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid FIM query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) FIM query: invalid_type"); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Invalid Syscheck query syntax, near \'invalid_type\'"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_syscheck_save_file_type_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save file 1212121 "); - - will_return(__wrap_wdb_syscheck_save, -1); - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot save FIM."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot save Syscheck"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_syscheck_save_file_nospace(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save file "); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid FIM query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "FIM query: "); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Invalid Syscheck query syntax, near \'\'"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_syscheck_save_file_type_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save file !1212121 "); - - will_return(__wrap_wdb_syscheck_save, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 1); - - os_free(query); -} - -void test_syscheck_save_registry_type_error(void **state) { - int ret; - - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save registry 1212121 "); - - will_return(__wrap_wdb_syscheck_save, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot save FIM."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot save Syscheck"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_syscheck_save_registry_type_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save registry !1212121 "); - - will_return(__wrap_wdb_syscheck_save, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 1); - - os_free(query); -} - -void test_syscheck_save2_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save2 "); - - will_return(__wrap_wdb_syscheck_save2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot save FIM."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot save Syscheck"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_syscheck_save2_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save2 "); - - will_return(__wrap_wdb_syscheck_save2, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, 0); - - os_free(query); -} - -void test_integrity_check_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("integrity_check_ "); - - will_return(__wrap_wdbi_query_checksum, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot query FIM range checksum."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot perform range checksum"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_integrity_check_no_data(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("integrity_check_ "); - - will_return(__wrap_wdbi_query_checksum, 0); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok no_data"); - assert_int_equal(ret, 0); - - os_free(query); -} - -void test_integrity_check_checksum_fail(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("integrity_check_ "); - - will_return(__wrap_wdbi_query_checksum, 1); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok checksum_fail"); - assert_int_equal(ret, 0); - - os_free(query); -} - -void test_integrity_check_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("integrity_check_ "); - - will_return(__wrap_wdbi_query_checksum, 2); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok "); - assert_int_equal(ret, 0); - - os_free(query); -} - -void test_integrity_clear_error(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("integrity_clear "); - - will_return(__wrap_wdbi_query_clear, -1); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot query FIM range checksum."); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Cannot perform range checksum"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_integrity_clear_ok(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("integrity_clear "); - - will_return(__wrap_wdbi_query_clear, 2); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "ok "); - assert_int_equal(ret, 0); - - os_free(query); -} - -void test_invalid_command(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("wrong_command "); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid FIM query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB query error near: wrong_command"); - - ret = wdb_parse_syscheck(data->wdb, WDB_FIM_FILE, query, data->output); - - assert_string_equal(data->output, "err Invalid Syscheck query syntax, near 'wrong_command'"); - assert_int_equal(ret, -1); - - os_free(query); -} - -void test_wdb_parse_sca_no_space(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid Security Configuration Assessment query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "Security Configuration Assessment query: badquery_nospace"); - - ret = wdb_parse_sca(data->wdb, "badquery_nospace", data->output); - - assert_string_equal(data->output, "err Invalid Security Configuration Assessment query syntax, near \'badquery_nospace\'"); - assert_int_equal(ret, -1); -} - -void test_wdb_parse_sca_query_not_found(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char query [7] = "query "; - - will_return(__wrap_wdb_sca_find, 0); - - ret = wdb_parse_sca(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok not found"); - assert_int_equal(ret, 0); -} - -void test_wdb_parse_sca_query_found(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char query [7] = "query "; - - will_return(__wrap_wdb_sca_find, 1); - - ret = wdb_parse_sca(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok found "); - assert_int_equal(ret, 1); -} - -void test_wdb_parse_sca_cannot_query(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char query [7] = "query "; - - will_return(__wrap_wdb_sca_find, -1); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot query Security Configuration Assessment."); - - ret = wdb_parse_sca(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Cannot query Security Configuration Assessment"); - assert_int_equal(ret, -1); -} - -void test_wdb_parse_sca_invalid_insert(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char query [8] = "insert "; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid Security Configuration Assessment query syntax. JSON object not found or invalid"); - - ret = wdb_parse_sca(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid Security Configuration Assessment query syntax, near ''"); - assert_int_equal(ret, -1); -} - -void test_wdb_parse_sca_invalid_insert_not_number_id(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char query [25] = "insert {\"id\":\"wazuh\"}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Malformed JSON: field 'id' must be a number"); - - ret = wdb_parse_sca(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid Security Configuration Assessment query syntax, near '{\"id\":\"wazuh\"}'"); - assert_int_equal(ret, -1); -} - -void test_wdb_parse_sca_invalid_insert_negative_number_id(void **state) { - int ret; - test_struct_t *data = (test_struct_t *)*state; - char query [25] = "insert {\"id\":-1}"; - - expect_string(__wrap__mdebug1, formatted_msg, "Malformed JSON: field 'id' cannot be negative"); - - ret = wdb_parse_sca(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid Security Configuration Assessment query syntax, near '{\"id\":-1}'"); - assert_int_equal(ret, -1); -} - - -void test_wdb_parse_rootcheck_badquery(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("badquery "); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) Invalid rootcheck query syntax: badquery"); - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid rootcheck query syntax, near 'badquery'"); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_wdb_parse_rootcheck_delete_error(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("delete"); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__merror, formatted_msg, "DB(000) Cannot cache statement"); - - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Error deleting rootcheck PM tuple"); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_wdb_parse_rootcheck_delete_ok(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("delete"); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_changes, 10); - - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok 0"); - assert_int_equal(ret, 0); - os_free(query); -} - -void test_wdb_parse_rootcheck_save_invalid_no_next(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save"); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) Invalid rootcheck query syntax: save"); - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid rootcheck query syntax, near 'save'"); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_wdb_parse_rootcheck_save_no_ptr(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save "); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) Invalid rootcheck query syntax: save"); - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid rootcheck query syntax, near 'save'"); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_wdb_parse_rootcheck_save_date_max_long(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save 9223372036854775807 asdasd"); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) Invalid rootcheck date timestamp: 9223372036854775807"); - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid rootcheck query syntax, near 'save'"); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_wdb_parse_rootcheck_save_update_cache_error(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save 123456789 Test"); - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__merror, formatted_msg, "DB(000) Cannot cache statement"); - - expect_string(__wrap__merror, formatted_msg, "DB(000) Error updating rootcheck PM tuple on SQLite database"); - - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Error updating rootcheck PM tuple"); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_wdb_parse_rootcheck_save_update_success(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save 123456789 Test"); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 123456789); - will_return_always(__wrap_sqlite3_bind_int, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "Test"); - will_return(__wrap_sqlite3_bind_text, 1); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_changes, 10); - - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok 1"); - assert_int_equal(ret, 0); - os_free(query); -} - -void test_wdb_parse_rootcheck_save_update_insert_cache_error(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save 123456789 Test"); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 123456789); - will_return_always(__wrap_sqlite3_bind_int, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "Test"); - will_return(__wrap_sqlite3_bind_text, 1); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_changes, 0); - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__merror, formatted_msg, "DB(000) Cannot cache statement"); - - expect_string(__wrap__merror, formatted_msg, "DB(000) Error inserting rootcheck PM tuple on SQLite database for agent"); - - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Error updating rootcheck PM tuple"); - assert_int_equal(ret, -1); - os_free(query); -} - -void test_wdb_parse_rootcheck_save_update_insert_success(void **state) -{ - int ret; - test_struct_t *data = (test_struct_t *)*state; - char *query = strdup("save 123456789 Test"); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 123456789); - will_return_always(__wrap_sqlite3_bind_int, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "Test"); - will_return(__wrap_sqlite3_bind_text, 1); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_changes, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, 123456789); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, 123456789); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "Test"); - will_return(__wrap_sqlite3_bind_text, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - will_return(__wrap_sqlite3_bind_text, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - will_return(__wrap_sqlite3_bind_text, 1); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_last_insert_rowid, 10); - - ret = wdb_parse_rootcheck(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok 2"); - assert_int_equal(ret, 0); - os_free(query); -} - -/* Tests osinfo */ - -void test_osinfo_syntax_error(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 osinfo", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: osinfo"); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) query error near: osinfo"); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'osinfo'"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_invalid_action(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 osinfo invalid", query); - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: osinfo invalid"); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid osinfo action: invalid"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_missing_action(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("", query); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Missing osinfo action"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_get_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("get", query); - - // wdb_agents_get_sys_osinfo - will_return(__wrap_wdb_agents_get_sys_osinfo, NULL); - will_return_count(__wrap_sqlite3_errmsg, "ERROR MESSAGE", -1); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Cannot get sys_osinfo database table information; SQL err: ERROR MESSAGE"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_get_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - char *result = NULL; - - os_strdup("get", query); - os_strdup("[]", result); - cJSON *test = cJSON_CreateObject(); - - // wdb_agents_get_sys_osinfo - will_return(__wrap_wdb_agents_get_sys_osinfo, test); - will_return(__wrap_cJSON_PrintUnformatted, result); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok []"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_osinfo_set_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_scan_id(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set ", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_scan_time(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_hostname(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_architecture(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_name(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_version(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_codename(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_major(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_minor(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_build(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_platform(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|os_minor|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_sysname(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|os_minor|os_build|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_release(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|os_minor|os_build|os_platform|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_version(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|os_minor|os_build|os_platform|sysname|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_no_os_release(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|os_minor|os_build|os_platform|sysname|NULL|NULL|", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap__mdebug1, formatted_msg, "Invalid OS info query syntax."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid OS info query syntax"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_error_saving(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|os_minor|os_build|os_platform|sysname|release|NULL|NULL|NULL|NULL", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap_wdb_osinfo_save, scan_id, "scan_id"); - expect_string(__wrap_wdb_osinfo_save, scan_time, "scan_time"); - expect_string(__wrap_wdb_osinfo_save, hostname, "hostname"); - expect_string(__wrap_wdb_osinfo_save, architecture, "architecture"); - expect_string(__wrap_wdb_osinfo_save, os_name, "os_name"); - expect_string(__wrap_wdb_osinfo_save, os_version, "os_version"); - expect_string(__wrap_wdb_osinfo_save, os_codename, "os_codename"); - expect_string(__wrap_wdb_osinfo_save, os_major, "os_major"); - expect_string(__wrap_wdb_osinfo_save, os_minor, "os_minor"); - expect_string(__wrap_wdb_osinfo_save, os_build, "os_build"); - expect_string(__wrap_wdb_osinfo_save, os_platform, "os_platform"); - expect_string(__wrap_wdb_osinfo_save, sysname, "sysname"); - expect_string(__wrap_wdb_osinfo_save, release, "release"); - expect_string(__wrap_wdb_osinfo_save, checksum, "legacy"); - expect_value(__wrap_wdb_osinfo_save, replace, FALSE); - will_return(__wrap_wdb_osinfo_save, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "Cannot save OS information."); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Cannot save OS information."); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_osinfo_set_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("set scan_id|scan_time|hostname|architecture|os_name|os_version|os_codename|os_major|os_minor|os_build|os_platform|sysname|release|version|os_release|os_patch|os_display_version", query); - - // wdb_parse_agents_set_sys_osinfo - expect_string(__wrap_wdb_osinfo_save, scan_id, "scan_id"); - expect_string(__wrap_wdb_osinfo_save, scan_time, "scan_time"); - expect_string(__wrap_wdb_osinfo_save, hostname, "hostname"); - expect_string(__wrap_wdb_osinfo_save, architecture, "architecture"); - expect_string(__wrap_wdb_osinfo_save, os_name, "os_name"); - expect_string(__wrap_wdb_osinfo_save, os_version, "os_version"); - expect_string(__wrap_wdb_osinfo_save, os_codename, "os_codename"); - expect_string(__wrap_wdb_osinfo_save, os_major, "os_major"); - expect_string(__wrap_wdb_osinfo_save, os_minor, "os_minor"); - expect_string(__wrap_wdb_osinfo_save, os_patch, "os_patch"); - expect_string(__wrap_wdb_osinfo_save, os_build, "os_build"); - expect_string(__wrap_wdb_osinfo_save, os_platform, "os_platform"); - expect_string(__wrap_wdb_osinfo_save, sysname, "sysname"); - expect_string(__wrap_wdb_osinfo_save, release, "release"); - expect_string(__wrap_wdb_osinfo_save, version, "version"); - expect_string(__wrap_wdb_osinfo_save, os_release, "os_release"); - expect_string(__wrap_wdb_osinfo_save, os_display_version, "os_display_version"); - expect_string(__wrap_wdb_osinfo_save, checksum, "legacy"); - expect_value(__wrap_wdb_osinfo_save, replace, FALSE); - will_return(__wrap_wdb_osinfo_save, OS_SUCCESS); - - ret = wdb_parse_osinfo(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -/* wdb_parse_packages */ - -/* get */ - -void test_packages_get_success(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - char* result = NULL; - os_strdup("get", query); - os_strdup("[{\"status\":\"SUCCESS\"}]", result); - cJSON *test = cJSON_CreateObject(); - - will_return(__wrap_wdb_agents_get_packages, test); - will_return(__wrap_wdb_agents_get_packages, OS_SUCCESS); - will_return(__wrap_cJSON_PrintUnformatted, result); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok [{\"status\":\"SUCCESS\"}]"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_get_null_response(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("get", query); - - will_return(__wrap_wdb_agents_get_packages, NULL); - will_return(__wrap_wdb_agents_get_packages, OS_SUCCESS); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting packages from sys_programs"); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Error getting packages from sys_programs"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_get_err_response(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - char* result = NULL; - os_strdup("get", query); - os_strdup("[{\"status\":\"ERROR\"}]", result); - cJSON *test = cJSON_CreateObject(); - - will_return(__wrap_wdb_agents_get_packages, test); - will_return(__wrap_wdb_agents_get_packages, OS_INVALID); - will_return(__wrap_cJSON_PrintUnformatted, result); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "err [{\"status\":\"ERROR\"}]"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_packages_get_sock_err_response(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - char* result = NULL; - os_strdup("get", query); - os_strdup("[{\"status\":\"ERROR\"}]", result); - cJSON *test = cJSON_CreateObject(); - - will_return(__wrap_wdb_agents_get_packages, test); - will_return(__wrap_wdb_agents_get_packages, OS_SOCKTERR); - will_return(__wrap_cJSON_PrintUnformatted, result); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, ""); - assert_int_equal(ret, OS_SOCKTERR); - - os_free(query); -} - -/* save */ - -void test_packages_save_success(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15", query); - - expect_string(__wrap_wdb_package_save, scan_id, "0"); - expect_string(__wrap_wdb_package_save, scan_time, "1"); - expect_string(__wrap_wdb_package_save, format, "2"); - expect_string(__wrap_wdb_package_save, name, "3"); - expect_string(__wrap_wdb_package_save, priority, "4"); - expect_string(__wrap_wdb_package_save, section, "5"); - expect_value(__wrap_wdb_package_save, size, 6); - expect_string(__wrap_wdb_package_save, vendor, "7"); - expect_string(__wrap_wdb_package_save, install_time, "8"); - expect_string(__wrap_wdb_package_save, version, "9"); - expect_string(__wrap_wdb_package_save, architecture, "10"); - expect_string(__wrap_wdb_package_save, multiarch, "11"); - expect_string(__wrap_wdb_package_save, source, "12"); - expect_string(__wrap_wdb_package_save, description, "13"); - expect_string(__wrap_wdb_package_save, location, "14"); - expect_string(__wrap_wdb_package_save, checksum, SYSCOLLECTOR_LEGACY_CHECKSUM_VALUE); - expect_string(__wrap_wdb_package_save, item_id, "15"); - expect_value(__wrap_wdb_package_save, replace, FALSE); - will_return(__wrap_wdb_package_save, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_attempt, component, WDB_SYSCOLLECTOR_PACKAGES); - expect_value(__wrap_wdbi_update_attempt, timestamp, 0); - expect_value(__wrap_wdbi_update_attempt, legacy, TRUE); - expect_string(__wrap_wdbi_update_attempt, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_attempt, manager_checksum, ""); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_save_success_null_items(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|1|2|3|4|5|NULL|7|8|9|10|11|12|13|NULL|NULL", query); - - expect_string(__wrap_wdb_package_save, scan_id, "0"); - expect_string(__wrap_wdb_package_save, scan_time, "1"); - expect_string(__wrap_wdb_package_save, format, "2"); - expect_string(__wrap_wdb_package_save, name, "3"); - expect_string(__wrap_wdb_package_save, priority, "4"); - expect_string(__wrap_wdb_package_save, section, "5"); - expect_value(__wrap_wdb_package_save, size, -1); - expect_string(__wrap_wdb_package_save, vendor, "7"); - expect_string(__wrap_wdb_package_save, install_time, "8"); - expect_string(__wrap_wdb_package_save, version, "9"); - expect_string(__wrap_wdb_package_save, architecture, "10"); - expect_string(__wrap_wdb_package_save, multiarch, "11"); - expect_string(__wrap_wdb_package_save, source, "12"); - expect_string(__wrap_wdb_package_save, description, "13"); - expect_value (__wrap_wdb_package_save, location, NULL); - expect_string(__wrap_wdb_package_save, checksum, SYSCOLLECTOR_LEGACY_CHECKSUM_VALUE); - expect_value(__wrap_wdb_package_save, item_id, NULL); - expect_value(__wrap_wdb_package_save, replace, FALSE); - will_return(__wrap_wdb_package_save, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_attempt, component, WDB_SYSCOLLECTOR_PACKAGES); - expect_value(__wrap_wdbi_update_attempt, timestamp, 0); - expect_value(__wrap_wdbi_update_attempt, legacy, TRUE); - expect_string(__wrap_wdbi_update_attempt, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_attempt, manager_checksum, ""); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_save_success_empty_items(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save |1|2|3||5|6|7||9|10|11||13|14|", query); - - expect_string(__wrap_wdb_package_save, scan_id, ""); - expect_string(__wrap_wdb_package_save, scan_time, "1"); - expect_string(__wrap_wdb_package_save, format, "2"); - expect_string(__wrap_wdb_package_save, name, "3"); - expect_string(__wrap_wdb_package_save, priority, ""); - expect_string(__wrap_wdb_package_save, section, "5"); - expect_value(__wrap_wdb_package_save, size, 6); - expect_string(__wrap_wdb_package_save, vendor, "7"); - expect_string(__wrap_wdb_package_save, install_time, ""); - expect_string(__wrap_wdb_package_save, version, "9"); - expect_string(__wrap_wdb_package_save, architecture, "10"); - expect_string(__wrap_wdb_package_save, multiarch, "11"); - expect_string(__wrap_wdb_package_save, source, ""); - expect_string(__wrap_wdb_package_save, description, "13"); - expect_string(__wrap_wdb_package_save, location, "14"); - expect_string(__wrap_wdb_package_save, checksum, SYSCOLLECTOR_LEGACY_CHECKSUM_VALUE); - expect_string(__wrap_wdb_package_save, item_id, ""); - expect_value(__wrap_wdb_package_save, replace, FALSE); - will_return(__wrap_wdb_package_save, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_attempt, component, WDB_SYSCOLLECTOR_PACKAGES); - expect_value(__wrap_wdbi_update_attempt, timestamp, 0); - expect_value(__wrap_wdbi_update_attempt, legacy, TRUE); - expect_string(__wrap_wdbi_update_attempt, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_attempt, manager_checksum, ""); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_save_missing_items(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14", query); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid package info query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "Package info query: 14"); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid package info query syntax, near '14'"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_packages_save_err(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15", query); - - expect_string(__wrap_wdb_package_save, scan_id, "0"); - expect_string(__wrap_wdb_package_save, scan_time, "1"); - expect_string(__wrap_wdb_package_save, format, "2"); - expect_string(__wrap_wdb_package_save, name, "3"); - expect_string(__wrap_wdb_package_save, priority, "4"); - expect_string(__wrap_wdb_package_save, section, "5"); - expect_value(__wrap_wdb_package_save, size, 6); - expect_string(__wrap_wdb_package_save, vendor, "7"); - expect_string(__wrap_wdb_package_save, install_time, "8"); - expect_string(__wrap_wdb_package_save, version, "9"); - expect_string(__wrap_wdb_package_save, architecture, "10"); - expect_string(__wrap_wdb_package_save, multiarch, "11"); - expect_string(__wrap_wdb_package_save, source, "12"); - expect_string(__wrap_wdb_package_save, description, "13"); - expect_string(__wrap_wdb_package_save, location, "14"); - expect_string(__wrap_wdb_package_save, checksum, SYSCOLLECTOR_LEGACY_CHECKSUM_VALUE); - expect_string(__wrap_wdb_package_save, item_id, "15"); - expect_value(__wrap_wdb_package_save, replace, FALSE); - will_return(__wrap_wdb_package_save, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Cannot save package information."); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Cannot save package information."); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -/* del */ - -void test_packages_del_success(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("del 0", query); - - expect_string(__wrap_wdb_package_update, scan_id, "0"); - will_return(__wrap_wdb_package_update, OS_SUCCESS); - - expect_string(__wrap_wdb_package_delete, scan_id, "0"); - will_return(__wrap_wdb_package_delete, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_completion, component, WDB_SYSCOLLECTOR_PACKAGES); - expect_value(__wrap_wdbi_update_completion, timestamp, 0); - expect_string(__wrap_wdbi_update_completion, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_completion, manager_checksum, ""); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_del_success_null_items(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("del NULL", query); - - expect_value(__wrap_wdb_package_update, scan_id, NULL); - will_return(__wrap_wdb_package_update, OS_SUCCESS); - - expect_value(__wrap_wdb_package_delete, scan_id, NULL); - will_return(__wrap_wdb_package_delete, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_completion, component, WDB_SYSCOLLECTOR_PACKAGES); - expect_value(__wrap_wdbi_update_completion, timestamp, 0); - expect_string(__wrap_wdbi_update_completion, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_completion, manager_checksum, ""); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_del_update_err(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("del 0", query); - - expect_string(__wrap_wdb_package_update, scan_id, "0"); - will_return(__wrap_wdb_package_update, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Cannot update scanned packages."); - - expect_string(__wrap_wdb_package_delete, scan_id, "0"); - will_return(__wrap_wdb_package_delete, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_completion, component, WDB_SYSCOLLECTOR_PACKAGES); - expect_value(__wrap_wdbi_update_completion, timestamp, 0); - expect_string(__wrap_wdbi_update_completion, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_completion, manager_checksum, ""); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_packages_del_delete_err(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("del 0", query); - - expect_string(__wrap_wdb_package_update, scan_id, "0"); - will_return(__wrap_wdb_package_update, OS_SUCCESS); - - expect_string(__wrap_wdb_package_delete, scan_id, "0"); - will_return(__wrap_wdb_package_delete, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Cannot delete old package information."); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Cannot delete old package information."); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -/* invalid action */ - -void test_packages_invalid_action(void **state) { - - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("invalid", query); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid package info query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB query error near: invalid"); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid package info query syntax, near 'invalid'"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_packages_no_action(void **state) { - - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("", query); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid package info query syntax. Missing action"); - expect_string(__wrap__mdebug2, formatted_msg, "DB query error. Missing action"); - - ret = wdb_parse_packages(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid package info query syntax. Missing action"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - - -/* wdb_parse_hotfixes */ - -/* get */ - -void test_hotfixes_get_success(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - char* result = NULL; - os_strdup("get", query); - os_strdup("[{\"status\":\"SUCCESS\"}]", result); - cJSON *test = cJSON_CreateObject(); - - will_return(__wrap_wdb_agents_get_hotfixes, test); - will_return(__wrap_wdb_agents_get_hotfixes, OS_SUCCESS); - will_return(__wrap_cJSON_PrintUnformatted, result); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok [{\"status\":\"SUCCESS\"}]"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_hotfixes_get_null_response(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("get", query); - - will_return(__wrap_wdb_agents_get_hotfixes, NULL); - will_return(__wrap_wdb_agents_get_hotfixes, OS_SUCCESS); - expect_string(__wrap__mdebug1, formatted_msg, "Error getting hotfixes from sys_hotfixes"); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Error getting hotfixes from sys_hotfixes"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_hotfixes_get_err_response(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - char* result = NULL; - os_strdup("get", query); - os_strdup("[{\"status\":\"ERROR\"}]", result); - cJSON *test = cJSON_CreateObject(); - - will_return(__wrap_wdb_agents_get_hotfixes, test); - will_return(__wrap_wdb_agents_get_hotfixes, OS_INVALID); - will_return(__wrap_cJSON_PrintUnformatted, result); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "err [{\"status\":\"ERROR\"}]"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_hotfixes_get_sock_err_response(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - char* result = NULL; - os_strdup("get", query); - os_strdup("[{\"status\":\"ERROR\"}]", result); - cJSON *test = cJSON_CreateObject(); - - will_return(__wrap_wdb_agents_get_hotfixes, test); - will_return(__wrap_wdb_agents_get_hotfixes, OS_SOCKTERR); - will_return(__wrap_cJSON_PrintUnformatted, result); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, ""); - assert_int_equal(ret, OS_SOCKTERR); - - os_free(query); -} - -/* save */ - -void test_hotfixes_save_success(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|1|2", query); - - expect_string(__wrap_wdb_hotfix_save, scan_id, "0"); - expect_string(__wrap_wdb_hotfix_save, scan_time, "1"); - expect_string(__wrap_wdb_hotfix_save, hotfix, "2"); - expect_string(__wrap_wdb_hotfix_save, checksum, SYSCOLLECTOR_LEGACY_CHECKSUM_VALUE); - expect_value(__wrap_wdb_hotfix_save, replace, FALSE); - will_return(__wrap_wdb_hotfix_save, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_attempt, component, WDB_SYSCOLLECTOR_HOTFIXES); - expect_value(__wrap_wdbi_update_attempt, timestamp, 0); - expect_value(__wrap_wdbi_update_attempt, legacy, TRUE); - expect_string(__wrap_wdbi_update_attempt, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_attempt, manager_checksum, ""); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_hotfixes_save_success_null_items(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|NULL|2", query); - - expect_string(__wrap_wdb_hotfix_save, scan_id, "0"); - expect_value(__wrap_wdb_hotfix_save, scan_time, NULL); - expect_string(__wrap_wdb_hotfix_save, hotfix, "2"); - expect_string(__wrap_wdb_hotfix_save, checksum, SYSCOLLECTOR_LEGACY_CHECKSUM_VALUE); - expect_value(__wrap_wdb_hotfix_save, replace, FALSE); - will_return(__wrap_wdb_hotfix_save, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_attempt, component, WDB_SYSCOLLECTOR_HOTFIXES); - expect_value(__wrap_wdbi_update_attempt, timestamp, 0); - expect_value(__wrap_wdbi_update_attempt, legacy, TRUE); - expect_string(__wrap_wdbi_update_attempt, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_attempt, manager_checksum, ""); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_hotfixes_save_missing_items(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|1", query); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid hotfix info query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "Hotfix info query: 1"); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid hotfix info query syntax, near '1'"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_hotfixes_save_err(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("save 0|1|2", query); - - expect_string(__wrap_wdb_hotfix_save, scan_id, "0"); - expect_string(__wrap_wdb_hotfix_save, scan_time, "1"); - expect_string(__wrap_wdb_hotfix_save, hotfix, "2"); - expect_string(__wrap_wdb_hotfix_save, checksum, SYSCOLLECTOR_LEGACY_CHECKSUM_VALUE); - expect_value(__wrap_wdb_hotfix_save, replace, FALSE); - will_return(__wrap_wdb_hotfix_save, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Cannot save hotfix information."); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Cannot save hotfix information."); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -/* del */ - -void test_hotfixes_del_success(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("del 0", query); - - expect_string(__wrap_wdb_hotfix_delete, scan_id, "0"); - will_return(__wrap_wdb_hotfix_delete, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_completion, component, WDB_SYSCOLLECTOR_HOTFIXES); - expect_value(__wrap_wdbi_update_completion, timestamp, 0); - expect_string(__wrap_wdbi_update_completion, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_completion, manager_checksum, ""); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_hotfixes_del_success_null_items(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("del NULL", query); - - expect_value(__wrap_wdb_hotfix_delete, scan_id, NULL); - will_return(__wrap_wdb_hotfix_delete, OS_SUCCESS); - - will_return(__wrap_time, 0); - expect_value(__wrap_wdbi_update_completion, component, WDB_SYSCOLLECTOR_HOTFIXES); - expect_value(__wrap_wdbi_update_completion, timestamp, 0); - expect_string(__wrap_wdbi_update_completion, last_agent_checksum, ""); - expect_string(__wrap_wdbi_update_completion, manager_checksum, ""); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok"); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_hotfixes_del_delete_err(void **state) { - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("del 0", query); - - expect_string(__wrap_wdb_hotfix_delete, scan_id, "0"); - will_return(__wrap_wdb_hotfix_delete, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "Cannot delete old hotfix information."); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Cannot delete old hotfix information."); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -/* invalid action */ - -void test_hotfixes_invalid_action(void **state) { - - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("invalid", query); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid hotfix info query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB query error near: invalid"); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid hotfix info query syntax, near 'invalid'"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_hotfixes_no_action(void **state) { - - int ret = -1; - test_struct_t *data = (test_struct_t *)*state; - char* query = NULL; - os_strdup("", query); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid hotfix info query syntax. Missing action"); - expect_string(__wrap__mdebug2, formatted_msg, "DB query error. Missing action"); - - ret = wdb_parse_hotfixes(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid hotfix info query syntax. Missing action"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -/* wdb_parse_dbsync */ - -void test_wdb_parse_dbsync_no_table(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - - char * query = NULL; - os_strdup("", query); - - expect_string(__wrap__mdebug2, formatted_msg, "DBSYNC query: "); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid dbsync query syntax, near ''"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_no_operation(void ** state) { - - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo ", query); - - expect_string(__wrap__mdebug2, formatted_msg, "DBSYNC query: osinfo"); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid dbsync query syntax, near 'osinfo'"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_no_delta_data(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo INSERTED ", query); - - expect_string(__wrap__mdebug2, formatted_msg, "DBSYNC query: osinfo"); - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err Invalid dbsync query syntax, near 'osinfo'"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_invalid_table(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("not_existant_table INSERTED data", query); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_delta_data_not_json(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo INSERTED {\"unclosed\":\"json", query); - - expect_string(__wrap__mdebug1, formatted_msg, DB_DELTA_PARSING_ERR); - expect_string(__wrap__mdebug2, formatted_msg, "JSON error near: json"); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_invalid_operation(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo NOOP {}", query); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid operation type: NOOP"); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_insert_ok(void ** state) { - - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo INSERTED {\"key\": \"value\"}", query); - - expect_function_call(__wrap_wdb_upsert_dbsync); - will_return(__wrap_wdb_upsert_dbsync, true); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok "); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_wdb_parse_dbsync_insert_err(void ** state) { - - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo INSERTED {\"key\": \"value\"}", query); - - expect_function_call(__wrap_wdb_upsert_dbsync); - will_return(__wrap_wdb_upsert_dbsync, false); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_modified_ok(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo MODIFIED {\"key\": \"value\"}", query); - - expect_function_call(__wrap_wdb_upsert_dbsync); - will_return(__wrap_wdb_upsert_dbsync, true); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok "); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_wdb_parse_dbsync_modified_err(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo MODIFIED {\"key\": \"value\"}", query); - - expect_function_call(__wrap_wdb_upsert_dbsync); - will_return(__wrap_wdb_upsert_dbsync, false); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "err"); - assert_int_equal(ret, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_dbsync_deleted_ok(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo DELETED {\"key\": \"value\"}", query); - - expect_function_call(__wrap_wdb_delete_dbsync); - will_return(__wrap_wdb_delete_dbsync, true); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok "); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -void test_wdb_parse_dbsync_deleted_err(void ** state) { - test_struct_t * data = (test_struct_t *) *state; - char * query = NULL; - - os_strdup("osinfo DELETED {\"key\": \"value\"}", query); - - expect_function_call(__wrap_wdb_delete_dbsync); - will_return(__wrap_wdb_delete_dbsync, false); - - const int ret = wdb_parse_dbsync(data->wdb, query, data->output); - - assert_string_equal(data->output, "ok "); - assert_int_equal(ret, OS_SUCCESS); - - os_free(query); -} - -/* wdb_parse_global_backup */ - -void test_wdb_parse_global_backup_invalid_syntax(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup"); - - expect_string(__wrap__mdebug1, formatted_msg, "Global DB Invalid DB query syntax for backup."); - expect_string(__wrap__mdebug2, formatted_msg, "Global DB query error near: backup"); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'backup'"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_backup_missing_action(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("", query); - - result = wdb_parse_global_backup(NULL, query, data->output); - - assert_string_equal(data->output, "err Missing backup action"); - assert_int_equal(result, OS_INVALID); - os_free(query); -} - -void test_wdb_parse_global_backup_invalid_action(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("invalid", query); - - result = wdb_parse_global_backup(NULL, query, data->output); - - assert_string_equal(data->output, "err Invalid backup action: invalid"); - assert_int_equal(result, OS_INVALID); - os_free(query); -} - -void test_wdb_parse_global_backup_create_failed(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup create", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup create"); - - will_return(__wrap_wdb_global_create_backup, "ERROR MESSAGE"); - will_return(__wrap_wdb_global_create_backup, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "Creating Global DB snapshot on demand failed: ERROR MESSAGE"); - - expect_string(__wrap_w_is_file, file, "queue/db/global.db"); - will_return(__wrap_w_is_file, 1); - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ERROR MESSAGE"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_backup_create_success(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int result = OS_INVALID; - char *query = NULL; - - os_strdup("global backup create", query); - will_return(__wrap_wdb_open_global, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Global query: backup create"); - - will_return(__wrap_wdb_global_create_backup, "ok SNAPSHOT"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok SNAPSHOT"); - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -/* Tests agent vacuum */ - -void test_wdb_parse_agent_vacuum_commit_error(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 vacuum", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: vacuum"); - - will_return(__wrap_wdb_commit2, OS_INVALID); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot end transaction."); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot end transaction"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_agent_vacuum_vacuum_error(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 vacuum", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot vacuum database."); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot vacuum database"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_agent_vacuum_success_get_db_state_error(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 vacuum", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_SUCCESS); - - will_return(__wrap_wdb_get_db_state, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Couldn't get fragmentation after vacuum for the database."); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Vacuum performed, but couldn't get fragmentation information after vacuum"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_agent_vacuum_success_update_vacuum_error(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 vacuum", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_SUCCESS); - - will_return(__wrap_wdb_get_db_state, 10); - - will_return(__wrap_time, 16655); - - expect_string(__wrap_wdb_update_last_vacuum_data, last_vacuum_value, "10"); - will_return(__wrap_wdb_update_last_vacuum_data, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Couldn't update last vacuum info for the database."); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Vacuum performed, but last vacuum information couldn't be updated in the metadata table"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_agent_vacuum_success(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - char* response = NULL; - os_strdup("{\"fragmentation_after_vacuum\":10}", response); - - os_strdup("agent 000 vacuum", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: vacuum"); - will_return(__wrap_wdb_commit2, OS_SUCCESS); - - expect_function_call(__wrap_wdb_finalize_all_statements); - - will_return(__wrap_wdb_vacuum, OS_SUCCESS); - - will_return(__wrap_wdb_get_db_state, 10); - - will_return(__wrap_time, 16655); - - expect_string(__wrap_wdb_update_last_vacuum_data, last_vacuum_value, "10"); - will_return(__wrap_wdb_update_last_vacuum_data, OS_SUCCESS); - - will_return(__wrap_cJSON_PrintUnformatted, response); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"fragmentation_after_vacuum\":10}"); - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -/* Tests agent get_fragmentation */ - -void test_wdb_parse_agent_get_fragmentation_db_state_error(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 get_fragmentation", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: get_fragmentation"); - - will_return(__wrap_wdb_get_db_state, OS_INVALID); - will_return(__wrap_wdb_get_db_free_pages_percentage, 10); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot get database fragmentation."); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot get database fragmentation"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_agent_get_fragmentation_free_pages_error(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 get_fragmentation", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: get_fragmentation"); - - will_return(__wrap_wdb_get_db_state, 10); - will_return(__wrap_wdb_get_db_free_pages_percentage, OS_INVALID); - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Cannot get database fragmentation."); - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - will_return(__wrap_w_is_file, 1); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Cannot get database fragmentation"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -void test_wdb_parse_global_get_fragmentation_success(void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - char* response = NULL; - os_strdup("{\"fragmentation\":50,\"free_pages_percentage\":10}", response); - - os_strdup("agent 000 get_fragmentation", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: get_fragmentation"); - - will_return(__wrap_wdb_get_db_state, 50); - will_return(__wrap_wdb_get_db_free_pages_percentage, 10); - - will_return(__wrap_cJSON_PrintUnformatted, response); - - expect_function_call(__wrap_wdb_pool_leave); - - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "ok {\"fragmentation\":50,\"free_pages_percentage\":10}"); - assert_int_equal(result, OS_SUCCESS); - - os_free(query); -} - -void test_wdb_parse_delete_db_file (void **state) { - int result = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - char *query = NULL; - - os_strdup("agent 000 non-query", query); - - expect_value(__wrap_wdb_open_agent2, agent_id, atoi(data->wdb->id)); - will_return(__wrap_wdb_open_agent2, data->wdb); - expect_string(__wrap__mdebug2, formatted_msg, "Agent 000 query: non-query"); - - - expect_string(__wrap__mdebug1, formatted_msg, "DB(000) Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB(000) query error near: non-query"); - - expect_string(__wrap_w_is_file, file, "queue/db/000.db"); - //DB file deleted manually - will_return(__wrap_w_is_file, 0); - - expect_string(__wrap__mwarn, formatted_msg, "DB(queue/db/000.db) not found. This behavior is unexpected, the database will be recreated."); - will_return(__wrap_wdb_close, NULL); - will_return(__wrap_wdb_close, OS_SUCCESS); - expect_function_call(__wrap_wdb_pool_leave); - result = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'non-query'"); - assert_int_equal(result, OS_INVALID); - - os_free(query); -} - -int main() -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_wdb_parse_syscheck_no_space, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_scan_info_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_scan_info_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_update_info_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_update_info_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_clean_old_entries_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_clean_old_entries_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_scan_info_update_noarg, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_scan_info_update_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_scan_info_update_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_scan_info_fim_check_control_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_scan_info_fim_check_control_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_load_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_load_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_fim_delete_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_fim_delete_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save_noarg, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save_invalid_type, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save_file_type_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save_file_nospace, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save_file_type_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save_registry_type_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save_registry_type_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save2_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_syscheck_save2_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_integrity_check_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_integrity_check_no_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_integrity_check_checksum_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_integrity_check_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_integrity_clear_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_integrity_clear_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_invalid_command, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_sca_no_space, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_sca_query_not_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_sca_query_found, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_sca_cannot_query, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_sca_invalid_insert, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_sca_invalid_insert_not_number_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_sca_invalid_insert_negative_number_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_badquery, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_delete_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_delete_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_save_invalid_no_next, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_save_no_ptr, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_save_date_max_long, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_save_update_cache_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_save_update_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_save_update_insert_cache_error, - test_setup, - test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_rootcheck_save_update_insert_success, test_setup, test_teardown), - /* Tests osinfo */ - cmocka_unit_test_setup_teardown(test_osinfo_syntax_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_invalid_action, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_missing_action, test_setup, test_teardown), - // osinfo get - cmocka_unit_test_setup_teardown(test_osinfo_get_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_get_success, test_setup, test_teardown), - // osinfo set - cmocka_unit_test_setup_teardown(test_osinfo_set_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_scan_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_scan_time, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_hostname, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_architecture, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_name, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_version, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_codename, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_major, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_minor, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_build, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_platform, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_sysname, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_release, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_version, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_no_os_release, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_error_saving, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_osinfo_set_success, test_setup, test_teardown), - // wdb_parse_packages - cmocka_unit_test_setup_teardown(test_packages_get_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_get_null_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_get_err_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_get_sock_err_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_save_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_save_success_null_items, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_save_success_empty_items, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_save_missing_items, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_save_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_del_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_del_success_null_items, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_del_update_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_del_delete_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_invalid_action, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_packages_no_action, test_setup, test_teardown), - // wdb_parse_hotfixes - cmocka_unit_test_setup_teardown(test_hotfixes_get_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_get_null_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_get_err_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_get_sock_err_response, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_save_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_save_success_null_items, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_save_missing_items, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_save_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_del_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_del_success_null_items, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_del_delete_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_invalid_action, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_hotfixes_no_action, test_setup, test_teardown), - /* dbsync Tests */ - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_no_table, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_no_operation, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_no_delta_data, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_invalid_table, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_invalid_operation, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_delta_data_not_json, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_insert_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_insert_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_modified_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_modified_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_deleted_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_dbsync_deleted_err, test_setup, test_teardown), - /* wdb_parse_global_backup */ - cmocka_unit_test_setup_teardown(test_wdb_parse_global_backup_invalid_syntax, test_setup_global, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_backup_missing_action, test_setup_global, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_backup_invalid_action, test_setup_global, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_backup_create_failed, test_setup_global, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_backup_create_success, test_setup_global, test_teardown), - /* wdb_parse_agent_vacuum */ - cmocka_unit_test_setup_teardown(test_wdb_parse_agent_vacuum_commit_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_agent_vacuum_vacuum_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_agent_vacuum_success_get_db_state_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_agent_vacuum_success_update_vacuum_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_agent_vacuum_success, test_setup, test_teardown), - /* wdb_parse_agent_get_fragmentation */ - cmocka_unit_test_setup_teardown(test_wdb_parse_agent_get_fragmentation_db_state_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_agent_get_fragmentation_free_pages_error, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_global_get_fragmentation_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_delete_db_file, test_setup, test_teardown), - - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_pool.c b/src/unit_tests/wazuh_db/test_wdb_pool.c deleted file mode 100644 index b3b4bdb74d2..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_pool.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb_pool.h" -#include "../wazuh_db/wdb.h" -#include "../headers/shared.h" -#include "../wrappers/common.h" - -extern wdb_pool_t wdb_pool; - -/* setup/teardowns */ -static int setup_test(void **state) { - wdb_pool_init(); - - for(int i = 1; i<4; i++) { - char node_name[10]; - snprintf(node_name, 10, "node%d", i); - wdb_t * node = wdb_init(node_name); - rbtree_insert(wdb_pool.nodes, node_name, node); - wdb_pool.size++; - } - - test_mode = 1; - - return 0; -} - -static int setup_test_clean_1(void **state) { - wdb_pool_init(); - - for(int i = 1; i<4; i++) { - char node_name[10]; - snprintf(node_name, 10, "node%d", i); - wdb_t * node = wdb_init(node_name); - if(i != 1) { - node->refcount++; - node->db = (sqlite3 *)1; - } - rbtree_insert(wdb_pool.nodes, node_name, node); - wdb_pool.size++; - } - - test_mode = 1; - - return 0; -} - -static int setup_test_clean_2(void **state) { - wdb_pool_init(); - - for(int i = 1; i<4; i++) { - char node_name[10]; - snprintf(node_name, 10, "node%d", i); - wdb_t * node = wdb_init(node_name); - if(i != 2) { - node->refcount++; - node->db = (sqlite3 *)1; - } - rbtree_insert(wdb_pool.nodes, node_name, node); - wdb_pool.size++; - } - - test_mode = 1; - - return 0; -} - -static int setup_test_clean_3(void **state) { - wdb_pool_init(); - - for(int i = 1; i<4; i++) { - char node_name[10]; - snprintf(node_name, 10, "node%d", i); - wdb_t * node = wdb_init(node_name); - if(i != 3) { - node->refcount++; - node->db = (sqlite3 *)1; - } - rbtree_insert(wdb_pool.nodes, node_name, node); - wdb_pool.size++; - } - - test_mode = 1; - - return 0; -} - -static int teardown_test(void **state) { - char ** keys = rbtree_keys(wdb_pool.nodes); - - for (int i = 0; keys[i]; i++) { - wdb_t * node = rbtree_get(wdb_pool.nodes, keys[i]); - wdb_destroy(node); - rbtree_delete(wdb_pool.nodes, keys[i]); - wdb_pool.size--; - } - - free_strarray(keys); - - rbtree_destroy(wdb_pool.nodes); - - test_mode = 0; - return 0; -} - -static void test_wdb_pool_get_or_create_get(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - // lock node mutex - expect_function_call(__wrap_pthread_mutex_lock); - - wdb_t * node = wdb_pool_get_or_create("node3"); - - assert_string_equal(node->id, "node3"); - char ** keys = rbtree_keys(wdb_pool.nodes); - assert_string_equal(keys[2], "node3"); - assert_null(keys[3]); - free_strarray(keys); -} - -static void test_wdb_pool_get_or_create_create(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - // lock node mutex - expect_function_call(__wrap_pthread_mutex_lock); - - wdb_t * node = wdb_pool_get_or_create("node4"); - - assert_string_equal(node->id, "node4"); - char ** keys = rbtree_keys(wdb_pool.nodes); - assert_string_equal(keys[3], "node4"); - free_strarray(keys); -} - -static void test_wdb_pool_get_unknown(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - wdb_t * node = wdb_pool_get("node4"); - - assert_null(node); -} - -static void test_wdb_pool_get_known(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - // lock node mutex - expect_function_call(__wrap_pthread_mutex_lock); - - wdb_t * node = wdb_pool_get("node3"); - - assert_string_equal(node->id, "node3"); -} - -static void test_wdb_pool_leave_node_null(void **state) { - wdb_pool_leave(NULL); -} - -static void test_wdb_pool_leave_node_no_null(void **state) { - wdb_t *node = wdb_init("node"); - node->refcount = 1; - - // unlock node mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - wdb_pool_leave(node); - - assert_int_equal(node->refcount, 0); - wdb_destroy(node); -} - -static void test_wdb_pool_keys(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - char **keys = wdb_pool_keys(); - - assert_string_equal(keys[0], "node1"); - assert_string_equal(keys[1], "node2"); - assert_string_equal(keys[2], "node3"); - free_strarray(keys); -} - -static void test_wdb_pool_clean_all(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - wdb_pool_clean(); - - char ** keys = rbtree_keys(wdb_pool.nodes); - assert_null(keys[0]); - free_strarray(keys); -} - -static void test_wdb_pool_clean_1(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - wdb_pool_clean(); - - char ** keys = rbtree_keys(wdb_pool.nodes); - assert_string_equal(keys[0], "node2"); - assert_string_equal(keys[1], "node3"); - free_strarray(keys); -} - -static void test_wdb_pool_clean_2(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - wdb_pool_clean(); - - char ** keys = rbtree_keys(wdb_pool.nodes); - assert_string_equal(keys[0], "node1"); - assert_string_equal(keys[1], "node3"); - free_strarray(keys); -} - -static void test_wdb_pool_clean_3(void **state) { - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - wdb_pool_clean(); - - char ** keys = rbtree_keys(wdb_pool.nodes); - assert_string_equal(keys[0], "node1"); - assert_string_equal(keys[1], "node2"); - free_strarray(keys); -} - -static void test_wdb_pool_size(void **state) { - assert_int_equal(wdb_pool_size(), 3); - - // lock pool mutex - expect_function_call(__wrap_pthread_mutex_lock); - - // unlock pool mutex - expect_function_call(__wrap_pthread_mutex_unlock); - - wdb_pool_clean(); - - assert_int_equal(wdb_pool_size(), 0); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // Test wdb_pool_get_or_create - cmocka_unit_test_setup_teardown(test_wdb_pool_get_or_create_get, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_wdb_pool_get_or_create_create, setup_test, teardown_test), - // Test wdb_pool_get - cmocka_unit_test_setup_teardown(test_wdb_pool_get_unknown, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_wdb_pool_get_known, setup_test, teardown_test), - // Test wdb_pool_leave - cmocka_unit_test_setup_teardown(test_wdb_pool_leave_node_null, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_wdb_pool_leave_node_no_null, setup_test, teardown_test), - // Test wdb_pool_keys - cmocka_unit_test_setup_teardown(test_wdb_pool_keys, setup_test, teardown_test), - // Test wdb_pool_clean - cmocka_unit_test_setup_teardown(test_wdb_pool_clean_all, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_wdb_pool_clean_1, setup_test_clean_1, teardown_test), - cmocka_unit_test_setup_teardown(test_wdb_pool_clean_2, setup_test_clean_2, teardown_test), - cmocka_unit_test_setup_teardown(test_wdb_pool_clean_3, setup_test_clean_3, teardown_test), - // Test wdb_pool_size - cmocka_unit_test_setup_teardown(test_wdb_pool_size, setup_test, teardown_test), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_rootcheck.c b/src/unit_tests/wazuh_db/test_wdb_rootcheck.c deleted file mode 100644 index e0150689842..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_rootcheck.c +++ /dev/null @@ -1,141 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../headers/shared.h" - -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" - - -/********** setup/teardown *********************/ -int setup_wdb(void **state) { - wdb_t *wdb = NULL; - os_calloc(1,sizeof(wdb_t),wdb); - os_strdup("000",wdb->id); - os_calloc(1,sizeof(sqlite3 *),wdb->db); - *state = wdb; - return 0; -} - -int teardown_wdb(void **state) { - wdb_t *wdb = (wdb_t *)*state; - os_free(wdb->id); - os_free(wdb->db); - os_free(wdb); - return 0; -} -/*********** tests *********************/ -void test_wdb_rootcheck_insert_cache_error(void **state) { - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__merror, formatted_msg, "DB(000) Cannot cache statement"); - - wdb_t *wdb = (wdb_t *)*state; - rk_event_t event; - event.date_last = time(0); - event.date_first = event.date_last; - event.log = "Test log"; - int ret = wdb_rootcheck_insert(wdb, &event); - assert_int_equal(ret, -1); -} - -void test_wdb_rootcheck_insert_success(void **state) { - wdb_t *wdb = (wdb_t *)*state; - rk_event_t event; - event.date_last = time(0); - event.date_first = event.date_last; - event.log = "Test log"; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, event.date_first); - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, event.date_last); - will_return_always(__wrap_sqlite3_bind_int, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "Test log"); - will_return(__wrap_sqlite3_bind_text, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - will_return(__wrap_sqlite3_bind_text, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - will_return(__wrap_sqlite3_bind_text, 1); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_last_insert_rowid, 10); - int ret = wdb_rootcheck_insert(wdb, &event); - - assert_int_equal(ret, 10); -} - - -void test_wdb_rootcheck_update_cache_error(void **state) { - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__merror, formatted_msg, "DB(000) Cannot cache statement"); - - wdb_t *wdb = (wdb_t *)*state; - rk_event_t event; - event.date_last = time(0); - event.date_first = event.date_last; - event.log = "Test log"; - int ret = wdb_rootcheck_update(wdb, &event); - assert_int_equal(ret, -1); -} - -void test_wdb_rootcheck_update_succcess(void **state) { - wdb_t *wdb = (wdb_t *)*state; - rk_event_t event; - event.date_first = time(0); - event.date_last = event.date_first + 1; - event.log = "Test log"; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, event.date_last); - will_return_always(__wrap_sqlite3_bind_int, 1); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "Test log"); - will_return(__wrap_sqlite3_bind_text, 1); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_changes, 10); - int ret = wdb_rootcheck_update(wdb, &event); - assert_int_equal(ret, 10); -} - -void test_wdb_rootcheck_delete_cache_error(void **state) { - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__merror, formatted_msg, "DB(000) Cannot cache statement"); - - wdb_t *wdb = (wdb_t *)*state; - int ret = wdb_rootcheck_delete(wdb); - assert_int_equal(ret, -1); -} - -void test_wdb_rootcheck_delete_success(void **state) { - wdb_t *wdb = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_sqlite3_changes, 10); - int ret = wdb_rootcheck_delete(wdb); - assert_int_equal(ret, 10); -} -/***********************************************/ - -int main() -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_wdb_rootcheck_insert_cache_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_rootcheck_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_rootcheck_update_cache_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_rootcheck_update_succcess, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_rootcheck_delete_cache_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_rootcheck_delete_success, setup_wdb, teardown_wdb) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_syscollector.c b/src/unit_tests/wazuh_db/test_wdb_syscollector.c deleted file mode 100644 index 0bd6e3c143d..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_syscollector.c +++ /dev/null @@ -1,5255 +0,0 @@ -/* - * Wazuh SQLite integration - * Copyright (C) 2015, Wazuh Inc. - * July 4, 2022. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../external/sqlite/sqlite3.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_agents_wrappers.h" -#include "../headers/os_err.h" - -static int test_setup(void **state) { - wdb_t *data = NULL; - - os_calloc(1, sizeof(wdb_t), data); - *state = data; - return 0; -} - -static int test_teardown(void **state) { - wdb_t *data = (wdb_t *)*state; - os_free(data); - return 0; -} - -#define ALLOW_ZERO true -#define NOT_ALLOW_ZERO false -#define ALLOW_OVER_ONEHUNDRED true -#define NOT_ALLOW_OVER_ONEHUNDRED false - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -/* setup/teardown */ -int setup_wdb(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("000",init_data->wdb->id); - os_calloc(256,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - init_data->wdb->stmt[0] = (sqlite3_stmt*)1; - init_data->wdb->transaction = 0; - *state = init_data; - return 0; -} - -int teardown_wdb(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - -static void wdb_syscollector_processes_save2_fail(void) { - int i = 0; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "1"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "name"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "state"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "cmd"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "argvs"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "euser"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "ruser"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "suser"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "egroup"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "rgroup"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "sgroup"); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "fgroup"); - for (i = 0; i < 13; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_process_save(): cannot begin transaction"); -} - -static void wdb_syscollector_processes_save2_success(cJSON *attribute) { - int i = 0; - - for (i = 0; i < 4; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - for (i = 0; i < 3; i++) { - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - } - - for (i = 0; i < 9; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - for (i = 0; i < 13; i++) { - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - } - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "1"); - will_return(__wrap_cJSON_GetStringValue, "name"); - will_return(__wrap_cJSON_GetStringValue, "state"); - will_return(__wrap_cJSON_GetStringValue, "cmd"); - will_return(__wrap_cJSON_GetStringValue, "argvs"); - will_return(__wrap_cJSON_GetStringValue, "euser"); - will_return(__wrap_cJSON_GetStringValue, "ruser"); - will_return(__wrap_cJSON_GetStringValue, "suser"); - will_return(__wrap_cJSON_GetStringValue, "egroup"); - will_return(__wrap_cJSON_GetStringValue, "rgroup"); - will_return(__wrap_cJSON_GetStringValue, "sgroup"); - will_return(__wrap_cJSON_GetStringValue, "fgroup"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 7); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 8); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "cmd"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "argvs"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "euser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "ruser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "suser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "egroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "rgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "sgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "fgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 18); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 19); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 20); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 21); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 22); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 23); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 24); - expect_value(__wrap_sqlite3_bind_int64, value, 5294967296); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 25); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 26); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 27); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 28); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 29); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 30); - expect_value(__wrap_sqlite3_bind_int, value, 123); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 31); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -static void wdb_syscollector_package_save2_fail() { - int i = 0; - - for (i = 0; i < 16; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "format"); - will_return(__wrap_cJSON_GetStringValue, "name"); - will_return(__wrap_cJSON_GetStringValue, "priority"); - will_return(__wrap_cJSON_GetStringValue, "groups"); - will_return(__wrap_cJSON_GetStringValue, "vendor"); - will_return(__wrap_cJSON_GetStringValue, "install_time"); - will_return(__wrap_cJSON_GetStringValue, "version"); - will_return(__wrap_cJSON_GetStringValue, "architecture"); - will_return(__wrap_cJSON_GetStringValue, "multiarch"); - will_return(__wrap_cJSON_GetStringValue, "source"); - will_return(__wrap_cJSON_GetStringValue, "description"); - will_return(__wrap_cJSON_GetStringValue, "location"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_save(): cannot begin transaction"); -} - -static void wdb_syscollector_package_save2_success(cJSON *attribute) { - int i = 0; - - for (i = 0; i < 5; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - - for (i = 0; i < 10; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "format"); - will_return(__wrap_cJSON_GetStringValue, "name"); - will_return(__wrap_cJSON_GetStringValue, "priority"); - will_return(__wrap_cJSON_GetStringValue, "groups"); - will_return(__wrap_cJSON_GetStringValue, "vendor"); - will_return(__wrap_cJSON_GetStringValue, "install_time"); - will_return(__wrap_cJSON_GetStringValue, "version"); - will_return(__wrap_cJSON_GetStringValue, "architecture"); - will_return(__wrap_cJSON_GetStringValue, "multiarch"); - will_return(__wrap_cJSON_GetStringValue, "source"); - will_return(__wrap_cJSON_GetStringValue, "description"); - will_return(__wrap_cJSON_GetStringValue, "location"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "priority"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "groups"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 987); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "install_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "multiarch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "source"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "description"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "location"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -static void wdb_syscollector_hotfix_save2_fail(void) { - int i = 0; - - for (i = 0; i < 3; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "hotfix"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hotfix_save(): cannot begin transaction"); -} - -static void wdb_syscollector_hotfix_save2_success(void) { - int i = 0; - - for (i = 0; i < 3; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "hotfix"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "hotfix"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -static void wdb_syscollector_port_save2_fail(void) { - int i = 0; - - for (i = 0; i < 14; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "protocol"); - will_return(__wrap_cJSON_GetStringValue, "local_ip"); - will_return(__wrap_cJSON_GetStringValue, "remote_ip"); - will_return(__wrap_cJSON_GetStringValue, "state"); - will_return(__wrap_cJSON_GetStringValue, "process"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_port_save(): cannot begin transaction"); -} - -static void wdb_syscollector_port_save2_success(cJSON *attribute) { - int i = 0; - - for (i = 0; i < 3; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - for (i = 0; i < 4; i++) { - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - } - - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - - for (i = 0; i < 3; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "protocol"); - will_return(__wrap_cJSON_GetStringValue, "local_ip"); - will_return(__wrap_cJSON_GetStringValue, "remote_ip"); - will_return(__wrap_cJSON_GetStringValue, "state"); - will_return(__wrap_cJSON_GetStringValue, "process"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "protocol"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "local_ip"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 541); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "remote_ip"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 7); - expect_value(__wrap_sqlite3_bind_int, value, 541); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 8); - expect_value(__wrap_sqlite3_bind_int, value, 541); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 9); - expect_value(__wrap_sqlite3_bind_int, value, 541); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 5294967296); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 12); - expect_value(__wrap_sqlite3_bind_int, value, 541); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "process"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -static void wdb_syscollector_netproto_save2_fail(void) { - int i = 0; - - for (i = 0; i < 7;i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "iface"); - will_return(__wrap_cJSON_GetStringValue, "gateway"); - will_return(__wrap_cJSON_GetStringValue, "type"); - will_return(__wrap_cJSON_GetStringValue, "dhcp"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netproto_save(): cannot begin transaction"); -} - -static void wdb_syscollector_netproto_save2_success(cJSON *attribute) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, "iface"); - will_return(__wrap_cJSON_GetStringValue, "ipv6"); - will_return(__wrap_cJSON_GetStringValue, "gateway"); - will_return(__wrap_cJSON_GetStringValue, "dhcp"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv6"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "gateway"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "dhcp"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 6); - expect_value(__wrap_sqlite3_bind_int64, value, 654); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -static void wdb_syscollector_netaddr_save2_fail(void) { - int i = 0; - - for (i = 0; i < 7; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "iface"); - will_return(__wrap_cJSON_GetStringValue, "address"); - will_return(__wrap_cJSON_GetStringValue, "netmask"); - will_return(__wrap_cJSON_GetStringValue, "broadcast"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netaddr_save(): cannot begin transaction"); -} - -static void wdb_syscollector_netaddr_save2_success(cJSON *attribute) { - int i = 0; - - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - - for (i = 0; i < 5; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "iface"); - will_return(__wrap_cJSON_GetStringValue, "address"); - will_return(__wrap_cJSON_GetStringValue, "netmask"); - will_return(__wrap_cJSON_GetStringValue, "broadcast"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv6"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "address"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "netmask"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "broadcast"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - -} - -static void wdb_syscollector_netinfo_save2_fail(void) { - int i = 0; - - for (i = 0; i < 17; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "name"); - will_return(__wrap_cJSON_GetStringValue, "adapter"); - will_return(__wrap_cJSON_GetStringValue, "type"); - will_return(__wrap_cJSON_GetStringValue, "state"); - will_return(__wrap_cJSON_GetStringValue, "mac"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_save(): cannot begin transaction"); -} - -static void wdb_syscollector_netinfo_save2_success(cJSON *attribute) { - int i = 0; - - for (i = 0; i < 5; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - for (i = 0; i < 8; i++) { - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - } - - will_return(__wrap_cJSON_GetObjectItem, NULL); - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "name"); - will_return(__wrap_cJSON_GetStringValue, "adapter"); - will_return(__wrap_cJSON_GetStringValue, "type"); - will_return(__wrap_cJSON_GetStringValue, "state"); - will_return(__wrap_cJSON_GetStringValue, "mac"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - will_return(__wrap_cJSON_GetStringValue, "item_id"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "adapter"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "type"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 4294967295); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "mac"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 9); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 11); - expect_value(__wrap_sqlite3_bind_int64, value, 4294967295); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 12); - expect_value(__wrap_sqlite3_bind_int64, value, 4294967295); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 13); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 14); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 15); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 16); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -static void wdb_syscollector_hwinfo_save2_fail(void) { - int i = 0; - - for (i = 0; i < 9; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "board_serial"); - will_return(__wrap_cJSON_GetStringValue, "cpu_name"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hardware_save(): cannot begin transaction"); -} - -static void wdb_syscollector_hwinfo_save2_success(cJSON *attribute) { - int i = 0; - - for (i = 0; i < 3; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - for (i = 0; i < 5; i++) { - will_return(__wrap_cJSON_GetObjectItem, 1); - will_return(__wrap_cJSON_GetObjectItem, attribute); - } - - will_return(__wrap_cJSON_GetObjectItem, NULL); - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "board_serial"); - will_return(__wrap_cJSON_GetStringValue, "cpu_name"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "board_serial"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "cpu_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 7); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_double, index, 6); - expect_value(__wrap_sqlite3_bind_double, value, 1.5); - will_return(__wrap_sqlite3_bind_double, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 7); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 8); - expect_value(__wrap_sqlite3_bind_int64, value, 7); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int, index, 9); - expect_value(__wrap_sqlite3_bind_int, value, 7); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); -} - -static void wdb_syscollector_osinfo_save2_fail(void) { - int i = 0; - - for (i = 0; i < 17; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "hostname"); - will_return(__wrap_cJSON_GetStringValue, "architecture"); - will_return(__wrap_cJSON_GetStringValue, "os_name"); - will_return(__wrap_cJSON_GetStringValue, "os_version"); - will_return(__wrap_cJSON_GetStringValue, "os_codename"); - will_return(__wrap_cJSON_GetStringValue, "os_major"); - will_return(__wrap_cJSON_GetStringValue, "os_minor"); - will_return(__wrap_cJSON_GetStringValue, "os_patch"); - will_return(__wrap_cJSON_GetStringValue, "os_build"); - will_return(__wrap_cJSON_GetStringValue, "os_platform"); - will_return(__wrap_cJSON_GetStringValue, "sysname"); - will_return(__wrap_cJSON_GetStringValue, "release"); - will_return(__wrap_cJSON_GetStringValue, "version"); - will_return(__wrap_cJSON_GetStringValue, "os_release"); - will_return(__wrap_cJSON_GetStringValue, "os_display_version"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_osinfo_save(): cannot begin transaction"); -} - -void test_wdb_netinfo_save_insertion_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_insert(): cannot cache statement"); - - output = wdb_netinfo_save(data, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, false); - assert_int_equal(output, -1); -} - -/* Tests wdb_netinfo_insert */ -void test_wdb_netinfo_insert_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_insert(): cannot cache statement"); - - output = wdb_netinfo_insert(data, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, false); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_insert_default_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "adapter"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "type"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "mac"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 9); - expect_value(__wrap_sqlite3_bind_int64, value, 2); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 3); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 11); - expect_value(__wrap_sqlite3_bind_int64, value, 4); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 12); - expect_value(__wrap_sqlite3_bind_int64, value, 5); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 13); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 14); - expect_value(__wrap_sqlite3_bind_int64, value, 7); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 15); - expect_value(__wrap_sqlite3_bind_int64, value, 8); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 16); - expect_value(__wrap_sqlite3_bind_int64, value, 9); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - output = wdb_netinfo_insert(data, "scan_id", "scan_time", "name", "adapter", "type", "state", 1, "mac", 2, 3, 4, 5, 6, 7, 8, 9, "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_insert_sql_constraint_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "adapter"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "type"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "mac"); - will_return(__wrap_sqlite3_bind_text, 0); - - - expect_value(__wrap_sqlite3_bind_int64, index, 9); - expect_value(__wrap_sqlite3_bind_int64, value, 2); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 3); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 11); - expect_value(__wrap_sqlite3_bind_int64, value, 4); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 12); - expect_value(__wrap_sqlite3_bind_int64, value, 5); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 13); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 14); - expect_value(__wrap_sqlite3_bind_int64, value, 7); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 15); - expect_value(__wrap_sqlite3_bind_int64, value, 8); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 16); - expect_value(__wrap_sqlite3_bind_int64, value, 9); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - // expect_sqlite3_step_call(SQLITE_CONSTRAINT); - will_return(__wrap_wdb_step, SQLITE_CONSTRAINT); - will_return(__wrap_sqlite3_errmsg, "DUPLICATE"); - will_return(__wrap_sqlite3_errmsg, "DUPLICATE"); - expect_string(__wrap__merror, formatted_msg, "SQLite: DUPLICATE"); - - output = wdb_netinfo_insert(data, "scan_id", "scan_time", "name", "adapter", "type", "state", 1, "mac", 2, 3, 4, 5, 6, 7, 8, 9, "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_insert_sql_constraint_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "adapter"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "type"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "mac"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 9); - expect_value(__wrap_sqlite3_bind_int64, value, 2); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 3); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 11); - expect_value(__wrap_sqlite3_bind_int64, value, 4); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 12); - expect_value(__wrap_sqlite3_bind_int64, value, 5); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 13); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 14); - expect_value(__wrap_sqlite3_bind_int64, value, 7); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 15); - expect_value(__wrap_sqlite3_bind_int64, value, 8); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 16); - expect_value(__wrap_sqlite3_bind_int64, value, 9); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_CONSTRAINT); - will_return(__wrap_sqlite3_errmsg, "UNIQUE"); - will_return(__wrap_sqlite3_errmsg, "UNIQUE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: UNIQUE"); - - output = wdb_netinfo_insert(data, "scan_id", "scan_time", "name", "adapter", "type", "state", 1, "mac", 2, 3, 4, 5, 6, 7, 8, 9, "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -void test_wdb_netinfo_insert_sql_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "adapter"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "type"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "mac"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 9); - expect_value(__wrap_sqlite3_bind_int64, value, 2); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 3); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 11); - expect_value(__wrap_sqlite3_bind_int64, value, 4); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 12); - expect_value(__wrap_sqlite3_bind_int64, value, 5); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 13); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 14); - expect_value(__wrap_sqlite3_bind_int64, value, 7); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 15); - expect_value(__wrap_sqlite3_bind_int64, value, 8); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 16); - expect_value(__wrap_sqlite3_bind_int64, value, 9); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_netinfo_insert(data, "scan_id", "scan_time", "name", "adapter", "type", "state", 1, "mac", 2, 3, 4, 5, 6, 7, 8, 9, "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -/* Test wdb_netproto_insert */ -void test_wdb_netproto_insert_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netproto_insert(): cannot cache statement"); - - output = wdb_netproto_insert(data, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, false); - assert_int_equal(output, -1); -} - -void test_wdb_netproto_insert_default_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv4"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "gateway"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "dhcp"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 6); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - output = wdb_netproto_insert(data, "scan_id", "iface", WDB_NETADDR_IPV4, "gateway", "dhcp", 6, "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_netproto_insert_sql_constraint_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv4"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "gateway"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "dhcp"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 6); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_CONSTRAINT); - will_return(__wrap_sqlite3_errmsg, "DUPLICATED"); - will_return(__wrap_sqlite3_errmsg, "DUPLICATED"); - expect_string(__wrap__merror, formatted_msg, "SQLite: DUPLICATED"); - - output = wdb_netproto_insert(data, "scan_id", "iface", WDB_NETADDR_IPV4, "gateway", "dhcp", 6, "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_netproto_insert_sql_constraint_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv4"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "gateway"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "dhcp"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 6); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_CONSTRAINT); - will_return(__wrap_sqlite3_errmsg, "UNIQUE"); - will_return(__wrap_sqlite3_errmsg, "UNIQUE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: UNIQUE"); - - output = wdb_netproto_insert(data, "scan_id", "iface", WDB_NETADDR_IPV4, "gateway", "dhcp", 6, "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -void test_wdb_netproto_insert_sql_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv4"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "gateway"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "dhcp"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int64, index, 6); - expect_value(__wrap_sqlite3_bind_int64, value, 6); - will_return(__wrap_sqlite3_bind_int64, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_netproto_insert(data, "scan_id", "iface", WDB_NETADDR_IPV4, "gateway", "dhcp", 6, "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -/* Test wdb_netaddr_save */ -void test_wdb_netaddr_save_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netaddr_save(): cannot begin transaction"); - - output = wdb_netaddr_save(data, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, false); - assert_int_equal(output, -1); -} - -void test_wdb_netaddr_save_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netaddr_insert(): cannot cache statement"); - - output = wdb_netaddr_save(data, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, false); - assert_int_equal(output, -1); -} - -void test_wdb_netaddr_save_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv6"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "address"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "netmask"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "broadcast"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_netaddr_save(data, "scan_id", "iface", 1, "address", "netmask", "broadcast", "checksum", "item_id", true); - assert_int_equal(output, 0); -} - -/* Test wdb_netaddr_insert */ -void test_wdb_netaddr_insert_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netaddr_insert(): cannot cache statement"); - - output = wdb_netaddr_insert(data, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, false); - assert_int_equal(output, -1); -} - -void test_wdb_netaddr_insert_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "iface"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "ipv4"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "address"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "netmask"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "broadcast"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - output = wdb_netaddr_insert(data, "scan_id", "iface", WDB_NETADDR_IPV4, "address", "netmask", "broadcast", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -/* Test wdb_netinfo_delete */ -void test_wdb_netinfo_delete_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_delete(): cannot begin transaction"); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_delete_sys_netiface_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_delete(): cannot cache statement"); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_delete_sys_netiface_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_netiface' table: ERROR"); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_delete_sys_netproto_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_delete(): cannot cache statement"); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_delete_sys_netproto_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_netproto' table: ERROR"); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_delete_sys_netaddr_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_delete(): cannot cache statement"); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_delete_sys_netaddr_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_netaddr' table: ERROR"); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_netinfo_delete_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_netinfo_delete(data, "scan_id"); - assert_int_equal(output, 0); -} - -/* Test wdb_hotfix_delete */ -void test_wdb_hotfix_delete_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hotfix_delete(): cannot begin transaction"); - - output = wdb_hotfix_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_hotfix_delete_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hotfix_delete(): cannot cache statement"); - - output = wdb_hotfix_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_hotfix_delete_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_hotfixes' table: ERROR"); - - output = wdb_hotfix_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_hotfix_delete_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_hotfix_delete(data, "scan_id"); - assert_int_equal(output, 0); -} - -/* Test wdb_osinfo_save */ -void test_wdb_osinfo_save_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_osinfo_save(): cannot begin transaction"); - - output = wdb_osinfo_save(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", "release", "version", "os_release", "os_display_version", "checksum", false); - assert_int_equal(output, -1); -} - - -void test_wdb_osinfo_save_retrieve_osinfo_type_reference_fail(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "hostname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_codename"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_major"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_minor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_patch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_build"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_platform"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "sysname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_display_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 19); - expect_any(__wrap_sqlite3_bind_text, buffer); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_osinfo_save(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", - "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", - "release", "version", "os_release", "os_display_version", "checksum", false); - assert_int_equal(output, 0); -} - -void test_wdb_osinfo_save_retrieve_osinfo_ok(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - - will_return(__wrap_wdb_begin2, 0); - - - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "hostname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_codename"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_major"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_minor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_patch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_build"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_platform"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "sysname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_display_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 19); - expect_any(__wrap_sqlite3_bind_text, buffer); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_osinfo_save(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", - "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", - "release", "version", "os_release", "os_display_version", "checksum", false); - assert_int_equal(output, 0); -} - -void test_wdb_osinfo_save_cache_fail(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - char debug_msg[OS_SIZE_512] = {0}; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, -1); - snprintf(debug_msg, OS_SIZE_512, "at wdb_osinfo_save(): cannot cache statement (%d)", WDB_STMT_OSINFO_DEL); - expect_string(__wrap__mdebug1, formatted_msg, debug_msg); - - output = wdb_osinfo_save(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", - "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", - "release", "version", "os_release", "os_display_version", "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_osinfo_save_sql_fail(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_osinfo' table: ERROR"); - - output = wdb_osinfo_save(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", - "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", - "release", "version", "os_release", "os_display_version", "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_osinfo_save_insert_fail(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - - will_return(__wrap_wdb_begin2, 0); - - - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_osinfo_insert(): cannot cache statement"); - - output = wdb_osinfo_save(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", - "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", - "release", "version", "os_release", "os_display_version", "checksum", false); - assert_int_equal(output, -1); -} - -/* Test wdb_osinfo_insert */ -void test_wdb_osinfo_insert_cache_fail(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_osinfo_insert(): cannot cache statement"); - - os_sha1 digest = "hexdigest"; - output = - wdb_osinfo_insert(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", - "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", - "release", "version", "os_release", "os_display_version", "checksum", false, digest); - assert_int_equal(output, -1); -} - -void test_wdb_osinfo_insert_sql_fail(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - os_sha1 digest = "hexdigest"; - - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "hostname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_codename"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_major"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_minor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_patch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_build"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_platform"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "sysname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_display_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 19); - expect_string(__wrap_sqlite3_bind_text, buffer, digest); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - output = - wdb_osinfo_insert(data, "scan_id", "scan_time", "hostname", "architecture", "os_name", "os_version", - "os_codename", "os_major", "os_minor", "os_patch", "os_build", "os_platform", "sysname", - "release", "version", "os_release", "os_display_version", "checksum", false, digest); - assert_int_equal(output, -1); -} - -/* Test wdb_package_save */ -void test_wdb_package_save_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_save(): cannot begin transaction"); - - output = wdb_package_save(data, "scan_id", "scan_time", "format", "name", "priority", "section", 0, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_package_save_insert_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_insert(): cannot cache statement"); - - output = wdb_package_save(data, "scan_id", "scan_time", "format", "name", "priority", "section", 0, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_package_save_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "priority"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "section"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_null, index, 7); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "install_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "multiarch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "source"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "description"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "location"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_package_save(data, "scan_id", "scan_time", "format", "name", "priority", "section", -1, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -/* Test wdb_package_insert */ -void test_wdb_package_insert_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_insert(): cannot cache statement"); - - output = wdb_package_insert(data, "scan_id", "scan_time", "format", "name", "priority", "section", 0, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_package_insert_default_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "priority"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "section"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "install_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "multiarch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "source"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "description"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "location"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - - output = wdb_package_insert(data, "scan_id", "scan_time", "format", "name", "priority", "section", 0, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_package_insert_sql_constraint_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "priority"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "section"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "install_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "multiarch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "source"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "description"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "location"); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_CONSTRAINT); - will_return(__wrap_sqlite3_errmsg, "DUPLICATED"); - will_return(__wrap_sqlite3_errmsg, "DUPLICATED"); - expect_string(__wrap__merror, formatted_msg, "SQLite: DUPLICATED"); - - output = wdb_package_insert(data, "scan_id", "scan_time", "format", "name", "priority", "section", 0, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_package_insert_sql_constraint_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "priority"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "section"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "install_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "multiarch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "source"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "description"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "location"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_CONSTRAINT); - will_return(__wrap_sqlite3_errmsg, "UNIQUE"); - will_return(__wrap_sqlite3_errmsg, "UNIQUE"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: UNIQUE"); - - output = wdb_package_insert(data, "scan_id", "scan_time", "format", "name", "priority", "section", 0, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -void test_wdb_package_insert_sql_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "priority"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "section"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 0); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "install_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "multiarch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "source"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "description"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "location"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_package_insert(data, "scan_id", "scan_time", "format", "name", "priority", "section", 0, "vendor", "install_time", "version", "architecture", "multiarch", "source", "description", "location", "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -/* Test wdb_hotfix_save */ -void test_wdb_hotfix_save_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hotfix_save(): cannot begin transaction"); - - output = wdb_hotfix_save(data, "scan_id", "scan_time", "hotfix", "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_hotfix_save_insert_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hotfix_insert(): cannot cache statement"); - - output = wdb_hotfix_save(data, "scan_id", "scan_time", "hotfix", "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_hotfix_save_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "hotfix"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_hotfix_save(data, "scan_id", "scan_time", "hotfix", "checksum", false); - assert_int_equal(output, 0); -} - -/* Test wdb_package_update */ -void test_wdb_package_update_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_update(): cannot begin transaction"); - - output = wdb_package_update(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_update_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_update(): cannot cache get statement"); - - output = wdb_package_update(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_update_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - - - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Unable to update the 'sys_programs' table: ERROR"); - - - output = wdb_package_update(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_update_loop_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "cpe"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "msu_name"); - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "format"); - expect_value(__wrap_sqlite3_column_text, iCol, 3); - will_return(__wrap_sqlite3_column_text, "name"); - expect_value(__wrap_sqlite3_column_text, iCol, 4); - will_return(__wrap_sqlite3_column_text, "vendor"); - expect_value(__wrap_sqlite3_column_text, iCol, 5); - will_return(__wrap_sqlite3_column_text, "version"); - expect_value(__wrap_sqlite3_column_text, iCol, 6); - will_return(__wrap_sqlite3_column_text, "arch"); - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_update(): cannot cache update statement"); - - output = wdb_package_update(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_update_loop_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "cpe"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "msu_name"); - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "format"); - expect_value(__wrap_sqlite3_column_text, iCol, 3); - will_return(__wrap_sqlite3_column_text, "name"); - expect_value(__wrap_sqlite3_column_text, iCol, 4); - will_return(__wrap_sqlite3_column_text, "vendor"); - expect_value(__wrap_sqlite3_column_text, iCol, 5); - will_return(__wrap_sqlite3_column_text, "version"); - expect_value(__wrap_sqlite3_column_text, iCol, 6); - will_return(__wrap_sqlite3_column_text, "arch"); - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "cpe"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "msu_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "arch"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Unable to update the 'sys_programs' table: ERROR"); - - output = wdb_package_update(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_update_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - expect_value(__wrap_sqlite3_column_text, iCol, 0); - will_return(__wrap_sqlite3_column_text, "cpe"); - expect_value(__wrap_sqlite3_column_text, iCol, 1); - will_return(__wrap_sqlite3_column_text, "msu_name"); - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "format"); - expect_value(__wrap_sqlite3_column_text, iCol, 3); - will_return(__wrap_sqlite3_column_text, "name"); - expect_value(__wrap_sqlite3_column_text, iCol, 4); - will_return(__wrap_sqlite3_column_text, "vendor"); - expect_value(__wrap_sqlite3_column_text, iCol, 5); - will_return(__wrap_sqlite3_column_text, "version"); - expect_value(__wrap_sqlite3_column_text, iCol, 6); - will_return(__wrap_sqlite3_column_text, "arch"); - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "cpe"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "msu_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "format"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "vendor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "arch"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_package_update(data, "scan_id"); - assert_int_equal(output, 0); -} - -/* Test wdb_package_delete */ -void test_wdb_package_delete_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_delete(): cannot begin transaction"); - - output = wdb_package_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_delete_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_delete(): cannot cache statement"); - - output = wdb_package_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_delete_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_programs' table: ERROR"); - - output = wdb_package_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_package_delete_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_package_delete(data, "scan_id"); - assert_int_equal(output, 0); -} - -/* Test wdb_hardware_save */ -void test_wdb_hardware_save_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hardware_save(): cannot begin transaction"); - - output = wdb_hardware_save(data, "scan_id", "scan_time", "serial", "cpu_name", 4, 2900, 8192, 6144, 2048, "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_hardware_save_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hardware_save(): cannot cache statement"); - - output = wdb_hardware_save(data, "scan_id", "scan_time", "serial", "cpu_name", 4, 2900, 8192, 6144, 2048, "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_hardware_save_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_hwinfo' table: ERROR"); - - output = wdb_hardware_save(data, "scan_id", "scan_time", "serial", "cpu_name", 4, 2900, 8192, 6144, 2048, "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_hardware_save_insert_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hardware_insert(): cannot cache statement"); - - output = wdb_hardware_save(data, "scan_id", "scan_time", "serial", "cpu_name", 4, 2900, 8192, 6144, 2048, "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_hardware_save_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "serial"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "cpu_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_null, index, 5); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 6); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 7); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 8); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 9); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_hardware_save(data, "scan_id", "scan_time", "serial", "cpu_name", 0, 0, 0, 0, 0, "checksum", false); - assert_int_equal(output, 0); -} - -/* Test wdb_hardware_insert */ -void test_wdb_hardware_insert_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hardware_insert(): cannot cache statement"); - - output = wdb_hardware_insert(data, "scan_id", "scan_time", "serial", "cpu_name", 4, 2900, 8192, 6144, 2048, "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_hardware_insert_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "serial"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "cpu_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 4); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_double, index, 6); - expect_value(__wrap_sqlite3_bind_double, value, 2900); - will_return(__wrap_sqlite3_bind_double, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 7); - expect_value(__wrap_sqlite3_bind_int64, value, 8192); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 8); - expect_value(__wrap_sqlite3_bind_int64, value, 6144); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int, index, 9); - expect_value(__wrap_sqlite3_bind_int, value, 100); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - output = wdb_hardware_insert(data, "scan_id", "scan_time", "serial", "cpu_name", 4, 2900, 8192, 6144, 100, "checksum", false); - assert_int_equal(output, -1); -} - -/* Test wdb_port_save */ -void test_wdb_port_save_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_port_save(): cannot begin transaction"); - - output = wdb_port_save(data, "scan_id", "scan_time", "protocol", "local_ip", 541, "remote_ip", 541, 10, 10, 1, "state", 32545, "process", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_port_save_insert_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_port_insert(): cannot cache statement"); - - output = wdb_port_save(data, "scan_id", "scan_time", "protocol", "local_ip", 541, "remote_ip", 541, 10, 10, 1, "state", 32545, "process", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_port_save_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "protocol"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "local_ip"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 541); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "remote_ip"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 7); - expect_value(__wrap_sqlite3_bind_int, value, 541); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 8); - expect_value(__wrap_sqlite3_bind_int, value, 10); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 9); - expect_value(__wrap_sqlite3_bind_int, value, 10); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 5294967296); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 12); - expect_value(__wrap_sqlite3_bind_int, value, 32545); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "process"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_port_save(data, "scan_id", "scan_time", "protocol", "local_ip", 541, "remote_ip", 541, 10, 10, 5294967296, "state", 32545, "process", "checksum", "item_id", false); - assert_int_equal(output, 0); -} - -/* Test wdb_port_insert */ -void test_wdb_port_insert_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_port_insert(): cannot cache statement"); - - output = wdb_port_insert(data, "scan_id", "scan_time", "protocol", "local_ip", 1, "remote_ip", 1, 1, 1, 1, "state", 1, "process", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -void test_wdb_port_insert_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "protocol"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "local_ip"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "remote_ip"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_null, index, 7); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 8); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 9); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 10); - expect_value(__wrap_sqlite3_bind_int64, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_null, index, 12); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "process"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "item_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - output = wdb_port_insert(data, "scan_id", "scan_time", "protocol", "local_ip", 1, "remote_ip", -1, -1, -1, 1, "state", -1, "process", "checksum", "item_id", false); - assert_int_equal(output, -1); -} - -/* Test wdb_port_delete */ -void test_wdb_port_delete_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_port_delete(): cannot begin transaction"); - - output = wdb_port_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_port_delete_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_port_delete(): cannot cache statement"); - - output = wdb_port_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_port_delete_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_ports' table: ERROR"); - - output = wdb_port_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_port_delete_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_port_delete(data, "scan_id"); - assert_int_equal(output, 0); -} - -/* Test wdb_process_save */ -void test_wdb_process_save_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_process_save(): cannot begin transaction"); - - output = wdb_process_save(data, "scan_id", "scan_time", 1, "name", "state", 1, 1, 1, "cmd", "argvs", "euser", "ruser", "suser", "egroup", "rgroup", "sgroup", "fgroup", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 65, 2, 2, "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_process_save_insert_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_process_insert(): cannot cache statement"); - - output = wdb_process_save(data, "scan_id", "scan_time", 1, "name", "state", 1, 1, 1, "cmd", "argvs", "euser", "ruser", "suser", "egroup", "rgroup", "sgroup", "fgroup", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 65, 2, 2, "checksum", false); - assert_int_equal(output, -1); -} - -void test_wdb_process_save_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 6); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 7); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 8); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "cmd"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "argvs"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "euser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "ruser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "suser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "egroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "rgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "sgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "fgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 18); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 19); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 20); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 21); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 22); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 23); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int64, 0); - expect_value(__wrap_sqlite3_bind_int64, index, 24); - expect_value(__wrap_sqlite3_bind_int64, value, 5294967296); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 25); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 26); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 27); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 28); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 29); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_int, index, 30); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 31); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_process_save(data, "scan_id", "scan_time", 1, "name", "state", 1, 1, 1, "cmd", "argvs", "euser", "ruser", "suser", "egroup", "rgroup", "sgroup", "fgroup", 1, 1, 1, 1, 1, 1, 5294967296, 1, 1, 1, 1, 1, 1, "checksum", false); - assert_int_equal(output, 0); -} - -void test_wdb_process_insert_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_int, index, 3); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "state"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_null, index, 6); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 7); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 8); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "cmd"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "argvs"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "euser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "ruser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "suser"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "egroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "rgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "sgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "fgroup"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_null, index, 18); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_int, index, 19); - expect_value(__wrap_sqlite3_bind_int, value, 1); - will_return(__wrap_sqlite3_bind_int, 0); - expect_value(__wrap_sqlite3_bind_null, index, 20); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 21); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 22); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 23); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 24); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 25); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 26); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 27); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 28); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 29); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_null, index, 30); - will_return(__wrap_sqlite3_bind_null, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 31); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - output = wdb_process_insert(data, "scan_id", "scan_time", 1, "name", "state", -1, -1, -1, "cmd", "argvs", "euser", "ruser", "suser", "egroup", "rgroup", "sgroup", "fgroup", -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "checksum", false); - assert_int_equal(output, -1); -} - -/* Test wdb_process_delete */ -void test_wdb_process_delete_transaction_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_process_delete(): cannot begin transaction"); - - output = wdb_process_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_process_delete_cache_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 1; - will_return(__wrap_wdb_stmt_cache, -1); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_process_delete(): cannot cache statement"); - - output = wdb_process_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_process_delete_sql_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, 1); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "Deleting old information from 'sys_processes' table: ERROR"); - - output = wdb_process_delete(data, "scan_id"); - assert_int_equal(output, -1); -} - -void test_wdb_process_delete_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - data->transaction = 0; - will_return(__wrap_wdb_begin2, 0); - will_return(__wrap_wdb_stmt_cache, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_id"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - output = wdb_process_delete(data, "scan_id"); - assert_int_equal(output, 0); -} - -/* Test wdb_syscollector_save2 */ -void test_wdb_syscollector_save2_parser_json_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, NULL); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_syscollector_save2(): no payload"); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PROCESSES, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_get_attributes_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, NULL); - expect_function_call(__wrap_cJSON_Delete); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_syscollector_save2(): no attributes"); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PROCESSES, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, 0, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_processes_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_processes_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PROCESSES, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_processes_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - cJSON attribute = {0}; - - attribute.valueint = 123; - attribute.valuedouble = 5294967296; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_processes_save2_success(&attribute); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PROCESSES, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_package_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_package_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PACKAGES, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_package_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - cJSON attribute = {0}; - - attribute.valueint = 987; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_package_save2_success(&attribute); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PACKAGES, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_hotfix_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_hotfix_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_HOTFIXES, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_hotfix_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_hotfix_save2_success(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_HOTFIXES, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_port_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_port_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PORTS, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_port_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - cJSON attribute = {0}; - - attribute.valueint = 541; - attribute.valuedouble = 5294967296; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_port_save2_success(&attribute); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_PORTS, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_netproto_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_netproto_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_NETPROTO, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_netproto_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - cJSON attribute = {0}; - - attribute.valueint = 654; - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_netproto_save2_success(&attribute); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_NETPROTO, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_netaddr_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_netaddr_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_NETADDRESS, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_netaddr_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - cJSON attribute = {0}; - - attribute.valueint = 1; - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_netaddr_save2_success(&attribute); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_NETADDRESS, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_netinfo_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_netinfo_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_NETINFO, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_netinfo_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - cJSON attribute = {0}; - - attribute.valueint = 1; - attribute.valuedouble = 4294967295; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_netinfo_save2_success(&attribute); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_NETINFO, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_hwinfo_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_hwinfo_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_HWINFO, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_hwinfo_success(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - cJSON attribute = {0}; - - attribute.valueint = 7; - attribute.valuedouble = 1.5; - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_hwinfo_save2_success(&attribute); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_HWINFO, NULL); - assert_int_equal(output, 0); -} - -void test_wdb_syscollector_save2_osinfo_fail(void **state) { - int output = 0; - wdb_t *data = (wdb_t *)*state; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - data->transaction = 0; - wdb_syscollector_osinfo_save2_fail(); - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_OSINFO, NULL); - assert_int_equal(output, -1); -} - -void test_wdb_syscollector_save2_osinfo_success(void ** state) { - int output = 0; - wdb_t * data = (wdb_t *) *state; - - data->transaction = 0; - - will_return(__wrap_cJSON_Parse, 1); - will_return(__wrap_cJSON_GetObjectItem, 1); - - for (int i = 0; i < 17; i++) { - will_return(__wrap_cJSON_GetObjectItem, NULL); - } - - will_return(__wrap_cJSON_GetStringValue, "scan_time"); - will_return(__wrap_cJSON_GetStringValue, "hostname"); - will_return(__wrap_cJSON_GetStringValue, "architecture"); - will_return(__wrap_cJSON_GetStringValue, "os_name"); - will_return(__wrap_cJSON_GetStringValue, "os_version"); - will_return(__wrap_cJSON_GetStringValue, "os_codename"); - will_return(__wrap_cJSON_GetStringValue, "os_major"); - will_return(__wrap_cJSON_GetStringValue, "os_minor"); - will_return(__wrap_cJSON_GetStringValue, "os_patch"); - will_return(__wrap_cJSON_GetStringValue, "os_build"); - will_return(__wrap_cJSON_GetStringValue, "os_platform"); - will_return(__wrap_cJSON_GetStringValue, "sysname"); - will_return(__wrap_cJSON_GetStringValue, "release"); - will_return(__wrap_cJSON_GetStringValue, "version"); - will_return(__wrap_cJSON_GetStringValue, "os_release"); - will_return(__wrap_cJSON_GetStringValue, "os_display_version"); - will_return(__wrap_cJSON_GetStringValue, "checksum"); - - will_return(__wrap_wdb_begin2, 0); - - will_return(__wrap_wdb_stmt_cache, 0); - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "0"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, "scan_time"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, "hostname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, "architecture"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 5); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_name"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 6); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_codename"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 8); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_major"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 9); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_minor"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 10); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_patch"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 11); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_build"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 12); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_platform"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 13); - expect_string(__wrap_sqlite3_bind_text, buffer, "sysname"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 14); - expect_string(__wrap_sqlite3_bind_text, buffer, "release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 15); - expect_string(__wrap_sqlite3_bind_text, buffer, "version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 16); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_release"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 17); - expect_string(__wrap_sqlite3_bind_text, buffer, "os_display_version"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 18); - expect_string(__wrap_sqlite3_bind_text, buffer, "checksum"); - will_return(__wrap_sqlite3_bind_text, 0); - expect_value(__wrap_sqlite3_bind_text, pos, 19); - expect_any(__wrap_sqlite3_bind_text, buffer); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - expect_function_call(__wrap_cJSON_Delete); - - output = wdb_syscollector_save2(data, WDB_SYSCOLLECTOR_OSINFO, NULL); - assert_int_equal(output, 0); -} - -/* test objects */ - -// sys_netinfo -typedef struct netinfo_object { - char *scan_id; - char *scan_time; - char *name; - char *adapter; - char *type; - char *_state; - int64_t mtu; - char *mac; - long tx_packets; - long rx_packets; - int64_t tx_bytes; - int64_t rx_bytes; - long tx_errors; - long rx_errors; - long tx_dropped; - long rx_dropped; - char *checksum; - char *item_id; - bool replace; -} netinfo_object; - -netinfo_object netinfo = { - .scan_id = "0", - .scan_time = "2022/06/29 15:29:45", - .name = "Ethernet 2", - .adapter = "Intel(R) PRO/1000 MT Desktop Adapter #2", - .type = "ethernet", - ._state = "up", - .mtu = 1500, - .mac = "08:00:27:4c:3d:35:", - .tx_packets = 40041, - .rx_packets = 38305, - .tx_bytes = 17929845, - .rx_bytes = 3332226, - .tx_errors = 0, - .rx_errors = 0, - .tx_dropped = 0, - .rx_dropped = 0, - .checksum = "cabec688e047879b0efbf902b2cf6a8f256f5908", - .item_id = "b6add5e98952c1216b6e189197de17c6962ccc74", - .replace = TRUE -}; - -// sys_netproto -typedef struct netproto_object { - char *scan_id; - char *iface; - int type; - char *gateway; - char *dhcp; - int metric; - char *checksum; - char *item_id; - bool replace; -} netproto_object; - -netproto_object netproto = { - .scan_id = "0", - .iface = "Loopback Pseudo-Interface 1", - .type = WDB_NETADDR_IPV4, - .gateway = " ", - .dhcp = "disabled", - .metric = 75, - .checksum = "c8e2003d6e3992ca9900667faa094ae195fbb98f", - .item_id = "e6db7b9f540419ba6258e01fbadd8336d35c8c0a", - .replace = TRUE -}; - -// sys_netaddr -typedef struct netaddr_object { - char *scan_id; - char *iface; - int proto; - char *address; - char *netmask; - char *broadcast; - char *checksum; - char *item_id; - bool replace; -} netaddr_object; - -netaddr_object netaddr = { - .scan_id = "0", - .iface = "Ethernet 2", - .proto = 0, - .address = "192.168.33.210", - .netmask = "255.255.255.0", - .broadcast = "192.168.33.255", - .checksum = "57f25994f150743a56c87cefe773f30b92b351cf", - .item_id = "9a6a01ef2bc8991938550cf826482d78c39050ee", - .replace = TRUE -}; - -// sys_osinfo -typedef struct osinfo_object { - char *scan_id; - char *scan_time; - char *hostname; - char *architecture; - char *os_name; - char *os_version; - char *os_codename; - char *os_major; - char *os_minor; - char *os_patch; - char *os_build; - char *os_platform; - char *sysname; - char *release; - char *version; - char *os_release; - char *os_display_version; - char *checksum; - bool replace; - char *reference; -} osinfo_object; - -osinfo_object osinfo = { - .scan_id = "0", - .scan_time = "2022/06/29 14:58:29", - .hostname = "DESKTOP-8NH6TAI", - .architecture = "x86_64", - .os_name = "Microsoft Windows 11 Enterprise Evaluation", - .os_version = "10.0.22000", - .os_codename = " ", - .os_major = "10", - .os_minor = "0", - .os_patch = " ", - .os_build = "22000", - .os_platform = " ", - .sysname = " ", - .release = " ", - .version = " ", - .os_release = "2009", - .os_display_version = "21H2", - .checksum = "1656514705657068700", - .replace = TRUE, - .reference = "eed7ce92814a61931ff8698ef3e8dea984df7635", -}; - -// sys_package -typedef struct package_object { - char *scan_id; - char *scan_time; - char *format; - char *name; - char *priority; - char * section; - long size; - char *vendor; - char *install_time; - char *version; - char *architecture; - char *multiarch; - char *source; - char *description; - char *location; - char *checksum; - char *item_id; - bool replace; -} package_object; - -package_object package = { - .scan_id = "0", - .scan_time = "2022/06/22 21:20:36", - .format = "win", - .name = "Microsoft SQL Server 2014 (64-bit)", - .priority = " ", - .section = " ", - .size = 12342356, - .vendor = "Microsoft Corporation", - .install_time = " ", - .version = "12", - .architecture = "x86_64", - .multiarch = " ", - .source = " ", - .description = " ", - .location = " ", - .checksum = "2d4009216d12de6cd8c724ee7ea7ac26c9c9a248", - .item_id = "8f5ddd79108614", - .replace = TRUE -}; - -// sys_hotfix -typedef struct hotfix_object { - char *scan_id; - char *scan_time; - char *hotfix; - char *checksum; - bool replace; -} hotfix_object; - -hotfix_object hotfix = { - .scan_id = "0", - .scan_time = "2022/06/29 15:29:45", - .hotfix = "KB982573", - .checksum = "62a01d14af223e0ddeb5a5182e101ebfe1b12007", - .replace = TRUE -}; - -// sys_hardware -typedef struct hardware_object { - char *scan_id; - char *scan_time; - char *serial; - char *cpu_name; - int cpu_cores; - double cpu_mhz; - uint64_t ram_total; - uint64_t ram_free; - int ram_usage; - char *checksum; - bool replace; -} hardware_object; - -hardware_object hardware = { - .scan_id = "0", - .scan_time = "2022/06/29 15:29:43", - .serial = "0", - .cpu_name = "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", - .cpu_cores = 2, - .cpu_mhz = 2592, - .ram_total = 4181100, - .ram_free = 2311016, - .ram_usage = 44, - .checksum = "f3f06f3756c908eee3bbc36391371c7a5fff4f33", - .replace = TRUE -}; - -// sys_port -typedef struct port_object { - char *scan_id; - char *scan_time; - char *protocol; - char *local_ip; - int local_port; - char *remote_ip; - int remote_port; - int tx_queue; - int rx_queue; - long long inode; - char *state; - int pid; - char *process; - char *checksum; - char *item_id; - bool replace; -} port_object; - -port_object port = { - .scan_id = "0", - .scan_time = "2022/06/29 15:26:03", - .protocol = "udp6", - .local_ip = "::", - .local_port = 54958, - .remote_ip = NULL, - .remote_port = 0, - .tx_queue = 0, - .rx_queue = 0, - .inode = 0, - .state = " ", - .pid = 1744, - .process = "svchost.exe", - .checksum = "24641b98af84f613faf490b219daa8eb0afb11d7", - .item_id = "9ec3a0047af3ebeaa72c9501fa09a3ccf53a69a3", - .replace = TRUE, -}; - -// process -typedef struct process_object { - char *scan_id; - char *scan_time; - int pid; - char *name; - char *state; - int ppid; - int utime; - int stime; - char *cmd; - char *argvs; - char *euser; - char *ruser; - char *suser; - char *egroup; - char *rgroup; - char *sgroup; - char *fgroup; - int priority; - int nice; - int size; - int vm_size; - int resident; - int share; - int start_time; - int pgrp; - int session; - int nlwp; - int tgid; - int tty; - int processor; - char *checksum; - bool replace; -} process_object; - -process_object process = { - .scan_id = "0", - .scan_time = "2022/07/04 17:14:07", - .pid = 10480, - .name = "uhssvc.exe", - .state = NULL, - .ppid = 780, - .utime = 0, - .stime = 0, - .cmd = "\\Device\\HarddiskVolume3\\Program Files\\Microsoft Update Health Tools\\uhssvc.exe", - .argvs = NULL, - .euser = NULL, - .ruser = NULL, - .suser = NULL, - .egroup = NULL, - .rgroup = NULL, - .sgroup = NULL, - .fgroup = NULL, - .priority = 8, - .nice = 0, - .size = 1355776, - .vm_size = 7737344, - .resident = 0, - .share = 0, - .start_time = 0, - .pgrp = 0, - .session = 0, - .nlwp = 3, - .tgid = 0, - .tty = 0, - .processor = 0, - .checksum = "4ef6bc09b0d48caec86533b54d5650a378659663", - .replace = TRUE -}; - -/* methods configurations */ -void configure_sqlite3_bind_text(int position, const char* string) { - will_return(__wrap_sqlite3_bind_text, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_text, pos, position); - if (string) { - expect_string(__wrap_sqlite3_bind_text, buffer, string); - } -} - -void configure_sqlite3_bind_int64(int position, int number, bool allow_zero) { - if (number > 0 || (0 == number && allow_zero)) { - will_return(__wrap_sqlite3_bind_int64, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int64, index, position); - expect_value(__wrap_sqlite3_bind_int64, value, number); - } else { - will_return(__wrap_sqlite3_bind_null, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_null, index, position); - } -} - -void configure_sqlite3_bind_int(int position, int number, bool allow_zero) { - if (number > 0 || (0 == number && allow_zero)) { - will_return(__wrap_sqlite3_bind_int, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_int, index, position); - expect_value(__wrap_sqlite3_bind_int, value, number); - } else { - will_return(__wrap_sqlite3_bind_null, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_null, index, position); - } -} - -void configure_sqlite3_bind_int_ex(int position, int number, bool allow_zero, bool allow_over_one_hundred) { - if (!allow_over_one_hundred && number > 100) { - will_return(__wrap_sqlite3_bind_null, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_null, index, position); - } else { - configure_sqlite3_bind_int(position, number, allow_zero); - } -} - -void configure_sqlite3_bind_double(int position, double number, bool allow_zero) { - if (number > 0 || (0 == number && allow_zero)) { - will_return(__wrap_sqlite3_bind_double, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_double, index, position); - expect_value(__wrap_sqlite3_bind_double, value, number); - } else { - will_return(__wrap_sqlite3_bind_null, OS_SUCCESS); - expect_value(__wrap_sqlite3_bind_null, index, position); - } -} - -// wdb_netinfo_insert -void configure_wdb_netinfo_insert(netinfo_object test_netinfo, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_netinfo.scan_id); - configure_sqlite3_bind_text(2, test_netinfo.scan_time); - configure_sqlite3_bind_text(3, test_netinfo.name); - configure_sqlite3_bind_text(4, test_netinfo.adapter); - configure_sqlite3_bind_text(5, test_netinfo.type); - configure_sqlite3_bind_text(6, test_netinfo._state); - configure_sqlite3_bind_int64(7, test_netinfo.mtu, NOT_ALLOW_ZERO); - configure_sqlite3_bind_text(8, test_netinfo.mac); - configure_sqlite3_bind_int64(9, test_netinfo.tx_packets, ALLOW_ZERO); - configure_sqlite3_bind_int64(10, test_netinfo.rx_packets, ALLOW_ZERO); - configure_sqlite3_bind_int64(11, test_netinfo.tx_bytes, ALLOW_ZERO); - configure_sqlite3_bind_int64(12, test_netinfo.rx_bytes, ALLOW_ZERO); - configure_sqlite3_bind_int64(13, test_netinfo.tx_errors, ALLOW_ZERO); - configure_sqlite3_bind_int64(14, test_netinfo.rx_errors, ALLOW_ZERO); - configure_sqlite3_bind_int64(15, test_netinfo.tx_dropped, ALLOW_ZERO); - configure_sqlite3_bind_int64(16, test_netinfo.rx_dropped, ALLOW_ZERO); - configure_sqlite3_bind_text(17, test_netinfo.checksum); - configure_sqlite3_bind_text(18, test_netinfo.item_id); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_netproto_insert -void configure_wdb_netproto_insert(netproto_object test_netproto, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_netproto.scan_id); - configure_sqlite3_bind_text(2, test_netproto.iface); - configure_sqlite3_bind_text(3, test_netproto.type == WDB_NETADDR_IPV4 ? "ipv4" : "ipv6"); - configure_sqlite3_bind_text(4, test_netproto.gateway); - configure_sqlite3_bind_text(5, test_netproto.dhcp); - configure_sqlite3_bind_int64(6, test_netproto.metric, ALLOW_ZERO); - configure_sqlite3_bind_text(7, test_netproto.checksum); - configure_sqlite3_bind_text(8, test_netproto.item_id); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_netaddr_insert -void configure_wdb_netaddr_insert(netaddr_object test_netaddr, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_netaddr.scan_id); - configure_sqlite3_bind_text(2, test_netaddr.iface); - configure_sqlite3_bind_text(3, test_netaddr.proto == WDB_NETADDR_IPV4 ? "ipv4" : "ipv6"); - configure_sqlite3_bind_text(4, test_netaddr.address); - configure_sqlite3_bind_text(5, test_netaddr.netmask); - configure_sqlite3_bind_text(6, test_netaddr.broadcast); - configure_sqlite3_bind_text(7, test_netaddr.checksum); - configure_sqlite3_bind_text(8, test_netaddr.item_id); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_osinfo_insert -void configure_wdb_osinfo_insert(osinfo_object test_osinfo, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_osinfo.scan_id); - configure_sqlite3_bind_text(2, test_osinfo.scan_time); - configure_sqlite3_bind_text(3, test_osinfo.hostname); - configure_sqlite3_bind_text(4, test_osinfo.architecture); - configure_sqlite3_bind_text(5, test_osinfo.os_name); - configure_sqlite3_bind_text(6, test_osinfo.os_version); - configure_sqlite3_bind_text(7, test_osinfo.os_codename); - configure_sqlite3_bind_text(8, test_osinfo.os_major); - configure_sqlite3_bind_text(9, test_osinfo.os_minor); - configure_sqlite3_bind_text(10, test_osinfo.os_patch); - configure_sqlite3_bind_text(11, test_osinfo.os_build); - configure_sqlite3_bind_text(12, test_osinfo.os_platform); - configure_sqlite3_bind_text(13, test_osinfo.sysname); - configure_sqlite3_bind_text(14, test_osinfo.release); - configure_sqlite3_bind_text(15, test_osinfo.version); - configure_sqlite3_bind_text(16, test_osinfo.os_release); - configure_sqlite3_bind_text(17, test_osinfo.os_display_version); - configure_sqlite3_bind_text(18, test_osinfo.checksum); - configure_sqlite3_bind_text(19, test_osinfo.reference); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_package_insert -void configure_wdb_package_insert(package_object test_package, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_package.scan_id); - configure_sqlite3_bind_text(2, test_package.scan_time); - configure_sqlite3_bind_text(3, test_package.format); - configure_sqlite3_bind_text(4, test_package.name); - configure_sqlite3_bind_text(5, test_package.priority); - configure_sqlite3_bind_text(6, test_package.section); - configure_sqlite3_bind_int64(7, test_package.size, ALLOW_ZERO); - configure_sqlite3_bind_text(8, test_package.vendor); - configure_sqlite3_bind_text(9, test_package.install_time); - configure_sqlite3_bind_text(10, test_package.version); - configure_sqlite3_bind_text(11, test_package.architecture); - configure_sqlite3_bind_text(12, test_package.multiarch); - configure_sqlite3_bind_text(13, test_package.source); - configure_sqlite3_bind_text(14, test_package.description); - configure_sqlite3_bind_text(15, test_package.location); - configure_sqlite3_bind_text(16, test_package.checksum); - configure_sqlite3_bind_text(17, test_package.item_id); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_hotfix_insert -void configure_wdb_hotfix_insert(hotfix_object test_hotfix, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_hotfix.scan_id); - configure_sqlite3_bind_text(2, test_hotfix.scan_time); - configure_sqlite3_bind_text(3, test_hotfix.hotfix); - configure_sqlite3_bind_text(4, test_hotfix.checksum); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_hardware_insert -void configure_wdb_hardware_insert(hardware_object test_hardware, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_hardware.scan_id); - configure_sqlite3_bind_text(2, test_hardware.scan_time); - configure_sqlite3_bind_text(3, test_hardware.serial); - configure_sqlite3_bind_text(4, test_hardware.cpu_name); - configure_sqlite3_bind_int(5, test_hardware.cpu_cores, NOT_ALLOW_ZERO); - configure_sqlite3_bind_double(6, test_hardware.cpu_mhz, NOT_ALLOW_ZERO); - configure_sqlite3_bind_int64(7, test_hardware.ram_total, NOT_ALLOW_ZERO); - configure_sqlite3_bind_int64(8, test_hardware.ram_free, NOT_ALLOW_ZERO); - configure_sqlite3_bind_int_ex(9, test_hardware.ram_usage, NOT_ALLOW_ZERO, NOT_ALLOW_OVER_ONEHUNDRED); - configure_sqlite3_bind_text(10, test_hardware.checksum); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_port_insert -void configure_wdb_port_insert(port_object test_port, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_port.scan_id); - configure_sqlite3_bind_text(2, test_port.scan_time); - configure_sqlite3_bind_text(3, test_port.protocol); - configure_sqlite3_bind_text(4, test_port.local_ip); - configure_sqlite3_bind_int(5, test_port.local_port, ALLOW_ZERO); - configure_sqlite3_bind_text(6, test_port.remote_ip); - configure_sqlite3_bind_int(7, test_port.remote_port, ALLOW_ZERO); - configure_sqlite3_bind_int(8, test_port.tx_queue, ALLOW_ZERO); - configure_sqlite3_bind_int(9, test_port.rx_queue, ALLOW_ZERO); - configure_sqlite3_bind_int64(10, test_port.inode, ALLOW_ZERO); - configure_sqlite3_bind_text(11, test_port.state); - configure_sqlite3_bind_int(12, test_port.pid, ALLOW_ZERO); - configure_sqlite3_bind_text(13, test_port.process); - configure_sqlite3_bind_text(14, test_port.checksum); - configure_sqlite3_bind_text(15, test_port.item_id); - - will_return(__wrap_wdb_step, sqlite_code); -} - -// wdb_process_insert -void configure_wdb_process_insert(process_object test_process, int sqlite_code) { - will_return(__wrap_wdb_stmt_cache, OS_SUCCESS); - - configure_sqlite3_bind_text(1, test_process.scan_id); - configure_sqlite3_bind_text(2, test_process.scan_time); - configure_sqlite3_bind_int(3, test_process.pid, ALLOW_ZERO); - configure_sqlite3_bind_text(4, test_process.name); - configure_sqlite3_bind_text(5, test_process.state); - configure_sqlite3_bind_int(6, test_process.ppid, ALLOW_ZERO); - configure_sqlite3_bind_int(7, test_process.utime, ALLOW_ZERO); - configure_sqlite3_bind_int(8, test_process.stime, ALLOW_ZERO); - configure_sqlite3_bind_text(9, test_process.cmd); - configure_sqlite3_bind_text(10, test_process.argvs); - configure_sqlite3_bind_text(11, test_process.euser); - configure_sqlite3_bind_text(12, test_process.ruser); - configure_sqlite3_bind_text(13, test_process.suser); - configure_sqlite3_bind_text(14, test_process.egroup); - configure_sqlite3_bind_text(15, test_process.rgroup); - configure_sqlite3_bind_text(16, test_process.sgroup); - configure_sqlite3_bind_text(17, test_process.fgroup); - configure_sqlite3_bind_int(18, test_process.priority, ALLOW_ZERO); - configure_sqlite3_bind_int(19, test_process.nice, ALLOW_ZERO); - configure_sqlite3_bind_int(20, test_process.size, ALLOW_ZERO); - configure_sqlite3_bind_int(21, test_process.vm_size, ALLOW_ZERO); - configure_sqlite3_bind_int(22, test_process.resident, ALLOW_ZERO); - configure_sqlite3_bind_int(23, test_process.share, ALLOW_ZERO); - configure_sqlite3_bind_int64(24, test_process.start_time, ALLOW_ZERO); - configure_sqlite3_bind_int(25, test_process.pgrp, ALLOW_ZERO); - configure_sqlite3_bind_int(26, test_process.session, ALLOW_ZERO); - configure_sqlite3_bind_int(27, test_process.nlwp, ALLOW_ZERO); - configure_sqlite3_bind_int(28, test_process.tgid, ALLOW_ZERO); - configure_sqlite3_bind_int(29, test_process.tty, ALLOW_ZERO); - configure_sqlite3_bind_int(30, test_process.processor, ALLOW_ZERO); - configure_sqlite3_bind_text(31, test_process.checksum); - - will_return(__wrap_wdb_step, sqlite_code); -} - -/* tests */ - -// Test wdb_netinfo_save -static void test_wdb_netinfo_save_transaction_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_save(): cannot begin transaction"); - - ret = wdb_netinfo_save(data->wdb, netinfo.scan_id, netinfo.scan_time, netinfo.name, netinfo.adapter, netinfo.type, - netinfo._state, netinfo.mtu, netinfo.mac, netinfo.tx_packets, netinfo.rx_packets, netinfo.tx_bytes, - netinfo.rx_bytes, netinfo.tx_errors, netinfo.rx_errors, netinfo.tx_dropped, netinfo.rx_dropped, netinfo.checksum, - netinfo.item_id, netinfo.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_netinfo_save_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - configure_wdb_netinfo_insert(netinfo, SQLITE_DONE); - - ret = wdb_netinfo_save(data->wdb, netinfo.scan_id, netinfo.scan_time, netinfo.name, netinfo.adapter, netinfo.type, - netinfo._state, netinfo.mtu, netinfo.mac, netinfo.tx_packets, netinfo.rx_packets, netinfo.tx_bytes, - netinfo.rx_bytes, netinfo.tx_errors, netinfo.rx_errors, netinfo.tx_dropped, netinfo.rx_dropped, netinfo.checksum, - netinfo.item_id, netinfo.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netinfo_save_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - - // wdb_netinfo_insert - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_insert(): cannot cache statement"); - - ret = wdb_netinfo_save(data->wdb, netinfo.scan_id, netinfo.scan_time, netinfo.name, netinfo.adapter, netinfo.type, - netinfo._state, netinfo.mtu, netinfo.mac, netinfo.tx_packets, netinfo.rx_packets, netinfo.tx_bytes, - netinfo.rx_bytes, netinfo.tx_errors, netinfo.rx_errors, netinfo.tx_dropped, netinfo.rx_dropped, netinfo.checksum, - netinfo.item_id, netinfo.replace); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_netinfo_insert -static void test_wdb_netinfo_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netinfo_insert(): cannot cache statement"); - - ret = wdb_netinfo_insert(NULL, netinfo.scan_id, netinfo.scan_time, netinfo.name, netinfo.adapter, netinfo.type, - netinfo._state, netinfo.mtu, netinfo.mac, netinfo.tx_packets, netinfo.rx_packets, netinfo.tx_bytes, - netinfo.rx_bytes, netinfo.tx_errors, netinfo.rx_errors, netinfo.tx_dropped, netinfo.rx_dropped, netinfo.checksum, - netinfo.item_id, netinfo.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_netinfo_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_netinfo_insert(netinfo, SQLITE_DONE); - - ret = wdb_netinfo_insert(data->wdb, netinfo.scan_id, netinfo.scan_time, netinfo.name, netinfo.adapter, netinfo.type, - netinfo._state, netinfo.mtu, netinfo.mac, netinfo.tx_packets, netinfo.rx_packets, netinfo.tx_bytes, - netinfo.rx_bytes, netinfo.tx_errors, netinfo.rx_errors, netinfo.tx_dropped, netinfo.rx_dropped, netinfo.checksum, - netinfo.item_id, netinfo.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netinfo_insert_name_null_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - netinfo_object test_netinfo = netinfo; - test_netinfo.name = NULL; - - expect_value(__wrap_wdbi_remove_by_pk, component, WDB_SYSCOLLECTOR_NETINFO); - expect_value(__wrap_wdbi_remove_by_pk, pk_value, test_netinfo.item_id); - - configure_wdb_netinfo_insert(test_netinfo, SQLITE_DONE); - - ret = wdb_netinfo_insert(data->wdb, test_netinfo.scan_id, test_netinfo.scan_time, test_netinfo.name, test_netinfo.adapter, test_netinfo.type, - test_netinfo._state, test_netinfo.mtu, test_netinfo.mac, test_netinfo.tx_packets, test_netinfo.rx_packets, test_netinfo.tx_bytes, - test_netinfo.rx_bytes, test_netinfo.tx_errors, test_netinfo.rx_errors, test_netinfo.tx_dropped, test_netinfo.rx_dropped, test_netinfo.checksum, - test_netinfo.item_id, test_netinfo.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netinfo_insert_negative_values_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - netinfo_object test_netinfo = netinfo; - - test_netinfo.mtu = OS_INVALID; - test_netinfo.tx_packets = OS_INVALID; - test_netinfo.rx_packets = OS_INVALID; - test_netinfo.tx_bytes = OS_INVALID; - test_netinfo.rx_bytes = OS_INVALID; - test_netinfo.tx_errors = OS_INVALID; - test_netinfo.rx_errors = OS_INVALID; - test_netinfo.tx_dropped = OS_INVALID; - test_netinfo.rx_dropped = OS_INVALID; - - configure_wdb_netinfo_insert(test_netinfo, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR_MESSAGE"); - - ret = wdb_netinfo_insert(data->wdb, test_netinfo.scan_id, test_netinfo.scan_time, test_netinfo.name, test_netinfo.adapter, test_netinfo.type, - test_netinfo._state, test_netinfo.mtu, test_netinfo.mac, test_netinfo.tx_packets, test_netinfo.rx_packets, test_netinfo.tx_bytes, - test_netinfo.rx_bytes, test_netinfo.tx_errors, test_netinfo.rx_errors, test_netinfo.tx_dropped, test_netinfo.rx_dropped, test_netinfo.checksum, - test_netinfo.item_id, test_netinfo.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_netinfo_insert_name_constraint_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_netinfo_insert(netinfo, SQLITE_CONSTRAINT); - - will_return(__wrap_sqlite3_errmsg, "UNIQUE constraint failed"); - will_return(__wrap_sqlite3_errmsg, "UNIQUE constraint failed"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: UNIQUE constraint failed"); - - - ret = wdb_netinfo_insert(data->wdb, netinfo.scan_id, netinfo.scan_time, netinfo.name, netinfo.adapter, netinfo.type, - netinfo._state, netinfo.mtu, netinfo.mac, netinfo.tx_packets, netinfo.rx_packets, netinfo.tx_bytes, - netinfo.rx_bytes, netinfo.tx_errors, netinfo.rx_errors, netinfo.tx_dropped, netinfo.rx_dropped, netinfo.checksum, - netinfo.item_id, netinfo.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netinfo_insert_name_constraint_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_netinfo_insert(netinfo, SQLITE_CONSTRAINT); - - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR_MESSAGE"); - - - ret = wdb_netinfo_insert(data->wdb, netinfo.scan_id, netinfo.scan_time, netinfo.name, netinfo.adapter, netinfo.type, - netinfo._state, netinfo.mtu, netinfo.mac, netinfo.tx_packets, netinfo.rx_packets, netinfo.tx_bytes, - netinfo.rx_bytes, netinfo.tx_errors, netinfo.rx_errors, netinfo.tx_dropped, netinfo.rx_dropped, netinfo.checksum, - netinfo.item_id, netinfo.replace); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_netproto_save - -static void test_wdb_netproto_save_transaction_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netproto_save(): cannot begin transaction"); - - ret = wdb_netproto_save(data->wdb, netproto.scan_id, netproto.iface, netproto.type, netproto.gateway, netproto.dhcp, - netproto.metric, netproto.checksum, netproto.item_id, netproto.replace ); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_netproto_save_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - configure_wdb_netproto_insert(netproto, SQLITE_DONE); - - ret = wdb_netproto_save(data->wdb, netproto.scan_id, netproto.iface, netproto.type, netproto.gateway, netproto.dhcp, - netproto.metric, netproto.checksum, netproto.item_id, netproto.replace ); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netproto_save_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, OS_SUCCESS); - //wdb_netproto_insert - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netproto_insert(): cannot cache statement"); - - ret = wdb_netproto_save(data->wdb, netproto.scan_id, netproto.iface, netproto.type, netproto.gateway, netproto.dhcp, - netproto.metric, netproto.checksum, netproto.item_id, netproto.replace ); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_netproto_insert -static void test_wdb_netproto_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netproto_insert(): cannot cache statement"); - - ret = wdb_netproto_insert(NULL, netproto.scan_id, netproto.iface, netproto.type, netproto.gateway, netproto.dhcp, - netproto.metric, netproto.checksum, netproto.item_id, netproto.replace ); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_netproto_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_netproto_insert(netproto, SQLITE_DONE); - - ret = wdb_netproto_insert(data->wdb, netproto.scan_id, netproto.iface, netproto.type, netproto.gateway, netproto.dhcp, netproto.metric, - netproto.checksum, netproto.item_id, netproto.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netproto_insert_iface_null(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - netproto_object test_netproto = netproto; - test_netproto.iface = NULL; - - expect_value(__wrap_wdbi_remove_by_pk, component, WDB_SYSCOLLECTOR_NETPROTO); - expect_value(__wrap_wdbi_remove_by_pk, pk_value, test_netproto.item_id); - - configure_wdb_netproto_insert(test_netproto, SQLITE_DONE); - - ret = wdb_netproto_insert(data->wdb, test_netproto.scan_id, test_netproto.iface, test_netproto.type, test_netproto.gateway, test_netproto.dhcp, test_netproto.metric, - test_netproto.checksum, test_netproto.item_id, test_netproto.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netproto_insert_negative_values_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - netproto_object test_netproto = netproto; - test_netproto.type = 1; - test_netproto.metric = OS_INVALID; - - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR_MESSAGE"); - - configure_wdb_netproto_insert(test_netproto, SQLITE_ERROR); - - ret = wdb_netproto_insert(data->wdb, test_netproto.scan_id, test_netproto.iface, test_netproto.type, test_netproto.gateway, test_netproto.dhcp, test_netproto.metric, - test_netproto.checksum, test_netproto.item_id, test_netproto.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_netproto_insert_name_constraint_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - netproto_object test_netproto = netproto; - - configure_wdb_netproto_insert(test_netproto, SQLITE_CONSTRAINT); - - will_return(__wrap_sqlite3_errmsg, "UNIQUE constraint failed"); - will_return(__wrap_sqlite3_errmsg, "UNIQUE constraint failed"); - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: UNIQUE constraint failed"); - - ret = wdb_netproto_insert(data->wdb, test_netproto.scan_id, test_netproto.iface, test_netproto.type, test_netproto.gateway, test_netproto.dhcp, test_netproto.metric, - test_netproto.checksum, test_netproto.item_id, test_netproto.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netproto_insert_name_constraint_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - netproto_object test_netproto = netproto; - - configure_wdb_netproto_insert(test_netproto, SQLITE_CONSTRAINT); - - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - will_return(__wrap_sqlite3_errmsg, "ERROR_MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR_MESSAGE"); - - ret = wdb_netproto_insert(data->wdb, test_netproto.scan_id, test_netproto.iface, test_netproto.type, test_netproto.gateway, test_netproto.dhcp, test_netproto.metric, - test_netproto.checksum, test_netproto.item_id, test_netproto.replace); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_netaddr_insert -static void test_wdb_netaddr_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_netaddr_insert(): cannot cache statement"); - - ret = wdb_netaddr_insert(NULL, netaddr.scan_id, netaddr.iface, netaddr.proto, netaddr.address, netaddr.netmask, - netaddr.broadcast, netaddr.checksum, netaddr.item_id, netaddr.replace ); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_netaddr_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_netaddr_insert(netaddr, SQLITE_DONE); - - ret = wdb_netaddr_insert(data->wdb, netaddr.scan_id, netaddr.iface, netaddr.proto, netaddr.address, netaddr.netmask, - netaddr.broadcast, netaddr.checksum, netaddr.item_id, netaddr.replace ); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_netaddr_insert_null_values_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - netaddr_object test_netaddr = netaddr; - test_netaddr.iface = NULL; - test_netaddr.address = NULL; - - expect_value(__wrap_wdbi_remove_by_pk, component, WDB_SYSCOLLECTOR_NETADDRESS); - expect_value(__wrap_wdbi_remove_by_pk, pk_value, test_netaddr.item_id); - - configure_wdb_netaddr_insert(test_netaddr, SQLITE_DONE); - - ret = wdb_netaddr_insert(data->wdb, test_netaddr.scan_id, test_netaddr.iface, test_netaddr.proto, test_netaddr.address, test_netaddr.netmask, - test_netaddr.broadcast, test_netaddr.checksum, test_netaddr.item_id, test_netaddr.replace ); - - assert_int_equal(ret, OS_SUCCESS); -} - -// Test wdb_osinfo_insert -static void test_wdb_osinfo_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_osinfo_insert(): cannot cache statement"); - - ret = wdb_osinfo_insert(NULL, osinfo.scan_id, osinfo.scan_time, osinfo.hostname, osinfo.architecture, osinfo.os_name, - osinfo.os_version, osinfo.os_codename, osinfo.os_major, osinfo.os_minor, osinfo.os_patch, osinfo.os_build, - osinfo.os_platform, osinfo.sysname, osinfo.release, osinfo.version, osinfo.os_release, osinfo.os_display_version, - osinfo.checksum, osinfo.replace, osinfo.reference); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_osinfo_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_osinfo_insert(osinfo, SQLITE_DONE); - - ret = wdb_osinfo_insert(data->wdb, osinfo.scan_id, osinfo.scan_time, osinfo.hostname, osinfo.architecture, osinfo.os_name, - osinfo.os_version, osinfo.os_codename, osinfo.os_major, osinfo.os_minor, osinfo.os_patch, osinfo.os_build, - osinfo.os_platform, osinfo.sysname, osinfo.release, osinfo.version, osinfo.os_release, osinfo.os_display_version, - osinfo.checksum, osinfo.replace, osinfo.reference); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_osinfo_insert_step_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_osinfo_insert(osinfo, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - ret = wdb_osinfo_insert(data->wdb, osinfo.scan_id, osinfo.scan_time, osinfo.hostname, osinfo.architecture, osinfo.os_name, - osinfo.os_version, osinfo.os_codename, osinfo.os_major, osinfo.os_minor, osinfo.os_patch, osinfo.os_build, - osinfo.os_platform, osinfo.sysname, osinfo.release, osinfo.version, osinfo.os_release, osinfo.os_display_version, - osinfo.checksum, osinfo.replace, osinfo.reference); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_package_insert -static void test_wdb_package_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_package_insert(): cannot cache statement"); - - ret = wdb_package_insert(NULL, package.scan_id, package.scan_time, package.format, package.name, package.priority, package.section, - package.size, package.vendor, package.install_time, package.version, package.architecture, package.multiarch, - package.source, package.description, package.location, package.checksum, package.item_id, - package.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_package_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_package_insert(package, SQLITE_DONE); - - ret = wdb_package_insert(data->wdb, package.scan_id, package.scan_time, package.format, package.name, package.priority, package.section, - package.size, package.vendor, package.install_time, package.version, package.architecture, package.multiarch, - package.source, package.description, package.location, package.checksum, package.item_id, - package.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_package_insert_step_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_package_insert(package, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - ret = wdb_package_insert(data->wdb, package.scan_id, package.scan_time, package.format, package.name, package.priority, package.section, - package.size, package.vendor, package.install_time, package.version, package.architecture, package.multiarch, - package.source, package.description, package.location, package.checksum, package.item_id, - package.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_package_insert_architecture_null(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - package_object temp_package = package; - temp_package.architecture = NULL; - - expect_value(__wrap_wdbi_remove_by_pk, component, WDB_SYSCOLLECTOR_PACKAGES); - expect_value(__wrap_wdbi_remove_by_pk, pk_value, package.item_id); - - configure_wdb_package_insert(temp_package, SQLITE_DONE); - - ret = wdb_package_insert(data->wdb, temp_package.scan_id, temp_package.scan_time, temp_package.format, temp_package.name, temp_package.priority, temp_package.section, - temp_package.size, temp_package.vendor, temp_package.install_time, temp_package.version, temp_package.architecture, temp_package.multiarch, - temp_package.source, temp_package.description, temp_package.location, temp_package.checksum, temp_package.item_id, - temp_package.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_package_insert_size_negative_value(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - package_object temp_package = package; - temp_package.size = -1; - - configure_wdb_package_insert(temp_package, SQLITE_DONE); - - ret = wdb_package_insert(data->wdb, temp_package.scan_id, temp_package.scan_time, temp_package.format, temp_package.name, temp_package.priority, temp_package.section, - temp_package.size, temp_package.vendor, temp_package.install_time, temp_package.version, temp_package.architecture, temp_package.multiarch, - temp_package.source, temp_package.description, temp_package.location, temp_package.checksum, temp_package.item_id, - temp_package.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_package_insert_constraint_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_package_insert(package, SQLITE_CONSTRAINT); - - will_return(__wrap_sqlite3_errmsg, "UNIQUE constraint failed"); - will_return(__wrap_sqlite3_errmsg, "UNIQUE constraint failed"); - - expect_string(__wrap__mdebug1, formatted_msg, "SQLite: UNIQUE constraint failed"); - - ret = wdb_package_insert(data->wdb, package.scan_id, package.scan_time, package.format, package.name, package.priority, package.section, - package.size, package.vendor, package.install_time, package.version, package.architecture, package.multiarch, - package.source, package.description, package.location, package.checksum, package.item_id, - package.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_package_insert_constraint_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_package_insert(package, SQLITE_CONSTRAINT); - - will_return(__wrap_sqlite3_errmsg, "ERROR"); - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - ret = wdb_package_insert(data->wdb, package.scan_id, package.scan_time, package.format, package.name, package.priority, package.section, - package.size, package.vendor, package.install_time, package.version, package.architecture, package.multiarch, - package.source, package.description, package.location, package.checksum, package.item_id, - package.replace); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_hotfix_insert -static void test_wdb_hotfix_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hotfix_insert(): cannot cache statement"); - - ret = wdb_hotfix_insert(NULL, hotfix.scan_id, hotfix.scan_time, hotfix.hotfix, hotfix.checksum, hotfix.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_hotfix_insert_hotfix_null(void **state) { - int ret = OS_INVALID; - hotfix_object temp_hotfix = hotfix; - temp_hotfix.hotfix = NULL; - - ret = wdb_hotfix_insert(NULL, temp_hotfix.scan_id, temp_hotfix.scan_time, temp_hotfix.hotfix, temp_hotfix.checksum, temp_hotfix.replace); - - assert_int_equal(ret, OS_INVALID); - -} - -static void test_wdb_hotfix_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_hotfix_insert(hotfix, SQLITE_DONE); - - ret = wdb_hotfix_insert(data->wdb, hotfix.scan_id, hotfix.scan_time, hotfix.hotfix, hotfix.checksum, hotfix.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_hotfix_insert_step_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_hotfix_insert(hotfix, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - ret = wdb_hotfix_insert(data->wdb, hotfix.scan_id, hotfix.scan_time, hotfix.hotfix, hotfix.checksum, hotfix.replace); - - assert_int_equal(ret, OS_INVALID); -} - -// Test wdb_hardware_insert -static void test_wdb_hardware_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_hardware_insert(): cannot cache statement"); - - ret = wdb_hardware_insert(NULL, hardware.scan_id, hardware.scan_time, hardware.serial, hardware.cpu_name, hardware.cpu_cores, - hardware.cpu_mhz, hardware.ram_total, hardware.ram_free, hardware.ram_usage, hardware.checksum, hardware.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_hardware_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_hardware_insert(hardware, SQLITE_DONE); - - ret = wdb_hardware_insert(data->wdb, hardware.scan_id, hardware.scan_time, hardware.serial, hardware.cpu_name, hardware.cpu_cores, - hardware.cpu_mhz, hardware.ram_total, hardware.ram_free, hardware.ram_usage, hardware.checksum, hardware.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_hardware_insert_step_error(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_hardware_insert(hardware, SQLITE_ERROR); - - will_return(__wrap_sqlite3_errmsg, "ERROR"); - expect_string(__wrap__merror, formatted_msg, "SQLite: ERROR"); - - ret = wdb_hardware_insert(data->wdb, hardware.scan_id, hardware.scan_time, hardware.serial, hardware.cpu_name, hardware.cpu_cores, - hardware.cpu_mhz, hardware.ram_total, hardware.ram_free, hardware.ram_usage, hardware.checksum, hardware.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_hardware_insert_success_null_values(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - hardware_object temp_hardware = hardware; - temp_hardware.cpu_cores = -1; - temp_hardware.cpu_mhz = -1; - temp_hardware.ram_usage = 101; - temp_hardware.ram_total = 0; - temp_hardware.ram_free = 0; - - configure_wdb_hardware_insert(temp_hardware, SQLITE_DONE); - - ret = wdb_hardware_insert(data->wdb, temp_hardware.scan_id, temp_hardware.scan_time, temp_hardware.serial, temp_hardware.cpu_name, - temp_hardware.cpu_cores, temp_hardware.cpu_mhz, temp_hardware.ram_total, temp_hardware.ram_free, temp_hardware.ram_usage, - temp_hardware.checksum, temp_hardware.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -// Test wdb_port_insert -static void test_wdb_port_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_port_insert(): cannot cache statement"); - - ret = wdb_port_insert(NULL, port.scan_id, port.scan_time, port.protocol, port.local_ip, port.local_port, port.remote_ip, port.remote_port, - port.tx_queue, port.rx_queue, port.inode, port.state, port.pid, port.process, port.checksum, port.item_id, port.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_port_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_port_insert(port, SQLITE_DONE); - - ret = wdb_port_insert(data->wdb, port.scan_id, port.scan_time, port.protocol, port.local_ip, port.local_port, port.remote_ip, port.remote_port, - port.tx_queue, port.rx_queue, port.inode, port.state, port.pid, port.process, port.checksum, port.item_id, port.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_port_insert_null_values_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - port_object test_port = port; - test_port.protocol = NULL; - test_port.local_ip = NULL; - test_port.local_port = OS_INVALID; - test_port.inode = OS_INVALID; - - configure_wdb_port_insert(test_port, SQLITE_DONE); - - expect_value(__wrap_wdbi_remove_by_pk, component, WDB_SYSCOLLECTOR_PORTS); - expect_value(__wrap_wdbi_remove_by_pk, pk_value, test_port.item_id); - - ret = wdb_port_insert(data->wdb, test_port.scan_id, test_port.scan_time, test_port.protocol, test_port.local_ip, test_port.local_port, test_port.remote_ip, test_port.remote_port, - test_port.tx_queue, test_port.rx_queue, test_port.inode, test_port.state, test_port.pid, test_port.process, test_port.checksum, test_port.item_id, test_port.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -// Test wdb_process_insert -static void test_wdb_process_insert_stmt_cache_fail(void **state) { - int ret = OS_INVALID; - - will_return(__wrap_wdb_stmt_cache, OS_INVALID); - expect_string(__wrap__mdebug1, formatted_msg, "at wdb_process_insert(): cannot cache statement"); - - ret = wdb_process_insert(NULL, process.scan_id, process.scan_time, process.pid, process.name, process.state, process.ppid, process.utime, - process.stime, process.cmd, process.argvs, process.euser, process.ruser, process.suser, process.egroup, process.rgroup, - process.sgroup, process.fgroup, process.priority, process.nice, process.size, process.vm_size, process.resident, - process.share, process.start_time, process.pgrp, process.session, process.nlwp, process.tgid, process.tty, process.processor, - process.checksum, process.replace); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wdb_process_insert_success(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - - configure_wdb_process_insert(process, SQLITE_DONE); - - ret = wdb_process_insert(data->wdb, process.scan_id, process.scan_time, process.pid, process.name, process.state, process.ppid, process.utime, - process.stime, process.cmd, process.argvs, process.euser, process.ruser, process.suser, process.egroup, process.rgroup, - process.sgroup, process.fgroup, process.priority, process.nice, process.size, process.vm_size, process.resident, - process.share, process.start_time, process.pgrp, process.session, process.nlwp, process.tgid, process.tty, process.processor, - process.checksum, process.replace); - - assert_int_equal(ret, OS_SUCCESS); -} - -static void test_wdb_process_insert_null_values_fail(void **state) { - int ret = OS_INVALID; - test_struct_t *data = (test_struct_t *)*state; - process_object test_process = process; - test_process.pid = OS_INVALID; - - ret = wdb_process_insert(data->wdb, test_process.scan_id, test_process.scan_time, test_process.pid, test_process.name, test_process.state, test_process.ppid, test_process.utime, - test_process.stime, test_process.cmd, test_process.argvs, test_process.euser, test_process.ruser, test_process.suser, test_process.egroup, test_process.rgroup, - test_process.sgroup, test_process.fgroup, test_process.priority, test_process.nice, test_process.size, test_process.vm_size, test_process.resident, - test_process.share, test_process.start_time, test_process.pgrp, test_process.session, test_process.nlwp, test_process.tgid, test_process.tty, test_process.processor, - test_process.checksum, test_process.replace); - - assert_int_equal(ret, OS_INVALID); -} - -// Main - -int main() { - - const struct CMUnitTest tests[] = { - /* Tests wdb_netinfo_save */ - cmocka_unit_test_setup_teardown(test_wdb_netinfo_save_insertion_fail, test_setup, test_teardown), - /* Tests wdb_netinfo_insert */ - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_default_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_sql_constraint_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_sql_constraint_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_sql_success, test_setup, test_teardown), - /* Test wdb_netproto_insert */ - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_default_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_sql_constraint_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_sql_constraint_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_sql_success, test_setup, test_teardown), - /* Test wdb_netaddr_save */ - cmocka_unit_test_setup_teardown(test_wdb_netaddr_save_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netaddr_save_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netaddr_save_success, test_setup, test_teardown), - /* Test wdb_netaddr_insert */ - cmocka_unit_test_setup_teardown(test_wdb_netaddr_insert_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netaddr_insert_fail, test_setup, test_teardown), - /* Test wdb_netinfo_delete */ - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_sys_netiface_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_sys_netiface_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_sys_netproto_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_sys_netproto_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_sys_netaddr_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_sys_netaddr_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_delete_success, test_setup, test_teardown), - /* Test wdb_hotfix_delete */ - cmocka_unit_test_setup_teardown(test_wdb_hotfix_delete_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hotfix_delete_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hotfix_delete_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hotfix_delete_success, test_setup, test_teardown), - /* Test wdb_osinfo_save */ - cmocka_unit_test_setup_teardown(test_wdb_osinfo_save_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_save_retrieve_osinfo_type_reference_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_save_retrieve_osinfo_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_save_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_save_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_save_insert_fail, test_setup, test_teardown), - /* Test wdb_osinfo_insert */ - cmocka_unit_test_setup_teardown(test_wdb_osinfo_insert_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_insert_sql_fail, test_setup, test_teardown), - /* Test wdb_package_save */ - cmocka_unit_test_setup_teardown(test_wdb_package_save_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_save_insert_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_save_success, test_setup, test_teardown), - /* Test wdb_package_insert */ - cmocka_unit_test_setup_teardown(test_wdb_package_insert_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_default_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_sql_constraint_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_sql_constraint_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_sql_success, test_setup, test_teardown), - /* Test wdb_hotfix_save */ - cmocka_unit_test_setup_teardown(test_wdb_hotfix_save_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hotfix_save_insert_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hotfix_save_success, test_setup, test_teardown), - /* Test wdb_package_update */ - cmocka_unit_test_setup_teardown(test_wdb_package_update_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_update_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_update_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_update_loop_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_update_loop_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_update_success, test_setup, test_teardown), - /* Test wdb_package_delete */ - cmocka_unit_test_setup_teardown(test_wdb_package_delete_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_delete_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_delete_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_package_delete_success, test_setup, test_teardown), - /* Test wdb_hardware_save */ - cmocka_unit_test_setup_teardown(test_wdb_hardware_save_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hardware_save_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hardware_save_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hardware_save_insert_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hardware_save_success, test_setup, test_teardown), - /* Test wdb_hardware_insert */ - cmocka_unit_test_setup_teardown(test_wdb_hardware_insert_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_hardware_insert_sql_fail, test_setup, test_teardown), - /* Test wdb_port_save */ - cmocka_unit_test_setup_teardown(test_wdb_port_save_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_port_save_insert_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_port_save_success, test_setup, test_teardown), - /* Test wdb_port_insert */ - cmocka_unit_test_setup_teardown(test_wdb_port_insert_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_port_insert_sql_fail, test_setup, test_teardown), - /* Test wdb_port_delete */ - cmocka_unit_test_setup_teardown(test_wdb_port_delete_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_port_delete_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_port_delete_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_port_delete_success, test_setup, test_teardown), - /* Test wdb_process_save */ - cmocka_unit_test_setup_teardown(test_wdb_process_save_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_process_save_insert_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_process_save_success, test_setup, test_teardown), - /* Test wdb_process_insert */ - cmocka_unit_test_setup_teardown(test_wdb_process_insert_sql_fail, test_setup, test_teardown), - /* Test wdb_process_delete */ - cmocka_unit_test_setup_teardown(test_wdb_process_delete_transaction_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_process_delete_cache_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_process_delete_sql_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_process_delete_success, test_setup, test_teardown), - /* Test wdb_syscollector_save2 */ - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_parser_json_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_get_attributes_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_processes_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_processes_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_package_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_package_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_hotfix_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_hotfix_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_port_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_port_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_netproto_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_netproto_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_netaddr_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_netaddr_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_netinfo_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_netinfo_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_hwinfo_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_hwinfo_success, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_osinfo_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_syscollector_save2_osinfo_success, test_setup, test_teardown), - // Test wdb_netinfo_save - cmocka_unit_test_setup_teardown(test_wdb_netinfo_save_transaction_fail, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_save_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_save_fail, setup_wdb, teardown_wdb), - // Test wdb_netinfo_insert - cmocka_unit_test(test_wdb_netinfo_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_name_null_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_negative_values_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_name_constraint_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netinfo_insert_name_constraint_fail, setup_wdb, teardown_wdb), - // Test wdb_netproto_save - cmocka_unit_test_setup_teardown(test_wdb_netproto_save_transaction_fail, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netproto_save_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netproto_save_fail, setup_wdb, teardown_wdb), - // Test wdb_netproto_insert - cmocka_unit_test(test_wdb_netproto_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_iface_null, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_negative_values_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_name_constraint_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netproto_insert_name_constraint_fail, setup_wdb, teardown_wdb), - // Test wdb_netaddr_insert - cmocka_unit_test(test_wdb_netaddr_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_netaddr_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_netaddr_insert_null_values_success, setup_wdb, teardown_wdb), - // Test wdb_osinfo_insert - cmocka_unit_test(test_wdb_osinfo_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_osinfo_insert_step_error, setup_wdb, teardown_wdb), - // Test wdb_package_insert - cmocka_unit_test(test_wdb_package_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_step_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_architecture_null, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_size_negative_value, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_constraint_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_package_insert_constraint_fail, setup_wdb, teardown_wdb), - // Test wdb_hotfix_insert - cmocka_unit_test(test_wdb_hotfix_insert_stmt_cache_fail), - cmocka_unit_test(test_wdb_hotfix_insert_hotfix_null), - cmocka_unit_test_setup_teardown(test_wdb_hotfix_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_hotfix_insert_step_error, setup_wdb, teardown_wdb), - // Test wdb_hardware_insert - cmocka_unit_test(test_wdb_hardware_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_hardware_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_hardware_insert_step_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_hardware_insert_success_null_values, setup_wdb, teardown_wdb), - // Test wdb_port_insert - cmocka_unit_test(test_wdb_port_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_port_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_port_insert_null_values_success, setup_wdb, teardown_wdb), - // Test wdb_process_insert - cmocka_unit_test(test_wdb_process_insert_stmt_cache_fail), - cmocka_unit_test_setup_teardown(test_wdb_process_insert_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_process_insert_null_values_fail, setup_wdb, teardown_wdb) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_task.c b/src/unit_tests/wazuh_db/test_wdb_task.c deleted file mode 100644 index f3f4a7914db..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_task.c +++ /dev/null @@ -1,1531 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * November, 2020. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "wazuhdb_op.h" - -extern void __real_cJSON_Delete(cJSON *item); - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("tasks",init_data->wdb->id); - os_calloc(256,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - *state = init_data; - return 0; -} - -static int test_teardown(void **state){ - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - - -void test_wdb_task_delete_old_entries_ok(void **state) -{ - int timestamp = 12345; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, timestamp); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - int ret = wdb_task_delete_old_entries(data->wdb, timestamp); - - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_task_delete_old_entries_step_err(void **state) -{ - int timestamp = 12345; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, timestamp); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, -1); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - int ret = wdb_task_delete_old_entries(data->wdb, timestamp); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_delete_old_entries_cache_err(void **state) -{ - int timestamp = 12345; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_delete_old_entries(data->wdb, timestamp); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_delete_old_entries_begin2_err(void **state) -{ - int timestamp = 12345; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_delete_old_entries(data->wdb, timestamp); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_set_timeout_status_timeout_ok(void **state) -{ - time_t now = 123456789; - int timeout = 700; - time_t next_timeout = now + timeout; - int task_id = 10; - int update_time = now - timeout; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "In progress"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_int, iCol, 6); - will_return(__wrap_sqlite3_column_int, update_time); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "Timeout"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, task_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - int ret = wdb_task_set_timeout_status(data->wdb, now, timeout, &next_timeout); - - assert_int_equal(ret, 0); - assert_int_equal(next_timeout, now + timeout); -} - -void test_wdb_task_set_timeout_status_no_timeout_ok(void **state) -{ - time_t now = 123456789; - int timeout = 700; - time_t next_timeout = now + timeout; - int task_id = 10; - int update_time = (now - timeout) + 100; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "In progress"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_int, iCol, 6); - will_return(__wrap_sqlite3_column_int, update_time); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - int ret = wdb_task_set_timeout_status(data->wdb, now, timeout, &next_timeout); - - assert_int_equal(ret, 0); - assert_int_equal(next_timeout, now + 100); -} - -void test_wdb_task_set_timeout_status_timeout_step_err(void **state) -{ - time_t now = 123456789; - int timeout = 700; - time_t next_timeout = now + timeout; - int task_id = 10; - int update_time = now - timeout; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "In progress"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_int, iCol, 6); - will_return(__wrap_sqlite3_column_int, update_time); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "Timeout"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, task_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - int ret = wdb_task_set_timeout_status(data->wdb, now, timeout, &next_timeout); - - assert_int_equal(ret, OS_INVALID); - assert_int_equal(next_timeout, now + timeout); -} - -void test_wdb_task_set_timeout_status_timeout_cache_err(void **state) -{ - time_t now = 123456789; - int timeout = 700; - time_t next_timeout = now + timeout; - int task_id = 10; - int update_time = now - timeout; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, "In progress"); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_int, iCol, 6); - will_return(__wrap_sqlite3_column_int, update_time); - - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_set_timeout_status(data->wdb, now, timeout, &next_timeout); - - assert_int_equal(ret, OS_INVALID); - assert_int_equal(next_timeout, now + timeout); -} - -void test_wdb_task_set_timeout_status_cache_err(void **state) -{ - time_t now = 123456789; - int timeout = 700; - time_t next_timeout = now + timeout; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_set_timeout_status(data->wdb, now, timeout, &next_timeout); - - assert_int_equal(ret, OS_INVALID); - assert_int_equal(next_timeout, now + timeout); -} - -void test_wdb_task_set_timeout_status_begin2_err(void **state) -{ - time_t now = 123456789; - int timeout = 700; - time_t next_timeout = now + timeout; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_set_timeout_status(data->wdb, now, timeout, &next_timeout); - - assert_int_equal(ret, OS_INVALID); - assert_int_equal(next_timeout, now + timeout); -} - -void test_wdb_task_insert_task(void **state) -{ - int agent_id = 55; - char *node = "node03"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = "Pending"; - int task_id = 20; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, node); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, module); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, command); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - int ret = wdb_task_insert_task(data->wdb, agent_id, node, module, command); - - assert_int_equal(ret, task_id); -} - -void test_wdb_task_insert_task_task_id_err(void **state) -{ - int agent_id = 55; - char *node = "node03"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = "Pending"; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, node); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, module); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, command); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, NULL); - - int ret = wdb_task_insert_task(data->wdb, agent_id, node, module, command); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_insert_task_begin2_err(void **state) -{ - int agent_id = 55; - char *node = "node03"; - char *module = "upgrade_module"; - char *command = "upgrade"; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_insert_task(data->wdb, agent_id, node, module, command); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_insert_task_stmt_cache_err(void **state) -{ - int agent_id = 55; - char *node = "node03"; - char *module = "upgrade_module"; - char *command = "upgrade"; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_insert_task(data->wdb, agent_id, node, module, command); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_insert_task_step1_err(void **state) -{ - int agent_id = 55; - char *node = "node03"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = "Pending"; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, node); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, module); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, command); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, -1); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - int ret = wdb_task_insert_task(data->wdb, agent_id, node, module, command); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_insert_task_cache2_err(void **state) -{ - int agent_id = 55; - char *node = "node03"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = "Pending"; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, node); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, module); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, command); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_insert_task(data->wdb, agent_id, node, module, command); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_insert_task_step2_err(void **state) -{ - int agent_id = 55; - char *node = "node03"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = "Pending"; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, node); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, module); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 4); - expect_string(__wrap_sqlite3_bind_text, buffer, command); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 5); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 7); - expect_string(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - - int ret = wdb_task_insert_task(data->wdb, agent_id, node, module, command); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_get_upgrade_task_status_ok(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - int task_id = 6; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "node03"); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, "In progress"); - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_SUCCESS); - assert_string_equal(status, "In progress"); - os_free(status); -} - -void test_wdb_task_get_upgrade_task_status_delete_old_node_pending(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - int task_id = 6; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "node02"); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, "Pending"); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, task_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_SUCCESS); - assert_null(status); -} - -void test_wdb_task_get_upgrade_task_status_delete_old_node_pending_step_err(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - int task_id = 6; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "node02"); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, "Pending"); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, task_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_INVALID); - assert_null(status); -} - -void test_wdb_task_get_upgrade_task_status_delete_old_node_pending_cache_err(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - int task_id = 6; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, "node02"); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, "Pending"); - - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_INVALID); - assert_null(status); -} - -void test_wdb_task_get_upgrade_task_status_no_task_id(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - int task_id = 0; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_SUCCESS); - assert_null(status); -} - -void test_wdb_task_get_upgrade_task_status_step_err(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_INVALID); - assert_null(status); -} - -void test_wdb_task_get_upgrade_task_status_cache_err(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_INVALID); - assert_null(status); -} - -void test_wdb_task_get_upgrade_task_status_begin2_err(void **state) -{ - int agent_id = 78; - char *node = "node03"; - char *status = NULL; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_get_upgrade_task_status(data->wdb, agent_id, node, &status); - - assert_int_equal(ret, OS_INVALID); - assert_null(status); -} - -void test_wdb_task_update_upgrade_task_status_ok(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - char *node_old = "node03"; - char *status_old = "In progress"; - char *error = "Error message"; - int task_id = 36; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, node_old); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, status_old); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, error); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, task_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, error); - - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_task_update_upgrade_task_status_old_status_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - char *node_old = "node03"; - char *status_old = "Done"; - int task_id = 36; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, node_old); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, status_old); - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_NOTFOUND); -} - -void test_wdb_task_update_upgrade_task_status_old_status2_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Failed"; - char *node_old = "node03"; - char *status_old = "Done"; - int task_id = 36; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, node_old); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, status_old); - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_NOTFOUND); -} - -void test_wdb_task_update_upgrade_task_status_task_id_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - int task_id = 0; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_NOTFOUND); -} - -void test_wdb_task_update_upgrade_task_status_status_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Timeout"; - - test_struct_t *data = (test_struct_t *)*state; - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_update_upgrade_task_status_begin2_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_update_upgrade_task_status_cache_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_update_upgrade_task_status_step_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_update_upgrade_task_status_cache2_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - char *node_old = "node03"; - char *status_old = "In progress"; - int task_id = 36; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, node_old); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, status_old); - - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, NULL); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_update_upgrade_task_status_step2_err(void **state) -{ - int agent_id = 115; - char *node = "node03"; - char *status = "Done"; - char *node_old = "node03"; - char *status_old = "In progress"; - char *error = "Error message"; - int task_id = 36; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value(__wrap_sqlite3_column_text, iCol, 2); - will_return(__wrap_sqlite3_column_text, node_old); - - expect_value(__wrap_sqlite3_column_text, iCol, 7); - will_return(__wrap_sqlite3_column_text, status_old); - - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_text, pos, 1); - expect_string(__wrap_sqlite3_bind_text, buffer, status); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 2); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 3); - expect_string(__wrap_sqlite3_bind_text, buffer, error); - will_return(__wrap_sqlite3_bind_text, 0); - - expect_value(__wrap_sqlite3_bind_int, index, 4); - expect_value(__wrap_sqlite3_bind_int, value, task_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - - int ret = wdb_task_update_upgrade_task_status(data->wdb, agent_id, node, status, error); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_get_upgrade_task_by_agent_id_begin2_err(void **state) -{ - int agent_id = 88; - char *node = NULL; - char *module = NULL; - char *command = NULL; - char *status = NULL; - char *error = NULL; - int update_time = 0; - int last_update = 0; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_get_upgrade_task_by_agent_id(data->wdb, agent_id, &node, &module, &command, &status, &error, &update_time, &last_update); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_get_upgrade_task_by_agent_id_cache_err(void **state) -{ - int agent_id = 88; - char *node = NULL; - char *module = NULL; - char *command = NULL; - char *status = NULL; - char *error = NULL; - int update_time = 0; - int last_update = 0; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_get_upgrade_task_by_agent_id(data->wdb, agent_id, &node, &module, &command, &status, &error, &update_time, &last_update); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_get_upgrade_task_by_agent_id_step_err(void **state) -{ - int agent_id = 88; - char *node = NULL; - char *module = NULL; - char *command = NULL; - char *status = NULL; - char *error = NULL; - int update_time = 0; - int last_update = 0; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - int ret = wdb_task_get_upgrade_task_by_agent_id(data->wdb, agent_id, &node, &module, &command, &status, &error, &update_time, &last_update); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_get_upgrade_task_by_agent_id_no_task_id(void **state) -{ - int agent_id = 88; - char *node = NULL; - char *module = NULL; - char *command = NULL; - char *status = NULL; - char *error = NULL; - int update_time = 0; - int last_update = 0; - int task_id = 0; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - int ret = wdb_task_get_upgrade_task_by_agent_id(data->wdb, agent_id, &node, &module, &command, &status, &error, &update_time, &last_update); - - assert_int_equal(ret, OS_NOTFOUND); -} - -void test_wdb_task_get_upgrade_task_by_agent_id_ok(void **state) -{ - int agent_id = 88; - char *node = NULL; - char *module = NULL; - char *command = NULL; - char *status = NULL; - char *error = NULL; - int update_time = 0; - int last_update = 0; - int task_id = 65; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, agent_id); - will_return(__wrap_sqlite3_bind_int, 0); - - will_return(__wrap_wdb_step, SQLITE_ROW); - - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, task_id); - - expect_value_count(__wrap_sqlite3_column_text, iCol, 2, 2); - will_return_count(__wrap_sqlite3_column_text, "node05", 2); - - expect_value_count(__wrap_sqlite3_column_text, iCol, 3, 2); - will_return_count(__wrap_sqlite3_column_text, "upgrade_module", 2); - - expect_value_count(__wrap_sqlite3_column_text, iCol, 4, 2); - will_return_count(__wrap_sqlite3_column_text, "upgrade", 2); - - expect_value(__wrap_sqlite3_column_int, iCol, 5); - will_return(__wrap_sqlite3_column_int, 12345); - - expect_value(__wrap_sqlite3_column_int, iCol, 6); - will_return(__wrap_sqlite3_column_int, 67890); - - expect_value_count(__wrap_sqlite3_column_text, iCol, 7, 2); - will_return_count(__wrap_sqlite3_column_text, "In progress", 2); - - expect_value_count(__wrap_sqlite3_column_text, iCol, 8, 2); - will_return_count(__wrap_sqlite3_column_text, "Error string", 2); - - - int ret = wdb_task_get_upgrade_task_by_agent_id(data->wdb, agent_id, &node, &module, &command, &status, &error, &update_time, &last_update); - - assert_int_equal(ret, task_id); - assert_string_equal(node, "node05"); - assert_string_equal(module, "upgrade_module"); - assert_string_equal(command, "upgrade"); - assert_int_equal(update_time, 12345); - assert_int_equal(last_update, 67890); - assert_string_equal(status, "In progress"); - assert_string_equal(error, "Error string"); - - os_free(node); - os_free(module); - os_free(command); - os_free(status); - os_free(error); -} - - -void test_wdb_task_cancel_upgrade_tasks_ok(void **state) -{ - char *node = "node05"; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, node); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_DONE); - - - int ret = wdb_task_cancel_upgrade_tasks(data->wdb, node); - - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wdb_task_cancel_upgrade_tasks_step_err(void **state) -{ - char *node = "node05"; - int now = 123456789; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, 1); - - will_return(__wrap_time, now); - - expect_value(__wrap_sqlite3_bind_int, index, 1); - expect_value(__wrap_sqlite3_bind_int, value, now); - will_return(__wrap_sqlite3_bind_int, 0); - - expect_value(__wrap_sqlite3_bind_text, pos, 2); - expect_string(__wrap_sqlite3_bind_text, buffer, node); - will_return(__wrap_sqlite3_bind_text, 0); - - will_return(__wrap_wdb_step, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "(5211): SQL error: 'ERROR MESSAGE'"); - - int ret = wdb_task_cancel_upgrade_tasks(data->wdb, node); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_cancel_upgrade_tasks_cache_err(void **state) -{ - char *node = "node05"; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, 1); - will_return(__wrap_wdb_stmt_cache, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_cancel_upgrade_tasks(data->wdb, node); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_task_cancel_upgrade_tasks_begin2_err(void **state) -{ - char *node = "node05"; - - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_wdb_begin2, -1); - - expect_any(__wrap__mdebug1, formatted_msg); - - int ret = wdb_task_cancel_upgrade_tasks(data->wdb, node); - - assert_int_equal(ret, OS_INVALID); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wdb_task_delete_old_entries - cmocka_unit_test_setup_teardown(test_wdb_task_delete_old_entries_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_delete_old_entries_step_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_delete_old_entries_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_delete_old_entries_begin2_err, test_setup, test_teardown), - // wdb_task_set_timeout_status - cmocka_unit_test_setup_teardown(test_wdb_task_set_timeout_status_timeout_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_set_timeout_status_no_timeout_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_set_timeout_status_timeout_step_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_set_timeout_status_timeout_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_set_timeout_status_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_set_timeout_status_begin2_err, test_setup, test_teardown), - // wdb_task_insert_task - cmocka_unit_test_setup_teardown(test_wdb_task_insert_task, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_insert_task_task_id_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_insert_task_begin2_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_insert_task_stmt_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_insert_task_step1_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_insert_task_cache2_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_insert_task_step2_err, test_setup, test_teardown), - // wdb_task_get_upgrade_task_status - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_delete_old_node_pending, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_delete_old_node_pending_step_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_delete_old_node_pending_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_no_task_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_step_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_status_begin2_err, test_setup, test_teardown), - // wdb_task_update_upgrade_task_status - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_old_status_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_old_status2_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_task_id_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_status_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_begin2_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_step_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_cache2_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_update_upgrade_task_status_step2_err, test_setup, test_teardown), - // wdb_task_get_upgrade_task_by_agent_id - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_by_agent_id_begin2_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_by_agent_id_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_by_agent_id_step_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_by_agent_id_no_task_id, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_get_upgrade_task_by_agent_id_ok, test_setup, test_teardown), - // wdb_task_cancel_upgrade_tasks - cmocka_unit_test_setup_teardown(test_wdb_task_cancel_upgrade_tasks_ok, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_cancel_upgrade_tasks_step_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_cancel_upgrade_tasks_cache_err, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_task_cancel_upgrade_tasks_begin2_err, test_setup, test_teardown) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_task_parser.c b/src/unit_tests/wazuh_db/test_wdb_task_parser.c deleted file mode 100644 index 1b554784c26..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_task_parser.c +++ /dev/null @@ -1,906 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include "hash_op.h" -#include "os_err.h" -#include "../wazuh_db/wdb.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_task_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" -#include "wazuhdb_op.h" - -// Setup/teardown - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -static int teardown_json(void **state) { - cJSON *json = *state; - cJSON_Delete(json); - return 0; -} - -static int test_setup(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("000",init_data->wdb->id); - os_calloc(256,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - *state = init_data; - return 0; -} - -static int test_teardown(void **state){ - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - -// Tests - -void test_wdb_parse_task_open_tasks_fail(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task "; - - will_return(__wrap_wdb_open_tasks, NULL); - expect_string(__wrap__mdebug2, formatted_msg, "Task query: "); - expect_string(__wrap__mdebug2, formatted_msg, "Couldn't open DB task: queue/tasks/tasks.db"); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Couldn't open DB task"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_no_space(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task"; - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "DB query: task"); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'task'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_invalid_command(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task invalid command"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: invalid command"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - expect_string(__wrap__mdebug1, formatted_msg, "Invalid DB query syntax."); - expect_string(__wrap__mdebug2, formatted_msg, "Task DB query error near: invalid"); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid DB query syntax, near 'invalid'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_upgrade_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task upgrade no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: upgrade no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_upgrade_custom_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task upgrade_custom no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: upgrade_custom no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_upgrade_get_status_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task upgrade_get_status no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: upgrade_get_status no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_upgrade_update_status_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task upgrade_update_status no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: upgrade_update_status no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_upgrade_result_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task upgrade_result no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: upgrade_result no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_upgrade_cancel_tasks_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task upgrade_cancel_tasks no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: upgrade_cancel_tasks no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_delete_old_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task delete_old no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: delete_old no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_set_timeout_invalid_parameters(void **state) -{ - int ret = 0; - test_struct_t *data = (test_struct_t *)*state; - char query[OS_BUFFER_SIZE] = "task set_timeout no_json"; - - expect_string(__wrap__mdebug2, formatted_msg, "Task query: set_timeout no_json"); - - will_return(__wrap_wdb_open_tasks, data->wdb); - - ret = wdb_parse(query, data->output, 0); - - assert_string_equal(data->output, "err Invalid command parameters, near 'no_json'"); - assert_int_equal(ret, OS_INVALID); -} - -void test_wdb_parse_task_upgrade_ok(void **state) -{ - int agent_id = 15; - char *node = "master"; - char *module = "api"; - char *command = "upgrade"; - int task_id = 31; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - cJSON_AddStringToObject(parameters, "module", module); - - expect_value(__wrap_wdb_task_insert_task, agent_id, agent_id); - expect_string(__wrap_wdb_task_insert_task, node, node); - expect_string(__wrap_wdb_task_insert_task, module, module); - expect_string(__wrap_wdb_task_insert_task, command, command); - will_return(__wrap_wdb_task_insert_task, task_id); - - int result = wdb_parse_task_upgrade((wdb_t*)1, parameters, command, output); - - *state = (void*)parameters; - - assert_int_equal(result, 0); - assert_string_equal(output, "ok {\"error\":0,\"task_id\":31}"); -} - -void test_wdb_parse_task_upgrade_err(void **state) -{ - int agent_id = 15; - char *node = "master"; - char *module = "api"; - char *command = "upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - cJSON_AddStringToObject(parameters, "module", module); - - expect_value(__wrap_wdb_task_insert_task, agent_id, agent_id); - expect_string(__wrap_wdb_task_insert_task, node, node); - expect_string(__wrap_wdb_task_insert_task, module, module); - expect_string(__wrap_wdb_task_insert_task, command, command); - will_return(__wrap_wdb_task_insert_task, OS_INVALID); - - int result = wdb_parse_task_upgrade((wdb_t*)1, parameters, command, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "ok {\"error\":-1}"); -} - -void test_wdb_parse_task_upgrade_module_err(void **state) -{ - int agent_id = 15; - char *node = "master"; - char *command = "upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - - int result = wdb_parse_task_upgrade((wdb_t*)1, parameters, command, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error insert task: 'parsing module error'"); -} - -void test_wdb_parse_task_upgrade_node_err(void **state) -{ - int agent_id = 15; - char *module = "api"; - char *command = "upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "module", module); - - int result = wdb_parse_task_upgrade((wdb_t*)1, parameters, command, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error insert task: 'parsing node error'"); -} - -void test_wdb_parse_task_upgrade_agent_err(void **state) -{ - char *node = "master"; - char *module = "api"; - char *command = "upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "node", node); - cJSON_AddStringToObject(parameters, "module", module); - - int result = wdb_parse_task_upgrade((wdb_t*)1, parameters, command, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error insert task: 'parsing agent error'"); -} - -void test_wdb_parse_task_upgrade_get_status_ok(void **state) -{ - int agent_id = 15; - char *node = "master"; - char *status_result = "Done"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - - expect_value(__wrap_wdb_task_get_upgrade_task_status, agent_id, agent_id); - expect_string(__wrap_wdb_task_get_upgrade_task_status, node, node); - will_return(__wrap_wdb_task_get_upgrade_task_status, status_result); - will_return(__wrap_wdb_task_get_upgrade_task_status, 0); - - int result = wdb_parse_task_upgrade_get_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, 0); - assert_string_equal(output, "ok {\"error\":0,\"status\":\"Done\"}"); -} - -void test_wdb_parse_task_upgrade_get_status_err(void **state) -{ - int agent_id = 15; - char *node = "master"; - char *status_result = "Done"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - - expect_value(__wrap_wdb_task_get_upgrade_task_status, agent_id, agent_id); - expect_string(__wrap_wdb_task_get_upgrade_task_status, node, node); - will_return(__wrap_wdb_task_get_upgrade_task_status, status_result); - will_return(__wrap_wdb_task_get_upgrade_task_status, OS_INVALID); - - int result = wdb_parse_task_upgrade_get_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "ok {\"error\":-1}"); -} - -void test_wdb_parse_task_upgrade_get_status_node_err(void **state) -{ - int agent_id = 15; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - - int result = wdb_parse_task_upgrade_get_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error get upgrade task status: 'parsing node error'"); -} - -void test_wdb_parse_task_upgrade_get_status_agent_err(void **state) -{ - char *node = "master"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "node", node); - - int result = wdb_parse_task_upgrade_get_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error get upgrade task status: 'parsing agent error'"); -} - -void test_wdb_parse_task_upgrade_update_status_ok(void **state) -{ - int agent_id = 15; - char *node = "master"; - char *status = "Failed"; - char *error_msg = "Invalid upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - cJSON_AddStringToObject(parameters, "status", status); - cJSON_AddStringToObject(parameters, "error_msg", error_msg); - - expect_value(__wrap_wdb_task_update_upgrade_task_status, agent_id, agent_id); - expect_string(__wrap_wdb_task_update_upgrade_task_status, node, node); - expect_string(__wrap_wdb_task_update_upgrade_task_status, status, status); - expect_string(__wrap_wdb_task_update_upgrade_task_status, error, error_msg); - will_return(__wrap_wdb_task_update_upgrade_task_status, 0); - - int result = wdb_parse_task_upgrade_update_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, 0); - assert_string_equal(output, "ok {\"error\":0}"); -} - -void test_wdb_parse_task_upgrade_update_status_err(void **state) -{ - int agent_id = 15; - char *node = "master"; - char *status = "Failed"; - char *error_msg = "Invalid upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - cJSON_AddStringToObject(parameters, "status", status); - cJSON_AddStringToObject(parameters, "error_msg", error_msg); - - expect_value(__wrap_wdb_task_update_upgrade_task_status, agent_id, agent_id); - expect_string(__wrap_wdb_task_update_upgrade_task_status, node, node); - expect_string(__wrap_wdb_task_update_upgrade_task_status, status, status); - expect_string(__wrap_wdb_task_update_upgrade_task_status, error, error_msg); - will_return(__wrap_wdb_task_update_upgrade_task_status, OS_INVALID); - - int result = wdb_parse_task_upgrade_update_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "ok {\"error\":-1}"); -} - -void test_wdb_parse_task_upgrade_update_status_status_err(void **state) -{ - int agent_id = 15; - char *node = "master"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "node", node); - - int result = wdb_parse_task_upgrade_update_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error upgrade update status task: 'parsing status error'"); -} - -void test_wdb_parse_task_upgrade_update_status_node_err(void **state) -{ - int agent_id = 15; - char *status = "Failed"; - char *error_msg = "Invalid upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - cJSON_AddStringToObject(parameters, "status", status); - cJSON_AddStringToObject(parameters, "error_msg", error_msg); - - int result = wdb_parse_task_upgrade_update_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error upgrade update status task: 'parsing node error'"); -} - -void test_wdb_parse_task_upgrade_update_status_agent_err(void **state) -{ - char *node = "master"; - char *status = "Failed"; - char *error_msg = "Invalid upgrade"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "node", node); - cJSON_AddStringToObject(parameters, "status", status); - cJSON_AddStringToObject(parameters, "error_msg", error_msg); - - int result = wdb_parse_task_upgrade_update_status((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error upgrade update status task: 'parsing agent error'"); -} - -void test_wdb_parse_task_upgrade_result_ok(void **state) -{ - int agent_id = 15; - char *node_result = "master"; - char *module_result = "upgrade_module"; - char *command_result = "upgrade_custom"; - char *status_result = "Pending"; - char *error_result = "Error message"; - int create_time = 123456; - int update_time = 123465; - int task_id = 44; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - - expect_value(__wrap_wdb_task_get_upgrade_task_by_agent_id, agent_id, agent_id); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, node_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, module_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, command_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, status_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, error_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, create_time); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, update_time); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, task_id); - - int result = wdb_parse_task_upgrade_result((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, 0); - assert_string_equal(output, "ok {\"error\":0,\"task_id\":44,\"node\":\"master\",\"module\":\"upgrade_module\",\"command\":\"upgrade_custom\",\"status\":\"Pending\",\"error_msg\":\"Error message\",\"create_time\":123456,\"update_time\":123465}"); -} - -void test_wdb_parse_task_upgrade_result_err(void **state) -{ - int agent_id = 15; - char *node_result = "master"; - char *module_result = "upgrade_module"; - char *command_result = "upgrade_custom"; - char *status_result = "Pending"; - char *error_result = "Error message"; - int create_time = 123456; - int update_time = 123465; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "agent", agent_id); - - expect_value(__wrap_wdb_task_get_upgrade_task_by_agent_id, agent_id, agent_id); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, node_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, module_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, command_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, status_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, error_result); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, create_time); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, update_time); - will_return(__wrap_wdb_task_get_upgrade_task_by_agent_id, OS_INVALID); - - int result = wdb_parse_task_upgrade_result((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "ok {\"error\":-1}"); -} - -void test_wdb_parse_task_upgrade_result_agent_err(void **state) -{ - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - - int result = wdb_parse_task_upgrade_result((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error upgrade result task: 'parsing agent error'"); -} - -void test_wdb_parse_task_upgrade_cancel_tasks_ok(void **state) -{ - char *node = "master"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "node", node); - - expect_string(__wrap_wdb_task_cancel_upgrade_tasks, node, node); - will_return(__wrap_wdb_task_cancel_upgrade_tasks, 0); - - int result = wdb_parse_task_upgrade_cancel_tasks((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, 0); - assert_string_equal(output, "ok {\"error\":0}"); -} - -void test_wdb_parse_task_upgrade_cancel_tasks_err(void **state) -{ - char *node = "master"; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "node", node); - - expect_string(__wrap_wdb_task_cancel_upgrade_tasks, node, node); - will_return(__wrap_wdb_task_cancel_upgrade_tasks, OS_INVALID); - - int result = wdb_parse_task_upgrade_cancel_tasks((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "ok {\"error\":-1}"); -} - -void test_wdb_parse_task_upgrade_cancel_tasks_agent_err(void **state) -{ - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - - int result = wdb_parse_task_upgrade_cancel_tasks((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error upgrade cancel task: 'parsing node error'"); -} - -void test_wdb_parse_task_set_timeout_ok(void **state) -{ - int now = 12345; - int interval = 100; - int next_timeout = 12445; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "now", now); - cJSON_AddNumberToObject(parameters, "interval", interval); - - expect_value(__wrap_wdb_task_set_timeout_status, now, now); - expect_value(__wrap_wdb_task_set_timeout_status, interval, interval); - will_return(__wrap_wdb_task_set_timeout_status, next_timeout); - will_return(__wrap_wdb_task_set_timeout_status, 0); - - int result = wdb_parse_task_set_timeout((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, 0); - assert_string_equal(output, "ok {\"error\":0,\"timestamp\":12445}"); -} - -void test_wdb_parse_task_set_timeout_err(void **state) -{ - int now = 12345; - int interval = 100; - int next_timeout = 12445; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "now", now); - cJSON_AddNumberToObject(parameters, "interval", interval); - - expect_value(__wrap_wdb_task_set_timeout_status, now, now); - expect_value(__wrap_wdb_task_set_timeout_status, interval, interval); - will_return(__wrap_wdb_task_set_timeout_status, next_timeout); - will_return(__wrap_wdb_task_set_timeout_status, OS_INVALID); - - int result = wdb_parse_task_set_timeout((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "ok {\"error\":-1}"); -} - -void test_wdb_parse_task_set_timeout_interval_err(void **state) -{ - int now = 12345; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "now", now); - - int result = wdb_parse_task_set_timeout((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error set timeout task: 'parsing interval error'"); -} - -void test_wdb_parse_task_set_timeout_now_err(void **state) -{ - int interval = 100; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "interval", interval); - - int result = wdb_parse_task_set_timeout((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error set timeout task: 'parsing now error'"); -} - -void test_wdb_parse_task_delete_old_ok(void **state) -{ - int timestamp = 12345; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "timestamp", timestamp); - - expect_value(__wrap_wdb_task_delete_old_entries, timestamp, timestamp); - will_return(__wrap_wdb_task_delete_old_entries, 0); - - int result = wdb_parse_task_delete_old((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, 0); - assert_string_equal(output, "ok {\"error\":0}"); -} - -void test_wdb_parse_task_delete_old_err(void **state) -{ - int timestamp = 12345; - - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - cJSON_AddNumberToObject(parameters, "timestamp", timestamp); - - expect_value(__wrap_wdb_task_delete_old_entries, timestamp, timestamp); - will_return(__wrap_wdb_task_delete_old_entries, OS_INVALID); - - int result = wdb_parse_task_delete_old((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "ok {\"error\":-1}"); -} - -void test_wdb_parse_task_delete_old_timestamp_err(void **state) -{ - char output[OS_MAXSTR + 1]; - *output = '\0'; - - cJSON *parameters = cJSON_CreateObject(); - - int result = wdb_parse_task_delete_old((wdb_t*)1, parameters, output); - - *state = (void*)parameters; - - assert_int_equal(result, OS_INVALID); - assert_string_equal(output, "err Error delete old task: 'parsing timestamp error'"); -} - -int main() -{ - const struct CMUnitTest tests[] = { - // wdb_parse - cmocka_unit_test_setup_teardown(test_wdb_parse_task_open_tasks_fail, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_no_space, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_invalid_command, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_upgrade_invalid_parameters, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_upgrade_custom_invalid_parameters, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_upgrade_update_status_invalid_parameters, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_upgrade_get_status_invalid_parameters, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_upgrade_result_invalid_parameters, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_upgrade_cancel_tasks_invalid_parameters, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_set_timeout_invalid_parameters, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_wdb_parse_task_delete_old_invalid_parameters, test_setup, test_teardown), - // wdb_parse_task_upgrade - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_ok, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_module_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_node_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_agent_err, teardown_json), - // wdb_parse_task_upgrade_get_status - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_get_status_ok, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_get_status_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_get_status_node_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_get_status_agent_err, teardown_json), - // wdb_parse_task_upgrade_update_status - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_update_status_ok, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_update_status_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_update_status_status_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_update_status_node_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_update_status_agent_err, teardown_json), - // wdb_parse_task_upgrade_result - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_result_ok, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_result_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_result_agent_err, teardown_json), - // wdb_parse_task_upgrade_cancel_tasks - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_cancel_tasks_ok, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_cancel_tasks_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_upgrade_cancel_tasks_agent_err, teardown_json), - // wdb_parse_task_set_timeout - cmocka_unit_test_teardown(test_wdb_parse_task_set_timeout_ok, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_set_timeout_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_set_timeout_interval_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_set_timeout_now_err, teardown_json), - // wdb_parse_task_delete_old - cmocka_unit_test_teardown(test_wdb_parse_task_delete_old_ok, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_delete_old_err, teardown_json), - cmocka_unit_test_teardown(test_wdb_parse_task_delete_old_timestamp_err, teardown_json) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_db/test_wdb_upgrade.c b/src/unit_tests/wazuh_db/test_wdb_upgrade.c deleted file mode 100644 index af8b4685491..00000000000 --- a/src/unit_tests/wazuh_db/test_wdb_upgrade.c +++ /dev/null @@ -1,943 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * September, 2020. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../wazuh_db/wdb.h" -#include "../wrappers/common.h" -#include "../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_metadata_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../wrappers/wazuh/wazuh_db/wdb_global_wrappers.h" -#include "../wrappers/libc/stdio_wrappers.h" -#include "../wrappers/posix/stat_wrappers.h" -#include "../wrappers/posix/unistd_wrappers.h" -#include "../wrappers/externals/sqlite/sqlite3_wrappers.h" - -extern int test_mode; - -typedef struct test_struct { - wdb_t *wdb; - char *output; -} test_struct_t; - -/* redefinitons/wrapping */ - -time_t __wrap_time(time_t *__timer) { - return 1; -} - -/* setup/teardown */ - -int setup_wdb(void **state) { - test_mode = 1; - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t),init_data); - os_calloc(1,sizeof(wdb_t),init_data->wdb); - os_strdup("global",init_data->wdb->id); - os_calloc(256,sizeof(char),init_data->output); - os_calloc(1,sizeof(sqlite3 *),init_data->wdb->db); - init_data->wdb->enabled = true; - *state = init_data; - return 0; -} - -int teardown_wdb(void **state) { - test_mode = 0; - test_struct_t *data = (test_struct_t *)*state; - os_free(data->output); - os_free(data->wdb->id); - os_free(data->wdb->db); - os_free(data->wdb); - os_free(data); - return 0; -} - -/* Tests test_wdb_recreate_global */ - -void test_wdb_recreate_global_error_closing_wdb_struct(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - // Error closing the wdb struct - will_return(__wrap_wdb_close, 0); - will_return(__wrap_wdb_close, OS_INVALID); - - ret = wdb_recreate_global(data->wdb); - - assert_memory_equal(data->wdb, ret, sizeof(ret)); -} - -void test_wdb_recreate_global_error_creating_global_db(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - // Closing the wdb struct and removing the current database file - will_return(__wrap_wdb_close, 1); - will_return(__wrap_wdb_close, OS_SUCCESS); - expect_string(__wrap_unlink, file, "queue/db/global.db"); - will_return(__wrap_unlink, 0); - - // Error creating global.db - expect_string(__wrap_wdb_create_global, path, "queue/db/global.db"); - will_return(__wrap_wdb_create_global, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "Couldn't create SQLite database 'queue/db/global.db'"); - - ret = wdb_recreate_global(data->wdb); - - assert_null(ret); -} - -void test_wdb_recreate_global_error_opening_global_db(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - // Closing the wdb struct and removing the current database file - will_return(__wrap_wdb_close, 1); - will_return(__wrap_wdb_close, OS_SUCCESS); - expect_string(__wrap_unlink, file, "queue/db/global.db"); - will_return(__wrap_unlink, 0); - - // Creating global.db - expect_string(__wrap_wdb_create_global, path, "queue/db/global.db"); - will_return(__wrap_wdb_create_global, OS_SUCCESS); - - // Error opening new global.db - expect_string(__wrap_sqlite3_open_v2, filename, "queue/db/global.db"); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, 1); - will_return(__wrap_sqlite3_open_v2, SQLITE_ERROR); - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - expect_string(__wrap__merror, formatted_msg, "Can't open SQLite backup database \ -'queue/db/global.db': ERROR MESSAGE"); - will_return(__wrap_sqlite3_close_v2, OS_SUCCESS); - - ret = wdb_recreate_global(data->wdb); - - assert_null(ret); -} - -void test_wdb_recreate_global_success(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - sqlite3 *new_db = NULL; - os_calloc(1,sizeof(sqlite3 *),new_db); - - // Closing the wdb struct and removing the current database file - will_return(__wrap_wdb_close, 1); - will_return(__wrap_wdb_close, OS_SUCCESS); - expect_string(__wrap_unlink, file, "queue/db/global.db"); - will_return(__wrap_unlink, 0); - - // Creating global.db - expect_string(__wrap_wdb_create_global, path, "queue/db/global.db"); - will_return(__wrap_wdb_create_global, OS_SUCCESS); - - // Opening new global.db - expect_string(__wrap_sqlite3_open_v2, filename, "queue/db/global.db"); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, new_db); - will_return(__wrap_sqlite3_open_v2, SQLITE_OK); - - ret = wdb_recreate_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_ptr_equal(new_db, ret->db); -} - -/* Tests wdb_upgrade_global */ - -void test_wdb_upgrade_global_error_checking_metadata_table(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 0); - will_return(__wrap_wdb_count_tables_with_name, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "DB(global) Error trying to find metadata table"); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_false(ret->enabled); -} - -void test_wdb_upgrade_global_error_backingup_legacy_db(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 0); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // wdb_upgrade_check_manager_keepalive (returns OS_SUCCESS - // to indicate that is a legacy database) - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // Error backing up the database - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "Creating pre-upgrade \ -Global DB snapshot failed: global.db-pre_upgrade"); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_false(ret->enabled); -} - -void test_wdb_upgrade_global_success_regenerating_legacy_db(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - sqlite3 *new_db = NULL; - os_calloc(1,sizeof(sqlite3 *),new_db); - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 0); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // wdb_upgrade_check_manager_keepalive (returns OS_SUCCESS - // to indicate that is a legacy database) - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // Success backing up the database - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - // Recreating the database - // Closing the wdb struct and removing the current database file - will_return(__wrap_wdb_close, 1); - will_return(__wrap_wdb_close, OS_SUCCESS); - expect_string(__wrap_unlink, file, "queue/db/global.db"); - will_return(__wrap_unlink, 0); - - // Creating global.db - expect_string(__wrap_wdb_create_global, path, "queue/db/global.db"); - will_return(__wrap_wdb_create_global, OS_SUCCESS); - - // Opening new global.db - expect_string(__wrap_sqlite3_open_v2, filename, "queue/db/global.db"); - expect_value(__wrap_sqlite3_open_v2, flags, SQLITE_OPEN_READWRITE); - will_return(__wrap_sqlite3_open_v2, new_db); - will_return(__wrap_sqlite3_open_v2, SQLITE_OK); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_ptr_equal(new_db, ret->db); -} - -void test_wdb_upgrade_global_error_getting_database_version(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // Error getting database version - char str_db_version[] = "1"; - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, str_db_version); - will_return(__wrap_wdb_metadata_get_entry, OS_INVALID); - expect_string(__wrap__mwarn, formatted_msg, "DB(global): Error trying to get DB version"); - - // Error creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_INVALID); - expect_string(__wrap__merror, - formatted_msg, - "Creating pre-upgrade Global DB snapshot failed: " - "global.db-pre_upgrade"); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_false(ret->enabled); -} - -void test_wdb_upgrade_global_error_creating_pre_upgrade_backup(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // Getting database version - char str_db_version[] = "1"; - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, str_db_version); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - // Error creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_INVALID); - expect_string(__wrap__merror, - formatted_msg, - "Creating pre-upgrade Global DB snapshot failed: " - "global.db-pre_upgrade"); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_false(ret->enabled); -} - -void test_wdb_upgrade_global_error_restoring_database_and_getting_backup_name(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // Getting database version - char str_db_version[] = "1"; - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, str_db_version); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - // Creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - // Error restoring database and getting the backup file name - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 2"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v2_sql); - will_return(__wrap_wdb_sql_exec, OS_INVALID); - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, FALSE); - will_return(__wrap_wdb_global_restore_backup, OS_INVALID); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 2."); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_false(ret->enabled); -} - -void test_wdb_upgrade_global_database_restored(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // Getting database version - char str_db_version[] = "1"; - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, str_db_version); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - // Creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - // Error upgrading database from version 1 to 2 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 2"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v2_sql); - will_return(__wrap_wdb_sql_exec, OS_INVALID); - // Restoring database to the most recent backup - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_SUCCESS); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 2. \ -The global.db was restored to the original state."); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_true(ret->enabled); -} - -void test_wdb_upgrade_global_intermediate_upgrade_error(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // Getting database version - char str_db_version[] = "1"; - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, str_db_version); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - // Creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - // Upgrading database from version 1 to 2 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 2"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v2_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Error upgrading database from version 2 to 3 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 3"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v3_sql); - will_return(__wrap_wdb_sql_exec, OS_INVALID); - // Restoring database to the most recent backup - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_SUCCESS); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 3. \ -The global.db was restored to the original state."); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_true(ret->enabled); -} - -void test_wdb_upgrade_global_full_upgrade_success(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // Getting database version - char str_db_version[] = "1"; - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, str_db_version); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - // Creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - // Upgrading database from version 1 to 2 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 2"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v2_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Upgrading database from version 2 to 3 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 3"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v3_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Upgrading database from version 3 to 4 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 4"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v4_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - will_return(__wrap_wdb_global_adjust_v4, OS_SUCCESS); - // Upgrading database from version 4 to 5 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 5"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v5_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Upgrading database from version 5 to 6 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_true(ret->enabled); -} - -void test_wdb_upgrade_global_full_upgrade_success_from_unversioned_db(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 0); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - // wdb_upgrade_check_manager_keepalive (returns 1 - // to indicate that is a legacy database greater than 3.10) - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - // Creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - // Upgrading unversioned database to version 1 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 1"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v1_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Upgrading database from version 1 to 2 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 2"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v2_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Upgrading database from version 2 to 3 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 3"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v3_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Upgrading database from version 3 to 4 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 4"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v4_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - will_return(__wrap_wdb_global_adjust_v4, OS_SUCCESS); - // Upgrading database from version 4 to 5 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 5"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v5_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - // Upgrading database from version 5 to 6 - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, OS_SUCCESS); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(data->wdb, ret); - assert_true(ret->enabled); -} - -void test_wdb_upgrade_global_update_v1_to_v6_success(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "1"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 2"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v2_sql); - will_return(__wrap_wdb_sql_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 3"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v3_sql); - will_return(__wrap_wdb_sql_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 4"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v4_sql); - will_return(__wrap_wdb_sql_exec, 0); - will_return(__wrap_wdb_global_adjust_v4, OS_SUCCESS); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 5"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v5_sql); - will_return(__wrap_wdb_sql_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, 0); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v1_to_v6_fail(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "1"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 2"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v2_sql); - - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_INVALID); - - will_return(__wrap_wdb_sql_exec, -1); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 2."); - - ret = wdb_upgrade_global(data->wdb); - - assert_ptr_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v2_to_v6_success(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "2"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 3"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v3_sql); - will_return(__wrap_wdb_sql_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 4"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v4_sql); - will_return(__wrap_wdb_sql_exec, 0); - will_return(__wrap_wdb_global_adjust_v4, OS_SUCCESS); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 5"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v5_sql); - will_return(__wrap_wdb_sql_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, 0); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v2_to_v6_fail(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "2"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 3"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v3_sql); - will_return(__wrap_wdb_sql_exec, -1); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 3. The global.db was " - "restored to the original state."); - - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_SUCCESS); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v3_to_v6_success(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "3"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 4"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v4_sql); - will_return(__wrap_wdb_sql_exec, 0); - will_return(__wrap_wdb_global_adjust_v4, OS_SUCCESS); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 5"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v5_sql); - will_return(__wrap_wdb_sql_exec, 0); - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, 0); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v3_to_v6_fail(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "3"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 4"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v4_sql); - will_return(__wrap_wdb_sql_exec, -1); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 4."); - - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_INVALID); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v4_to_v6_success(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "4"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 5"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v5_sql); - will_return(__wrap_wdb_sql_exec, 0); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, 0); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v4_to_v6_fail(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "4"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 5"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v5_sql); - will_return(__wrap_wdb_sql_exec, -1); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 5."); - - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_INVALID); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v5_to_v6_success(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "5"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, 0); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_update_v5_to_v6_fail(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "5"); - will_return(__wrap_wdb_metadata_get_entry, OS_SUCCESS); - - will_return(__wrap_wdb_global_create_backup, "string"); - will_return(__wrap_wdb_global_create_backup, OS_SUCCESS); - - expect_string(__wrap__mdebug2, formatted_msg, "Updating database 'global' to version 6"); - expect_string(__wrap_wdb_sql_exec, sql_exec, schema_global_upgrade_v6_sql); - will_return(__wrap_wdb_sql_exec, -1); - expect_string(__wrap__merror, formatted_msg, "Failed to update global.db to version 6."); - - expect_value(__wrap_wdb_global_restore_backup, save_pre_restore_state, false); - will_return(__wrap_wdb_global_restore_backup, OS_INVALID); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); -} - -void test_wdb_upgrade_global_fail_backup_fail(void **state) -{ - wdb_t *ret = NULL; - test_struct_t *data = (test_struct_t *)*state; - - expect_string(__wrap_wdb_count_tables_with_name, key, "metadata"); - will_return(__wrap_wdb_count_tables_with_name, 1); - will_return(__wrap_wdb_count_tables_with_name, OS_SUCCESS); - - expect_string(__wrap_wdb_metadata_get_entry, key, "db_version"); - will_return(__wrap_wdb_metadata_get_entry, "1"); - will_return(__wrap_wdb_metadata_get_entry, OS_INVALID); - - expect_string(__wrap__mwarn, formatted_msg, "DB(global): Error trying to get DB version"); - - // Error creating pre upgrade backup - will_return(__wrap_wdb_global_create_backup, "global.db"); - will_return(__wrap_wdb_global_create_backup, OS_INVALID); - expect_string(__wrap__merror, - formatted_msg, - "Creating pre-upgrade Global DB snapshot failed: " - "global.db-pre_upgrade"); - - ret = wdb_upgrade_global(data->wdb); - - assert_int_equal(ret, data->wdb); - assert_false(ret->enabled); -} - -/* Tests wdb_is_older_than_v310 */ - -void test_wdb_is_older_than_v310_prepare_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_errmsg, "ERROR MESSAGE"); - will_return(__wrap_sqlite3_prepare_v2, NULL); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_ERROR); - expect_string(__wrap__merror, formatted_msg, "DB(global) sqlite3_prepare_v2(): ERROR MESSAGE"); - - assert_int_equal(wdb_is_older_than_v310(data->wdb), true); -} - -void test_wdb_is_older_than_v310_step_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ERROR); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(wdb_is_older_than_v310(data->wdb), true); -} - -void test_wdb_is_older_than_v310_step_nodata(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_DONE); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(wdb_is_older_than_v310(data->wdb), true); -} - -void test_wdb_is_older_than_v310_step_ok(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - will_return(__wrap_sqlite3_prepare_v2, 1); - will_return(__wrap_sqlite3_prepare_v2, SQLITE_OK); - expect_sqlite3_step_call(SQLITE_ROW); - expect_value(__wrap_sqlite3_column_int, iCol, 0); - will_return(__wrap_sqlite3_column_int, 1); - will_return(__wrap_sqlite3_finalize, SQLITE_OK); - - assert_int_equal(wdb_is_older_than_v310(data->wdb), false); -} - - -int main() -{ - - const struct CMUnitTest tests[] = - { - cmocka_unit_test_setup_teardown(test_wdb_recreate_global_error_closing_wdb_struct, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_recreate_global_error_creating_global_db, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_recreate_global_error_opening_global_db, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_recreate_global_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_error_checking_metadata_table, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_error_backingup_legacy_db, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_success_regenerating_legacy_db, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_error_getting_database_version, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_error_creating_pre_upgrade_backup, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_error_restoring_database_and_getting_backup_name, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_database_restored, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_intermediate_upgrade_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_full_upgrade_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_full_upgrade_success_from_unversioned_db, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_is_older_than_v310_prepare_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_is_older_than_v310_step_error, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_is_older_than_v310_step_nodata, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_is_older_than_v310_step_ok, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v1_to_v6_fail, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v1_to_v6_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v2_to_v6_fail, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v2_to_v6_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v3_to_v6_fail, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v3_to_v6_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v4_to_v6_fail, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v4_to_v6_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v5_to_v6_fail, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_update_v5_to_v6_success, setup_wdb, teardown_wdb), - cmocka_unit_test_setup_teardown(test_wdb_upgrade_global_fail_backup_fail, setup_wdb, teardown_wdb), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/CMakeLists.txt b/src/unit_tests/wazuh_modules/agent_upgrade/CMakeLists.txt deleted file mode 100644 index 199af8aa2f1..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/CMakeLists.txt +++ /dev/null @@ -1,113 +0,0 @@ -# Generate agent upgrade library -file(GLOB upgrade_files - ${SRC_FOLDER}/wazuh_modules/*.o - ${SRC_FOLDER}/wazuh_modules/agent_upgrade/*.o - ${SRC_FOLDER}/wazuh_modules/agent_upgrade/agent/*.o - ${SRC_FOLDER}/wazuh_modules/agent_upgrade/manager/*.o) -list(REMOVE_ITEM upgrade_files ${SRC_FOLDER}/wazuh_modules/main.o) - -add_library(UPGRADE_O STATIC ${upgrade_files}) - -set_source_files_properties( - ${upgrade_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - UPGRADE_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(UPGRADE_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate agent upgrade tests -list(APPEND upgrade_names "test_wm_agent_upgrade") -list(APPEND upgrade_flags "-Wl,--wrap,_mtinfo -Wl,--wrap,wm_agent_upgrade_start_agent_module -Wl,--wrap,wm_agent_upgrade_start_manager_module -Wl,--wrap,getpid -Wl,--wrap,unlink") - -if(${TARGET} STREQUAL "server") - - list(APPEND upgrade_names "test_wm_agent_upgrade_manager") - list(APPEND upgrade_flags "-Wl,--wrap,OS_BindUnixDomainWithPerms -Wl,--wrap,select -Wl,--wrap,close -Wl,--wrap,accept -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,OS_SendSecureTCP \ - -Wl,--wrap,wm_agent_upgrade_parse_message -Wl,--wrap,wm_agent_upgrade_process_upgrade_command -Wl,--wrap,wm_agent_upgrade_process_upgrade_custom_command -Wl,--wrap,wm_agent_upgrade_process_agent_result_command \ - -Wl,--wrap,wm_agent_upgrade_parse_response -Wl,--wrap,wm_agent_upgrade_cancel_pending_upgrades -Wl,--wrap,wm_agent_upgrade_process_upgrade_result_command -Wl,--wrap,sleep -Wl,--wrap,CreateThread -Wl,--wrap,pthread_exit -Wl,--wrap,getpid \ - ${DEBUG_OP_WRAPPERS}") - - list(APPEND upgrade_names "test_wm_agent_upgrade_parsing") - list(APPEND upgrade_flags "-Wl,--wrap,OS_ReadXML -Wl,--wrap,OS_GetOneContentforElement -Wl,--wrap,OS_ClearXML ${DEBUG_OP_WRAPPERS}") - - list(APPEND upgrade_names "test_wm_agent_upgrade_validate") - list(APPEND upgrade_flags "-Wl,--wrap,wurl_http_get -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,OS_SHA1_File -Wl,--wrap,wurl_request -Wl,--wrap,sleep -Wl,--wrap,wfopen \ - -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,getpid -Wl,--wrap,fgetpos -Wl,--wrap=fgetc \ - -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS}") - - list(APPEND upgrade_names "test_wm_agent_upgrade_tasks") - list(APPEND upgrade_flags "-Wl,--wrap,OS_ConnectUnixDomain -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,close -Wl,--wrap,w_create_sendsync_payload -Wl,--wrap,w_send_clustered_message \ - -Wl,--wrap,w_is_worker -Wl,--wrap,cJSON_Duplicate -Wl,--wrap,getpid ${HASH_OP_WRAPPERS} ${DEBUG_OP_WRAPPERS}") - - list(APPEND upgrade_names "test_wm_agent_upgrade_tasks_callbacks") - list(APPEND upgrade_flags "-Wl,--wrap,wm_agent_upgrade_validate_task_ids_message -Wl,--wrap,wm_agent_upgrade_remove_entry \ - -Wl,--wrap,wm_agent_upgrade_parse_data_response -Wl,--wrap,wm_agent_upgrade_parse_response -Wl,--wrap,wm_agent_upgrade_validate_task_status_message -Wl,--wrap,wm_agent_upgrade_send_command_to_agent \ - -Wl,--wrap,wm_agent_upgrade_parse_agent_response -Wl,--wrap,wm_agent_upgrade_send_tasks_information -Wl,--wrap,wm_agent_upgrade_parse_agent_upgrade_command_response ${DEBUG_OP_WRAPPERS}") - - list(APPEND upgrade_names "test_wm_agent_upgrade_commands") - list(APPEND upgrade_flags "-Wl,--wrap,wm_agent_upgrade_parse_task_module_request -Wl,--wrap,wm_agent_upgrade_task_module_callback -Wl,--wrap,wm_agent_upgrade_validate_task_status_message -Wl,--wrap,wm_agent_upgrade_validate_id \ - -Wl,--wrap,wm_agent_upgrade_validate_status -Wl,--wrap,wm_agent_upgrade_validate_system -Wl,--wrap,wm_agent_upgrade_validate_version -Wl,--wrap,wdb_get_agent_info -Wl,--wrap,wm_agent_upgrade_create_task_entry \ - -Wl,--wrap,wm_agent_upgrade_parse_data_response -Wl,--wrap,wm_agent_upgrade_parse_response -Wl,--wrap,wm_agent_upgrade_prepare_upgrades -Wl,--wrap,wm_agent_upgrade_get_agent_ids ${DEBUG_OP_WRAPPERS}") - - list(APPEND upgrade_names "test_wm_agent_upgrade_upgrades") - list(APPEND upgrade_flags "-Wl,--wrap,OS_ConnectUnixDomain -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,close -Wl,--wrap,popen \ - -Wl,--wrap,wm_agent_upgrade_parse_task_module_request -Wl,--wrap,wm_agent_upgrade_task_module_callback -Wl,--wrap,wm_agent_upgrade_parse_agent_response -Wl,--wrap,fopen -Wl,--wrap,fread -Wl,--wrap,fclose \ - -Wl,--wrap,OS_SHA1_File -Wl,--wrap,wm_agent_upgrade_get_first_node -Wl,--wrap,wm_agent_upgrade_get_next_node -Wl,--wrap,compare_wazuh_versions -Wl,--wrap,wm_agent_upgrade_remove_entry \ - -Wl,--wrap,wm_agent_upgrade_validate_task_status_message -Wl,--wrap,wm_agent_upgrade_validate_wpk -Wl,--wrap,wm_agent_upgrade_validate_wpk_custom -Wl,--wrap,wm_agent_upgrade_validate_wpk_version \ - -Wl,--wrap,linked_queue_push_ex -Wl,--wrap,linked_queue_pop_ex -Wl,--wrap,pthread_cond_signal -Wl,--wrap,pthread_cond_wait -Wl,--wrap,CreateThread -Wl,--wrap,wfopen \ - -Wl,--wrap,wm_agent_upgrade_parse_agent_upgrade_command_response -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,getpid -Wl,--wrap,fgetpos -Wl,--wrap=fgetc \ - ${DEBUG_OP_WRAPPERS}") - -else() - - list(APPEND upgrade_names "test_wm_agent_upgrade_agent") - list(APPEND upgrade_flags "-Wl,--wrap,wm_sendmsg -Wl,--wrap,fopen -Wl,--wrap,fgets -Wl,--wrap,fclose -Wl,--wrap,StartMQ -Wl,--wrap,sleep -Wl,--wrap,close -Wl,--wrap,wfopen \ - -Wl,--wrap,OS_BindUnixDomain -Wl,--wrap,select -Wl,--wrap,close -Wl,--wrap,accept -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,wm_agent_upgrade_process_command \ - -Wl,--wrap,fflush -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove -Wl,--wrap,getpid -Wl,--wrap,CreateThread -Wl,--wrap,unlink -Wl,--wrap,fgetpos -Wl,--wrap=fgetc \ - -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS}") - - list(APPEND upgrade_names "test_wm_agent_upgrade_com") - list(APPEND upgrade_flags "-Wl,--wrap,w_ref_parent_folder -Wl,--wrap,w_wpk_unsign -Wl,--wrap,unlink -Wl,--wrap,getpid -Wl,--wrap,gzopen \ - -Wl,--wrap,fopen -Wl,--wrap,fclose -Wl,--wrap,fflush -Wl,--wrap,fgets -Wl,--wrap,fread -Wl,--wrap,fseek -Wl,--wrap,fwrite -Wl,--wrap,remove \ - -Wl,--wrap,gzclose -Wl,--wrap,gzread -Wl,--wrap,mkstemp -Wl,--wrap,atexit -Wl,--wrap,chmod -Wl,--wrap,stat -Wl,--wrap,wfopen \ - -Wl,--wrap,OS_SHA1_File -Wl,--wrap,getDefine_Int -Wl,--wrap,cldir_ex -Wl,--wrap,UnmergeFiles -Wl,--wrap,wm_exec -Wl,--wrap,remove \ - -Wl,--wrap,fgetpos -Wl,--wrap=fgetc -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS}") - -endif() - -# Compiling tests -list(LENGTH upgrade_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET upgrade_names ${counter} test_name) - list(GET upgrade_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - UPGRADE_O - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade.c deleted file mode 100644 index 4f6efb54056..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/posix/pthread_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_agent_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/wm_agent_upgrade.h" -#include "../../headers/shared.h" - -void* wm_agent_upgrade_main(wm_agent_upgrade* upgrade_config); -void wm_agent_upgrade_destroy(wm_agent_upgrade* upgrade_config); -cJSON *wm_agent_upgrade_dump(const wm_agent_upgrade* upgrade_config); - -// Setup / teardown - -static int setup_group(void **state) { - wm_agent_upgrade *config = NULL; - os_calloc(1, sizeof(wm_agent_upgrade), config); - *state = config; - return 0; -} - -static int teardown_group(void **state) { - wm_agent_upgrade *config = *state; - #ifdef TEST_SERVER - os_free(config->manager_config.wpk_repository); - #else - if (wcom_ca_store) { - for (int i=0; wcom_ca_store[i]; i++) { - os_free(wcom_ca_store[i]); - } - os_free(wcom_ca_store); - } - #endif - os_free(config); - return 0; -} - -static int teardown_json(void **state) { - if (state[1]) { - cJSON *json = state[1]; - cJSON_Delete(json); - } - return 0; -} - -// Tests - -void test_wm_agent_upgrade_dump_enabled(void **state) -{ - wm_agent_upgrade *config = *state; - - config->enabled = 1; - - #ifdef TEST_SERVER - os_strdup("wazuh.com/packages", config->manager_config.wpk_repository); - config->manager_config.chunk_size = 512; - config->manager_config.max_threads = 8; - #else - config->agent_config.enable_ca_verification = 1; - os_calloc(2, sizeof(char*), wcom_ca_store); - os_strdup(DEF_CA_STORE, wcom_ca_store[0]); - wcom_ca_store[1] = NULL; - #endif - - cJSON *ret = wm_agent_upgrade_dump(config); - - state[1] = ret; - - assert_non_null(ret); - cJSON *conf = cJSON_GetObjectItem(ret, "agent-upgrade"); - assert_non_null(conf); - assert_non_null(cJSON_GetObjectItem(conf, "enabled")); - assert_string_equal(cJSON_GetObjectItem(conf, "enabled")->valuestring, "yes"); - #ifdef TEST_SERVER - assert_int_equal(cJSON_GetObjectItem(conf, "max_threads")->valueint, 8); - assert_int_equal(cJSON_GetObjectItem(conf, "chunk_size")->valueint, 512); - assert_non_null(cJSON_GetObjectItem(conf, "wpk_repository")); - assert_string_equal(cJSON_GetObjectItem(conf, "wpk_repository")->valuestring, "wazuh.com/packages"); - #else - assert_non_null(cJSON_GetObjectItem(conf, "ca_verification")); - assert_string_equal(cJSON_GetObjectItem(conf, "ca_verification")->valuestring, "yes"); - cJSON *certs = cJSON_GetObjectItem(conf, "ca_store"); - assert_non_null(certs); - assert_int_equal(cJSON_GetArraySize(certs), 1); - assert_string_equal(cJSON_GetArrayItem(certs, 0)->valuestring, DEF_CA_STORE); - assert_null(cJSON_GetArrayItem(certs, 1)); - #endif -} - -void test_wm_agent_upgrade_dump_disabled(void **state) -{ - wm_agent_upgrade *config = *state; - - config->enabled = 0; - - #ifdef TEST_SERVER - os_free(config->manager_config.wpk_repository); - #else - config->agent_config.enable_ca_verification = 0; - if (wcom_ca_store) { - for (int i=0; wcom_ca_store[i]; i++) { - os_free(wcom_ca_store[i]); - } - os_free(wcom_ca_store); - } - #endif - - cJSON *ret = wm_agent_upgrade_dump(config); - - state[1] = ret; - - assert_non_null(ret); - cJSON *conf = cJSON_GetObjectItem(ret, "agent-upgrade"); - assert_non_null(conf); - assert_non_null(cJSON_GetObjectItem(conf, "enabled")); - assert_string_equal(cJSON_GetObjectItem(conf, "enabled")->valuestring, "no"); - #ifndef TEST_SERVER - assert_non_null(cJSON_GetObjectItem(conf, "ca_verification")); - assert_string_equal(cJSON_GetObjectItem(conf, "ca_verification")->valuestring, "no"); - cJSON *certs = cJSON_GetObjectItem(conf, "ca_store"); - assert_null(certs); - #endif -} - -void test_wm_agent_upgrade_destroy(void **state) -{ - wm_agent_upgrade *config = NULL; - os_calloc(1, sizeof(wm_agent_upgrade), config); - - #ifdef TEST_SERVER - os_strdup("wazuh.com/packages", config->manager_config.wpk_repository); - #endif - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtinfo, formatted_msg, "(8154): Module Agent Upgrade finished."); - - wm_agent_upgrade_destroy(config); -} - -void test_wm_agent_upgrade_main_ok(void **state) -{ - wm_agent_upgrade *config = *state; - - config->enabled = 1; - - #ifdef TEST_SERVER - expect_memory(__wrap_wm_agent_upgrade_start_manager_module, manager_configs, &config->manager_config, sizeof(&config->manager_config)); - expect_value(__wrap_wm_agent_upgrade_start_manager_module, enabled, config->enabled); - #else - expect_memory(__wrap_wm_agent_upgrade_start_agent_module, agent_config, &config->agent_config, sizeof(&config->agent_config)); - expect_value(__wrap_wm_agent_upgrade_start_agent_module, enabled, config->enabled); - #endif - - wm_agent_upgrade_main(config); -} - -void test_wm_agent_upgrade_main_disabled(void **state) -{ - wm_agent_upgrade *config = *state; - - config->enabled = 0; - - #ifdef TEST_SERVER - expect_memory(__wrap_wm_agent_upgrade_start_manager_module, manager_configs, &config->manager_config, sizeof(&config->manager_config)); - expect_value(__wrap_wm_agent_upgrade_start_manager_module, enabled, config->enabled); - #else - expect_memory(__wrap_wm_agent_upgrade_start_agent_module, agent_config, &config->agent_config, sizeof(&config->agent_config)); - expect_value(__wrap_wm_agent_upgrade_start_agent_module, enabled, config->enabled); - #endif - - wm_agent_upgrade_main(config); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_dump - cmocka_unit_test_teardown(test_wm_agent_upgrade_dump_enabled, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_dump_disabled, teardown_json), - // wm_task_manager_destroy - cmocka_unit_test(test_wm_agent_upgrade_destroy), - // wm_agent_upgrade_main - cmocka_unit_test(test_wm_agent_upgrade_main_ok), - cmocka_unit_test(test_wm_agent_upgrade_main_disabled) - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_agent.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_agent.c deleted file mode 100644 index cc3e6010aa2..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_agent.c +++ /dev/null @@ -1,1070 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/posix/select_wrappers.h" -#include "../../wrappers/posix/unistd_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wmodules_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/agent/wm_agent_upgrade_agent.h" -#include "../../headers/shared.h" - -#ifndef TEST_WINAGENT -void wm_agent_upgrade_listen_messages(const wm_agent_configs* agent_configs); -#endif -void wm_agent_upgrade_check_status(const wm_agent_configs* agent_config); -bool wm_upgrade_agent_search_upgrade_result(int *queue_fd); -void wm_upgrade_agent_send_ack_message(int *queue_fd, wm_upgrade_agent_state state); - -// Setup / teardown - -static int setup_group(void **state) { - wm_agent_configs *config = NULL; - os_calloc(1, sizeof(wm_agent_configs), config); - *state = config; - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - wm_agent_configs *config = *state; - os_free(config); - test_mode = 0; - return 0; -} - -static int setup_test_executions(void **state) { - wm_max_eps = 1; - return 0; -} - -// Wrappers - -int __wrap_accept() { - return mock(); -} - -int __wrap_CreateThread(void * (*function_pointer)(void *), void *data) { - check_expected_ptr(function_pointer); - return 1; -} - -// Tests - -void test_wm_upgrade_agent_send_ack_message_successful(void **state) -{ - (void) state; - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_SUCCESSFUL; - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}'"); - - wm_upgrade_agent_send_ack_message(&queue, upgrade_state); - - assert_int_equal(queue, 0); -} - -void test_wm_upgrade_agent_send_ack_message_failed(void **state) -{ - (void) state; - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_FAILED; - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}'"); - - wm_upgrade_agent_send_ack_message(&queue, upgrade_state); - - assert_int_equal(queue, 0); -} - -void test_wm_upgrade_agent_send_ack_message_error(void **state) -{ - (void) state; - int queue = 0; - int result = -1; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_FAILED; - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'Success'"); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}'"); - - wm_upgrade_agent_send_ack_message(&queue, upgrade_state); - - assert_int_equal(queue, 1); -} - -void test_wm_upgrade_agent_send_ack_message_error_exit(void **state) -{ - (void) state; - int queue = 0; - int result = -1; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_FAILED; - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'Success'"); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, -1); - - expect_string(__wrap__mterror_exit, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror_exit, formatted_msg, "(1211): Unable to access queue: 'queue/sockets/queue'. Giving up."); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}'"); - - wm_upgrade_agent_send_ack_message(&queue, upgrade_state); - - assert_int_equal(queue, -1); -} - -void test_wm_upgrade_agent_search_upgrade_result_successful(void **state) -{ - (void) state; - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_SUCCESSFUL; - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "0\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "0\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}'"); - - int ret = wm_upgrade_agent_search_upgrade_result(&queue); - - assert_int_equal(ret, 1); - assert_int_equal(queue, 0); -} - -void test_wm_upgrade_agent_search_upgrade_result_failed_missing_dependency(void **state) -{ - (void) state; - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_FAILED_DEPENDENCY; - - expect_string(__wrap_fopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_fopen, mode, "r"); - will_return(__wrap_fopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "1\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "1\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":1," - "\"message\":\"Upgrade failed due missing dependency\"," - "\"status\":\"Failed\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":1," - "\"message\":\"Upgrade failed due missing dependency\"," - "\"status\":\"Failed\"}}'"); - - int ret = wm_upgrade_agent_search_upgrade_result(&queue); - - assert_int_equal(ret, 1); - assert_int_equal(queue, 0); -} - -void test_wm_upgrade_agent_search_upgrade_result_failed(void **state) -{ - (void) state; - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_FAILED; - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "2\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "2\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":2," - "\"message\":\"Upgrade failed\"," - "\"status\":\"Failed\"}}'"); - - int ret = wm_upgrade_agent_search_upgrade_result(&queue); - - assert_int_equal(ret, 1); - assert_int_equal(queue, 0); -} - -void test_wm_upgrade_agent_search_upgrade_result_error_open(void **state) -{ - (void) state; - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_FAILED; - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - - int ret = wm_upgrade_agent_search_upgrade_result(&queue); - - assert_int_equal(ret, 0); - assert_int_equal(queue, 0); -} - -void test_wm_upgrade_agent_search_upgrade_result_error_code(void **state) -{ - (void) state; - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_FAILED; - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "5\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "5\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - int ret = wm_upgrade_agent_search_upgrade_result(&queue); - - assert_int_equal(ret, 0); - assert_int_equal(queue, 0); -} - -void test_wm_agent_upgrade_check_status_successful(void **state) -{ - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_SUCCESSFUL; - wm_agent_configs *config = *state; - - config->upgrade_wait_start = 1; - config->upgrade_wait_max = 10; - config->upgrade_wait_factor_increase = 3; - - allow_upgrades = false; - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, queue); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME * 1000); -#else - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME); -#endif - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "0\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "0\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}'"); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, config->upgrade_wait_start * 1000); -#else - expect_value(__wrap_sleep, seconds, config->upgrade_wait_start); -#endif - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - - wm_agent_upgrade_check_status(config); - - assert_int_equal(allow_upgrades, true); -} - -void test_wm_agent_upgrade_check_status_time_limit(void **state) -{ - int queue = 0; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_SUCCESSFUL; - wm_agent_configs *config = *state; - - config->upgrade_wait_start = 1; - config->upgrade_wait_max = 10; - config->upgrade_wait_factor_increase = 3; - - allow_upgrades = false; - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, queue); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME * 1000); -#else - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME); -#endif - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "0\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "0\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}'"); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, config->upgrade_wait_start * 1000); -#else - expect_value(__wrap_sleep, seconds, config->upgrade_wait_start); -#endif - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "0\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "0\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}'"); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, config->upgrade_wait_start * config->upgrade_wait_factor_increase * 1000); -#else - expect_value(__wrap_sleep, seconds, config->upgrade_wait_start * config->upgrade_wait_factor_increase); -#endif - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "0\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "0\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}'"); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, config->upgrade_wait_start * config->upgrade_wait_factor_increase * config->upgrade_wait_factor_increase * 1000); -#else - expect_value(__wrap_sleep, seconds, config->upgrade_wait_start * config->upgrade_wait_factor_increase * config->upgrade_wait_factor_increase); -#endif - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, (FILE*)1); - -#ifdef TEST_WINAGENT - expect_value(wrap_fgets, __stream, (FILE*)1); - will_return(wrap_fgets, "0\n"); -#else - expect_value(__wrap_fgets, __stream, (FILE*)1); - will_return(__wrap_fgets, "0\n"); -#endif - - expect_value(__wrap_fclose, _File, (FILE*)1); - will_return(__wrap_fclose, 1); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue); - expect_string(__wrap_wm_sendmsg, message, "{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, task_manager_modules_list[WM_TASK_UPGRADE_MODULE]); - expect_value(__wrap_wm_sendmsg, loc, UPGRADE_MQ); - - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8163): Sending upgrade ACK event: " - "'{\"command\":\"upgrade_update_status\"," - "\"parameters\":{\"error\":0," - "\"message\":\"Upgrade was successful\"," - "\"status\":\"Done\"}}'"); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, config->upgrade_wait_max * 1000); -#else - expect_value(__wrap_sleep, seconds, config->upgrade_wait_max); -#endif - - expect_string(__wrap_wfopen, path, WM_AGENT_UPGRADE_RESULT_FILE); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - - wm_agent_upgrade_check_status(config); - - assert_int_equal(allow_upgrades, true); -} - -void test_wm_agent_upgrade_check_status_queue_error(void **state) -{ - int queue = -1; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_SUCCESSFUL; - wm_agent_configs *config = *state; - - config->upgrade_wait_start = 1; - config->upgrade_wait_max = 10; - config->upgrade_wait_factor_increase = 3; - - allow_upgrades = false; - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, queue); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME * 1000); -#else - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME); -#endif - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8113): Could not open default queue to send upgrade notification."); - - wm_agent_upgrade_check_status(config); - - assert_int_equal(allow_upgrades, true); -} - -#ifndef TEST_WINAGENT - -void test_wm_agent_upgrade_listen_messages_ok(void **state) -{ - int socket = 0; - int peer = 1111; - - char *input = "{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"file\":\"test.wpk\"," - " \"installer\":\"test.sh\"" - " }" - "}"; - - size_t input_size = strlen(input) + 1; - char *response = NULL; - os_calloc(OS_SIZE_256, sizeof(char), response); - - sprintf(response, "{" - " \"error\":0," - " \"data\":[]," - " \"message\":\"ok\"" - "}"); - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8155): Incomming message: '{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"file\":\"test.wpk\"," - " \"installer\":\"test.sh\"" - " }" - "}'"); - - expect_memory(__wrap_wm_agent_upgrade_process_command, buffer, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_process_command, response); - will_return(__wrap_wm_agent_upgrade_process_command, strlen(response)); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8156): Response message: '{" - " \"error\":0," - " \"data\":[]," - " \"message\":\"ok\"" - "}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_receive_empty(void **state) -{ - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8159): Empty message from local client."); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_receive_error(void **state) -{ - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8111): Error in recv(): 'Success'"); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_receive_sock_error(void **state) -{ - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_accept_error_eintr(void **state) -{ - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - errno = EINTR; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, -1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_accept_error(void **state) -{ - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - errno = 1; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8110): Error in accept(): 'Operation not permitted'"); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_select_zero(void **state) -{ - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, 0); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_select_error_eintr(void **state) -{ - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - errno = EINTR; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, -1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_select_error(void **state) -{ - int socket = 0; - errno = 1; - - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, socket); - - will_return(__wrap_select, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8109): Error in select(): 'Operation not permitted'. Exiting..."); - - wm_agent_upgrade_listen_messages(NULL); -} - -void test_wm_agent_upgrade_listen_messages_bind_error(void **state) -{ - expect_string(__wrap_OS_BindUnixDomain, path, AGENT_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_BindUnixDomain, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8108): Unable to bind to socket 'queue/ossec/upgrade': 'Operation not permitted'"); - - wm_agent_upgrade_listen_messages(NULL); -} - -#endif - -void test_wm_agent_upgrade_start_agent_module_enabled(void **state) -{ - int queue = -1; - int result = 0; - wm_upgrade_agent_state upgrade_state = WM_UPGRADE_SUCCESSFUL; - wm_agent_configs *config = *state; - - config->upgrade_wait_start = 1; - config->upgrade_wait_max = 10; - config->upgrade_wait_factor_increase = 3; - - allow_upgrades = false; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtinfo, formatted_msg, "(8153): Module Agent Upgrade started."); - -#ifndef TEST_WINAGENT - expect_memory(__wrap_CreateThread, function_pointer, wm_agent_upgrade_listen_messages, sizeof(wm_agent_upgrade_listen_messages)); -#endif - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, queue); - -#ifdef TEST_WINAGENT - expect_value(wrap_Sleep, dwMilliseconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME * 1000); -#else - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_RESULT_WAIT_TIME); -#endif - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8113): Could not open default queue to send upgrade notification."); - - wm_agent_upgrade_start_agent_module(config, 1); - - assert_int_equal(allow_upgrades, true); -} - -void test_wm_agent_upgrade_start_agent_module_disabled(void **state) -{ - wm_agent_configs *config = *state; - - allow_upgrades = false; - -#ifndef TEST_WINAGENT - expect_memory(__wrap_CreateThread, function_pointer, wm_agent_upgrade_listen_messages, sizeof(wm_agent_upgrade_listen_messages)); -#endif - - wm_agent_upgrade_start_agent_module(config, 0); - - assert_int_equal(allow_upgrades, false); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_upgrade_agent_send_ack_message - cmocka_unit_test_setup(test_wm_upgrade_agent_send_ack_message_successful, setup_test_executions), - cmocka_unit_test_setup(test_wm_upgrade_agent_send_ack_message_failed, setup_test_executions), - cmocka_unit_test_setup(test_wm_upgrade_agent_send_ack_message_error, setup_test_executions), - cmocka_unit_test_setup(test_wm_upgrade_agent_send_ack_message_error_exit, setup_test_executions), - // wm_upgrade_agent_search_upgrade_result - cmocka_unit_test_setup(test_wm_upgrade_agent_search_upgrade_result_successful, setup_test_executions), - cmocka_unit_test_setup(test_wm_upgrade_agent_search_upgrade_result_failed, setup_test_executions), - cmocka_unit_test_setup(test_wm_upgrade_agent_search_upgrade_result_failed_missing_dependency, setup_test_executions), - cmocka_unit_test_setup(test_wm_upgrade_agent_search_upgrade_result_error_open, setup_test_executions), - cmocka_unit_test_setup(test_wm_upgrade_agent_search_upgrade_result_error_code, setup_test_executions), - // wm_agent_upgrade_check_status - cmocka_unit_test_setup(test_wm_agent_upgrade_check_status_successful, setup_test_executions), - cmocka_unit_test_setup(test_wm_agent_upgrade_check_status_time_limit, setup_test_executions), - cmocka_unit_test_setup(test_wm_agent_upgrade_check_status_queue_error, setup_test_executions), -#ifndef TEST_WINAGENT - // wm_agent_upgrade_listen_messages - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_ok), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_receive_empty), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_receive_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_receive_sock_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_accept_error_eintr), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_accept_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_select_zero), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_select_error_eintr), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_select_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_bind_error), -#endif - // wm_agent_upgrade_start_agent_module - cmocka_unit_test_setup(test_wm_agent_upgrade_start_agent_module_enabled, setup_test_executions), - cmocka_unit_test(test_wm_agent_upgrade_start_agent_module_disabled) - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_com.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_com.c deleted file mode 100644 index 1e9332fd273..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_com.c +++ /dev/null @@ -1,1921 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../wazuh_modules/wm_task_general.h" -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/wm_agent_upgrade.h" -#include "../../wazuh_modules/agent_upgrade/agent/wm_agent_upgrade_agent.h" - -#include "../../wrappers/common.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../../wrappers/libc/string_wrappers.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/posix/unistd_wrappers.h" -#include "../../wrappers/externals/zlib/zlib_wrappers.h" - -extern int test_mode; - -extern size_t __real_strlen(const char *s); - -extern int _jailfile(char finalpath[PATH_MAX + 1], const char * basedir, const char * filename); -extern int _unsign(const char * source, char dest[PATH_MAX + 1]); -extern int _uncompress(const char * source, const char *package, char dest[PATH_MAX + 1]); - -extern char * wm_agent_upgrade_com_open(const cJSON* json_object); -extern char * wm_agent_upgrade_com_write(const cJSON* json_object); -extern char * wm_agent_upgrade_com_close(const cJSON* json_object); -extern char * wm_agent_upgrade_com_sha1(const cJSON* json_object); -extern char * wm_agent_upgrade_com_upgrade(const cJSON* json_object); -extern char * wm_agent_upgrade_com_clear_result(); - -extern struct {char path[PATH_MAX + 1]; FILE * fp;} file; -extern const char * error_messages[]; -/* Internal methods tests */ - -int setup_jailfile(void **state) { - char *filename = malloc(sizeof(char) * OS_MAXSTR); - sprintf(filename, "test_filename"); - *state = filename; - test_mode = 1; - return 0; -} - -#ifdef TEST_WINAGENT -int setup_jailfile_long_name(void **state) { - char *filename = malloc(sizeof(char) * OS_MAXSTR); - const unsigned int length = PATH_MAX - strlen(INCOMING_DIR) - 2; - for(int i=0; i < length; i++) { - sprintf(&filename[i], "a"); - } - *state = filename; - test_mode = 1; - return 0; -} -#endif - -int setup_jailfile_long_name2(void **state) { - char *filename = malloc(sizeof(char) * OS_MAXSTR); - const unsigned int length = PATH_MAX - strlen(TMP_DIR) - 2; - for(int i=0; i < length; i++) { - sprintf(&filename[i], "a"); - } - *state = filename; - test_mode = 1; - return 0; -} - -int teardown_jailfile(void **state) { - char *filename = *state; - test_mode = 0; - os_free(filename); - return 0; -} - -int setup_clear_result(void **state) { - test_mode = 1; - return 0; -} - -int teadown_clear_result(void **state) { - test_mode = 0; - return 0; -} - -void test_jailfile_invalid_path(void **state) { - char finalpath[PATH_MAX + 1]; - char *filename = *state; - - expect_string(__wrap_w_ref_parent_folder, path, filename); - will_return(__wrap_w_ref_parent_folder, 1); - int ret = _jailfile(finalpath, TMP_DIR, filename); - assert_int_equal(ret, -1); -} - -void test_jailfile_valid_path(void **state) { - char finalpath[PATH_MAX + 1]; - char *filename = *state; - - expect_string(__wrap_w_ref_parent_folder, path, filename); - will_return(__wrap_w_ref_parent_folder, 0); - int ret = _jailfile(finalpath, TMP_DIR, filename); - assert_int_equal(ret, 0); -#ifdef TEST_WINAGENT - assert_string_equal(finalpath, "tmp\\test_filename"); -#else - assert_string_equal(finalpath, "tmp/test_filename"); -#endif -} - -void test_unsign_invalid_source_incomming(void **state) { - char finalpath[PATH_MAX + 1]; - char *source = *state; - - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 1); - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At unsign(): Invalid file name."); - int ret = _unsign(source, finalpath); - assert_int_equal(ret, -1); -} - -void test_unsign_invalid_source_temp(void **state) { - char finalpath[PATH_MAX + 1]; - char *source = *state; - - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 1); - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At unsign(): Invalid file name."); - int ret = _unsign(source, finalpath); - assert_int_equal(ret, -1); -} - -#ifdef TEST_WINAGENT -void test_unsign_invalid_source_len(void **state) { - char finalpath[PATH_MAX + 1]; - char *source = *state; - - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8137): At unsign(): Too long temp file."); - - int ret = _unsign(source, finalpath); - assert_int_equal(ret, -1); -} -#endif - -void test_unsign_temp_file_fail(void **state) { - char finalpath[PATH_MAX + 1]; - char *source = *state; - - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - -#ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, 1); -#else - will_return(__wrap_mkstemp, -1); -#endif - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8138): At unsign(): Could not create temporary compressed file."); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - int ret = _unsign(source, finalpath); - assert_int_equal(ret, -1); -} - -void test_unsign_wpk_using_fail(void **state) { - char finalpath[PATH_MAX + 1]; - char *source = *state; - - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - -#ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_filename"); - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8139): At unsign(): Could not unsign package file 'incoming\\test_filename'"); -#else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_filename"); - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8139): At unsign(): Could not unsign package file 'var/incoming/test_filename'"); -#endif - will_return(__wrap_w_wpk_unsign, -1); - expect_any_count(__wrap_unlink, file, 2); - will_return_count(__wrap_unlink, 0, 2); - - int ret = _unsign(source, finalpath); - assert_int_equal(ret, -1); -} - -void test_unsign_temp_chmod_fail(void **state) { - char finalpath[PATH_MAX + 1]; - char *source = *state; - - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, -1); - - expect_any_count(__wrap_unlink, file, 2); - will_return_count(__wrap_unlink, 0, 2); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8134): At unsign(): Could not chmod 'tmp/test_filename.gz.XXXXXX'"); - - int ret = _unsign(source, finalpath); - assert_int_equal(ret, -1); -} - -void test_unsign_success(void **state) { - char finalpath[PATH_MAX + 1]; - char *source = *state; - - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, source); - will_return(__wrap_w_ref_parent_folder, 0); - -#ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_filename"); -#else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_filename"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); -#endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - int ret = _unsign(source, finalpath); - assert_int_equal(ret, 0); -} - - -void test_uncompress_invalid_filename(void **state) { - char compressed[PATH_MAX + 1]; - char merged[PATH_MAX + 1]; - char *package = *state; - - expect_string(__wrap_w_ref_parent_folder, path, package); - will_return(__wrap_w_ref_parent_folder, 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At uncompress(): Invalid file name."); - - int ret = _uncompress(compressed, package, merged); - assert_int_equal(ret, -1); -} - -void test_uncompress_invalid_file_len(void **state) { - char merged[PATH_MAX + 1]; - char *package = *state; - - expect_string(__wrap_w_ref_parent_folder, path, package); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8137): At uncompress(): Too long temp file."); - - int ret = _uncompress("compressed_test", package, merged); - assert_int_equal(ret, -1); -} - -void test_uncompress_gzopen_fail(void **state) { - char merged[PATH_MAX + 1]; - char *package = *state; - - expect_string(__wrap_w_ref_parent_folder, path, package); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap_gzopen, path, "compressed_test"); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, NULL); - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8140): At uncompress(): Unable to open 'compressed_test'"); - - int ret = _uncompress("compressed_test", package, merged); - assert_int_equal(ret, -1); -} - -void test_uncompress_fopen_fail(void **state) { - char merged[PATH_MAX + 1]; - char *package = *state; - - expect_string(__wrap_w_ref_parent_folder, path, package); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap_gzopen, path, "compressed_test"); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); -#ifdef TEST_WINAGENT - expect_string(__wrap__mterror, formatted_msg, "(8140): At uncompress(): Unable to open 'tmp\\test_filename.mg.XXXXXX'"); -#else - expect_string(__wrap__mterror, formatted_msg, "(8140): At uncompress(): Unable to open 'tmp/test_filename.mg.XXXXXX'"); -#endif - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - int ret = _uncompress("compressed_test", package, merged); - assert_int_equal(ret, -1); -} - -void test_uncompress_fwrite_fail(void **state) { - char merged[PATH_MAX + 1]; - char *package = *state; - - expect_string(__wrap_w_ref_parent_folder, path, package); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap_gzopen, path, "compressed_test"); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, -1); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8129): At uncompress(): Cannot write on 'compressed_test'"); - - int ret = _uncompress("compressed_test", package, merged); - assert_int_equal(ret, -1); -} - -void test_uncompress_gzread_fail(void **state) { - char merged[PATH_MAX + 1]; - char *package = *state; - - expect_string(__wrap_w_ref_parent_folder, path, package); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap_gzopen, path, "compressed_test"); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, -1); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8141): At uncompress(): Unable to read 'compressed_test'"); - - int ret = _uncompress("compressed_test", package, merged); - assert_int_equal(ret, -1); -} - -void test_uncompress_success(void **state) { - char merged[PATH_MAX + 1]; - char *package = *state; - - expect_string(__wrap_w_ref_parent_folder, path, package); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap_gzopen, path, "compressed_test"); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - int ret = _uncompress("compressed_test", package, merged); - assert_int_equal(ret, 0); -} - -/* Commands tests */ -int setup_open1(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "mode", "r"); - cJSON_AddStringToObject(command, "file", "test_file"); - *state = command; - test_mode = 1; - return 0; -} - -int setup_open2(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "mode", "w"); - cJSON_AddStringToObject(command, "file", "test_file"); - *state = command; - test_mode = 1; - return 0; -} - -int setup_write(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "buffer", "ABCDABCD"); - cJSON_AddStringToObject(command, "file", "test_file"); - cJSON_AddNumberToObject(command, "length", 8); - *state = command; - test_mode = 1; - return 0; -} - -int setup_sha1(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "file", "test_file"); - *state = command; - test_mode = 1; - return 0; -} - -int setup_upgrade(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "file", "test_file"); - cJSON_AddStringToObject(command, "installer", "install.sh"); - *state = command; - test_mode = 1; - return 0; -} - -int teardown_commands(void **state) { - cJSON * command = *state; - test_mode = 0; - cJSON_Delete(command); - return 0; -} - -void test_wm_agent_upgrade_com_open_unsopported_mode(void **state) { - cJSON * command = *state; - - sprintf(file.path, "existent_path"); - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtwarn, formatted_msg, "(8124): At open: File 'existent_path' was opened. Closing."); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8125): At open: Unsupported mode."); - - char *response = wm_agent_upgrade_com_open(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Unsupported file mode"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_open_invalid_file_name(void **state) { - cJSON * command = *state; - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At open: Invalid file name."); - - char *response = wm_agent_upgrade_com_open(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Invalid file name"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_open_invalid_open(void **state) { - cJSON * command = *state; - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(1103): Could not open file 'test_file' due to [(2)-(No such file or directory)]."); - - errno = 2; - - char *response = wm_agent_upgrade_com_open(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "File Open Error: No such file or directory"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_open_success(void **state) { - cJSON * command = *state; - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 4); - - char *response = wm_agent_upgrade_com_open(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "ok"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_write_file_closed(void **state) { - cJSON * command = *state; - - sprintf(file.path, "%s", "\0"); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8127): At write: File not opened. Agent might have been auto-restarted during upgrade."); - - char *response = wm_agent_upgrade_com_write(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "File not opened. Agent might have been auto-restarted during upgrade"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_write_invalid_file_name(void **state) { - cJSON * command = *state; - - sprintf(file.path, "%s", "test_file"); - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At write: Invalid file name."); - - char *response = wm_agent_upgrade_com_write(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Invalid file name"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_write_different_file_name(void **state) { - cJSON * command = *state; - - sprintf(file.path, "%s", "test_file_different"); - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8128): At write: The target file doesn't match the opened file 'test_file_different'"); - - char *response = wm_agent_upgrade_com_write(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "The target file doesn't match the opened file"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_write_error(void **state) { - cJSON * command = *state; -#ifdef TEST_WINAGENT - sprintf(file.path, "incoming\\test_file"); -#else - sprintf(file.path, "var/incoming/test_file"); -#endif - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - will_return(__wrap_fwrite, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); -#ifdef TEST_WINAGENT - expect_string(__wrap__mterror, formatted_msg, "(8129): At write: Cannot write on 'incoming\\test_file'"); -#else - expect_string(__wrap__mterror, formatted_msg, "(8129): At write: Cannot write on 'var/incoming/test_file'"); -#endif - - char *response = wm_agent_upgrade_com_write(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Cannot write file"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_write_success(void **state) { - cJSON * command = *state; -#ifdef TEST_WINAGENT - sprintf(file.path, "incoming\\test_file"); -#else - sprintf(file.path, "var/incoming/test_file"); -#endif - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - will_return(__wrap_fwrite, 8); - - char *response = wm_agent_upgrade_com_write(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "ok"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_close_file_opened(void **state) { - cJSON * command = *state; - - sprintf(file.path, "%s", "\0"); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8130): At close: No file is opened."); - - char *response = wm_agent_upgrade_com_close(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "No file opened"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_close_invalid_file_name(void **state) { - cJSON * command = *state; - - sprintf(file.path, "test_file"); - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At close: Invalid file name."); - - char *response = wm_agent_upgrade_com_close(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Invalid file name"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_close_different_file_name(void **state) { - cJSON * command = *state; - - sprintf(file.path, "%s", "test_file_different"); - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8128): At close: The target file doesn't match the opened file 'test_file_different'"); - - char *response = wm_agent_upgrade_com_close(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "The target file doesn't match the opened file"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_close_failed(void **state) { - cJSON * command = *state; - - #ifdef TEST_WINAGENT - sprintf(file.path, "incoming\\test_file"); - #else - sprintf(file.path, "var/incoming/test_file"); - #endif - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, -1); - - errno = EPERM; - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8131): At close: 'Operation not permitted'"); - - char *response = wm_agent_upgrade_com_close(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Cannot close file"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_close_success(void **state) { - cJSON * command = *state; - - #ifdef TEST_WINAGENT - sprintf(file.path, "incoming\\test_file"); - #else - sprintf(file.path, "var/incoming/test_file"); - #endif - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 0); - - char *response = wm_agent_upgrade_com_close(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "ok"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_sha1_invalid_file(void **state) { - cJSON * command = *state; - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At sha1: Invalid file name."); - - char *response = wm_agent_upgrade_com_sha1(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Invalid file name"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_sha1_sha_error(void **state) { - cJSON * command = *state; - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_OS_SHA1_File, fname); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, ""); - will_return(__wrap_OS_SHA1_File, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8132): At sha1: Error generating SHA1."); - - char *response = wm_agent_upgrade_com_sha1(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Cannot generate SHA1"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_sha1_sha_success(void **state) { - cJSON * command = *state; - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_OS_SHA1_File, fname); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, "2c312ada12ab321a253ad321af65983fa412e3a1"); - will_return(__wrap_OS_SHA1_File, 0); - - char *response = wm_agent_upgrade_com_sha1(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "2c312ada12ab321a253ad321af65983fa412e3a1"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_upgrade_unsign_error(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 1); - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At unsign(): Invalid file name."); - } - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8131): At upgrade: 'Could not verify signature'"); - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Could not verify signature"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_upgrade_uncompress_error(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - // Uncompress - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 1); - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At uncompress(): Invalid file name."); - } - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8131): At upgrade: 'Could not uncompress package'"); - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Could not uncompress package"); - cJSON_Delete(response_object); - os_free(response); -} - - -void test_wm_agent_upgrade_com_upgrade_clean_directory_error(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - // Uncompress - { - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_gzopen, path); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - will_return(__wrap_cldir_ex, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8131): At upgrade: 'Could not clean up upgrade directory'"); - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Could not clean up upgrade directory"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_unmerge_error(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - // Uncompress - { - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_gzopen, path); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - will_return(__wrap_cldir_ex, 0); - - expect_any(__wrap_UnmergeFiles, finalpath); - expect_any(__wrap_UnmergeFiles, optdir); - expect_value(__wrap_UnmergeFiles, mode, OS_BINARY); - will_return(__wrap_UnmergeFiles, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_any(__wrap__mterror, formatted_msg); - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Error unmerging file"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_installer_error(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - // Uncompress - { - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_gzopen, path); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - will_return(__wrap_cldir_ex, 0); - - expect_any(__wrap_UnmergeFiles, finalpath); - expect_any(__wrap_UnmergeFiles, optdir); - expect_value(__wrap_UnmergeFiles, mode, OS_BINARY); - will_return(__wrap_UnmergeFiles, -1); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8126): At upgrade: Invalid file name."); - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Invalid file name"); - cJSON_Delete(response_object); - os_free(response); -} - -#ifndef TEST_WINAGENT -void test_wm_agent_upgrade_com_chmod_error(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - // Uncompress - { - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_gzopen, path); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - will_return(__wrap_cldir_ex, 0); - - expect_any(__wrap_UnmergeFiles, finalpath); - expect_any(__wrap_UnmergeFiles, optdir); - expect_value(__wrap_UnmergeFiles, mode, OS_BINARY); - will_return(__wrap_UnmergeFiles, -1); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - // Jailfile - { - expect_string(__wrap_w_ref_parent_folder, path, "install.sh"); - will_return(__wrap_w_ref_parent_folder, 0); - } - - expect_string(__wrap_chmod, path, "var/upgrade/install.sh"); - will_return(__wrap_chmod, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8134): At upgrade: Could not chmod 'var/upgrade/install.sh'"); - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Could not chmod"); - cJSON_Delete(response_object); - os_free(response); -} -#endif - -void test_wm_agent_upgrade_com_execute_error(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - // Uncompress - { - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_gzopen, path); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - will_return(__wrap_cldir_ex, 0); - - expect_any(__wrap_UnmergeFiles, finalpath); - expect_any(__wrap_UnmergeFiles, optdir); - expect_value(__wrap_UnmergeFiles, mode, OS_BINARY); - will_return(__wrap_UnmergeFiles, -1); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - // Jailfile - { - expect_string(__wrap_w_ref_parent_folder, path, "install.sh"); - will_return(__wrap_w_ref_parent_folder, 0); - } - - #ifndef TEST_WINAGENT - expect_string(__wrap_chmod, path, "var/upgrade/install.sh"); - will_return(__wrap_chmod, 0); - expect_string(__wrap_wm_exec, command, "var/upgrade/install.sh"); - - #else - expect_string(__wrap_wm_exec, command, "upgrade\\install.sh"); - #endif - - - expect_value(__wrap_wm_exec, secs, 3600); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, "OUTPUT COMMAND"); - will_return(__wrap_wm_exec, -1); - will_return(__wrap_wm_exec, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - - #ifndef TEST_WINAGENT - expect_string(__wrap__mterror, formatted_msg, "(8135): At upgrade: Error executing command [var/upgrade/install.sh]"); - #else - expect_string(__wrap__mterror, formatted_msg, "(8135): At upgrade: Error executing command [upgrade\\install.sh]"); - #endif - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Error executing command"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_success(void **state) { - cJSON * command = *state; - - will_return(__wrap_getDefine_Int, 3600); - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - // Uncompress - { - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_gzopen, path); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - will_return(__wrap_cldir_ex, 0); - - expect_any(__wrap_UnmergeFiles, finalpath); - expect_any(__wrap_UnmergeFiles, optdir); - expect_value(__wrap_UnmergeFiles, mode, OS_BINARY); - will_return(__wrap_UnmergeFiles, -1); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - // Jailfile - { - expect_string(__wrap_w_ref_parent_folder, path, "install.sh"); - will_return(__wrap_w_ref_parent_folder, 0); - } - - #ifndef TEST_WINAGENT - expect_string(__wrap_chmod, path, "var/upgrade/install.sh"); - will_return(__wrap_chmod, 0); - expect_string(__wrap_wm_exec, command, "var/upgrade/install.sh"); - - #else - expect_string(__wrap_wm_exec, command, "upgrade\\install.sh"); - #endif - - - expect_value(__wrap_wm_exec, secs, 3600); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, "OUTPUT COMMAND"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - char *response = wm_agent_upgrade_com_upgrade(command); - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "0"); - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_clear_result_failed(void **state) { - allow_upgrades = false; - - #ifndef TEST_WINAGENT - expect_string(__wrap_remove, filename, "var/upgrade/upgrade_result"); - #else - expect_string(__wrap_remove, filename, "upgrade\\upgrade_result"); - #endif - will_return(__wrap_remove, -1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - #ifndef TEST_WINAGENT - expect_string(__wrap__mtdebug1, formatted_msg, "(8136): At clear_upgrade_result: Could not erase file 'var/upgrade/upgrade_result'"); - #else - expect_string(__wrap__mtdebug1, formatted_msg, "(8136): At clear_upgrade_result: Could not erase file 'upgrade\\upgrade_result'"); - #endif - - char *response = wm_agent_upgrade_com_clear_result(); - - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "Could not erase upgrade_result file"); - - assert_int_equal(allow_upgrades, false); - - cJSON_Delete(response_object); - os_free(response); -} - -void test_wm_agent_upgrade_com_clear_result_success(void **state) { - allow_upgrades = false; - - #ifndef TEST_WINAGENT - expect_string(__wrap_remove, filename, "var/upgrade/upgrade_result"); - #else - expect_string(__wrap_remove, filename, "upgrade\\upgrade_result"); - #endif - will_return(__wrap_remove, 0); - - char *response = wm_agent_upgrade_com_clear_result(); - - cJSON *response_object = cJSON_Parse(response); - assert_string_equal(cJSON_GetObjectItem(response_object, task_manager_json_keys[WM_TASK_ERROR_MESSAGE])->valuestring, "ok"); - - assert_int_equal(allow_upgrades, true); - - cJSON_Delete(response_object); - os_free(response); -} - -/* Process commands */ -int setup_process_clear_upgrade(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "clear_upgrade_result"); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -int teardown_process(void **state) { - char *buffer = *state; - os_free(buffer); - allow_upgrades = true; - test_mode = 0; - return 0; -} - -int setup_process_no_parameters(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "open"); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -int setup_process_open(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "open"); - cJSON * parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "mode", "w"); - cJSON_AddStringToObject(parameters, "file", "test_file"); - cJSON_AddItemToObject(command, "parameters", parameters); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -int setup_process_write(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "write"); - cJSON * parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "buffer", "ABCDABCD"); - cJSON_AddStringToObject(parameters, "file", "test_file"); - cJSON_AddNumberToObject(parameters, "length", 8); - cJSON_AddItemToObject(command, "parameters", parameters); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -int setup_process_close(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "close"); - cJSON * parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "file", "test_file"); - cJSON_AddItemToObject(command, "parameters", parameters); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -int setup_process_sha1(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "sha1"); - cJSON * parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "file", "test_file"); - cJSON_AddItemToObject(command, "parameters", parameters); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -int setup_process_upgrade(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "upgrade"); - cJSON * parameters = cJSON_CreateObject(); - cJSON_AddStringToObject(parameters, "file", "test_file"); - cJSON_AddStringToObject(parameters, "installer", "install.sh"); - cJSON_AddItemToObject(command, "parameters", parameters); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -int setup_process_upgrade_not_allowed(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "open"); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - // Turn off upgrades - allow_upgrades = false; - return 0; -} - -int setup_process_unknown(void **state) { - cJSON * command = cJSON_CreateObject(); - cJSON_AddStringToObject(command, "command", "abcd"); - cJSON * parameters = cJSON_CreateObject(); - cJSON_AddItemToObject(command, "parameters", parameters); - char *ptr = cJSON_PrintUnformatted(command); - *state = ptr; - cJSON_Delete(command); - test_mode = 1; - return 0; -} - -void test_wm_agent_upgrade_process_clear_command(void **state) { - char * buffer = *state; - char *output = NULL; - - { - #ifndef TEST_WINAGENT - expect_string(__wrap_remove, filename, "var/upgrade/upgrade_result"); - #else - expect_string(__wrap_remove, filename, "upgrade\\upgrade_result"); - #endif - will_return(__wrap_remove, 0); - } - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "ok"); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_open_no_parameters(void **state) { - char * buffer = *state; - char *output = NULL; - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Required parameters were not found"); - assert_int_not_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_open_command(void **state) { - char * buffer = *state; - char *output = NULL; - // Open - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "w"); - will_return(__wrap_wfopen, 4); - } - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "ok"); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_write_command(void **state) { - char * buffer = *state; - char *output = NULL; - // Write - { - #ifdef TEST_WINAGENT - sprintf(file.path, "incoming\\test_file"); - #else - sprintf(file.path, "var/incoming/test_file"); - #endif - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - will_return(__wrap_fwrite, 8); - } - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "ok"); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_close_command(void **state) { - char * buffer = *state; - char *output = NULL; - // Close - { - #ifdef TEST_WINAGENT - sprintf(file.path, "incoming\\test_file"); - #else - sprintf(file.path, "var/incoming/test_file"); - #endif - - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_fclose, _File); - will_return(__wrap_fclose, 0); - } - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "ok"); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_sha1_command(void **state) { - char * buffer = *state; - char *output = NULL; - // sha1 - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_OS_SHA1_File, fname); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, "2c312ada12ab321a253ad321af65983fa412e3a1"); - will_return(__wrap_OS_SHA1_File, 0); - } - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "2c312ada12ab321a253ad321af65983fa412e3a1"); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_upgrade_command(void **state) { - char * buffer = *state; - char *output = NULL; - // upgrade - { - will_return(__wrap_getDefine_Int, 3600); - // Unsign - { - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - expect_string(__wrap_w_ref_parent_folder, path, "test_file"); - will_return(__wrap_w_ref_parent_folder, 0); - - #ifdef TEST_WINAGENT - will_return(wrap_mktemp_s, NULL); - expect_string(__wrap_w_wpk_unsign, source, "incoming\\test_file"); - #else - expect_string(__wrap_w_wpk_unsign, source, "var/incoming/test_file"); - - will_return(__wrap_mkstemp, 8); - expect_any(__wrap_chmod, path); - will_return(__wrap_chmod, 0); - #endif - will_return(__wrap_w_wpk_unsign, 0); - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - // Uncompress - { - expect_any(__wrap_w_ref_parent_folder, path); - will_return(__wrap_w_ref_parent_folder, 0); - - expect_any(__wrap_gzopen, path); - expect_string(__wrap_gzopen, mode, "rb"); - will_return(__wrap_gzopen, 4); - - expect_any(__wrap_wfopen, path); - expect_string(__wrap_wfopen, mode, "wb"); - will_return(__wrap_wfopen, 5); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 4); - will_return(__wrap_gzread, "test"); - - will_return(__wrap_fwrite, 4); - - expect_value(__wrap_gzread, gz_fd, 4); - will_return(__wrap_gzread, 0); - - expect_value(__wrap_gzclose, file, 4); - will_return(__wrap_gzclose, 0); - - expect_value(__wrap_fclose, _File, 5); - will_return(__wrap_fclose, 0); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - } - - will_return(__wrap_cldir_ex, 0); - - expect_any(__wrap_UnmergeFiles, finalpath); - expect_any(__wrap_UnmergeFiles, optdir); - expect_value(__wrap_UnmergeFiles, mode, OS_BINARY); - will_return(__wrap_UnmergeFiles, -1); - - expect_any(__wrap_unlink, file); - will_return(__wrap_unlink, 0); - - // Jailfile - { - expect_string(__wrap_w_ref_parent_folder, path, "install.sh"); - will_return(__wrap_w_ref_parent_folder, 0); - } - - #ifndef TEST_WINAGENT - expect_string(__wrap_chmod, path, "var/upgrade/install.sh"); - will_return(__wrap_chmod, 0); - expect_string(__wrap_wm_exec, command, "var/upgrade/install.sh"); - - #else - expect_string(__wrap_wm_exec, command, "upgrade\\install.sh"); - #endif - - - expect_value(__wrap_wm_exec, secs, 3600); - expect_value(__wrap_wm_exec, add_path, NULL); - will_return(__wrap_wm_exec, "OUTPUT COMMAND"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - } - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "0"); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_upgrade_not_allowed(void **state) { - char * buffer = *state; - char *output = NULL; - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Upgrade module is disabled or not ready yet"); - assert_int_not_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -void test_wm_agent_upgrade_process_unknown(void **state) { - char * buffer = *state; - char *output = NULL; - - size_t length = wm_agent_upgrade_process_command(buffer, &output); - cJSON *response = cJSON_Parse(output); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Command not found"); - assert_int_not_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_int_equal(strlen(output), length); - cJSON_Delete(response); - os_free(output); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_jailfile_invalid_path, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_jailfile_valid_path, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_unsign_invalid_source_incomming, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_unsign_invalid_source_temp, setup_jailfile, teardown_jailfile), - #ifdef TEST_WINAGENT - cmocka_unit_test_setup_teardown(test_unsign_invalid_source_len, setup_jailfile_long_name, teardown_jailfile), - #endif - cmocka_unit_test_setup_teardown(test_unsign_temp_file_fail, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_unsign_wpk_using_fail, setup_jailfile, teardown_jailfile), - #ifndef TEST_WINAGENT - cmocka_unit_test_setup_teardown(test_unsign_temp_chmod_fail, setup_jailfile, teardown_jailfile), - #endif - cmocka_unit_test_setup_teardown(test_unsign_success, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_uncompress_invalid_filename, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_uncompress_invalid_file_len, setup_jailfile_long_name2, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_uncompress_gzopen_fail, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_uncompress_fopen_fail, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_uncompress_fwrite_fail, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_uncompress_gzread_fail, setup_jailfile, teardown_jailfile), - cmocka_unit_test_setup_teardown(test_uncompress_success, setup_jailfile, teardown_jailfile), - // Test commands - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_open_unsopported_mode, setup_open1, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_open_invalid_file_name, setup_open2, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_open_invalid_open, setup_open2, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_open_success, setup_open2, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_write_file_closed, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_write_invalid_file_name, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_write_different_file_name, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_write_error, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_write_success, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_close_file_opened, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_close_invalid_file_name, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_close_different_file_name, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_close_failed, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_close_success, setup_write, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_sha1_invalid_file, setup_sha1, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_sha1_sha_error, setup_sha1, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_sha1_sha_success, setup_sha1, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_upgrade_unsign_error, setup_upgrade, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_upgrade_uncompress_error, setup_upgrade, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_upgrade_clean_directory_error, setup_upgrade, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_unmerge_error, setup_upgrade, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_installer_error, setup_upgrade, teardown_commands), - #ifndef TEST_WINAGENT - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_chmod_error, setup_upgrade, teardown_commands), - #endif - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_execute_error, setup_upgrade, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_success, setup_upgrade, teardown_commands), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_clear_result_failed, setup_clear_result, teadown_clear_result), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_com_clear_result_success, setup_clear_result, teadown_clear_result), - // Command dispatcher - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_clear_command, setup_process_clear_upgrade, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_open_no_parameters, setup_process_no_parameters, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_open_command, setup_process_open, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_write_command, setup_process_write, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_close_command, setup_process_close, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_sha1_command, setup_process_sha1, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_upgrade_command, setup_process_upgrade, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_upgrade_not_allowed, setup_process_upgrade_not_allowed, teardown_process), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_unknown, setup_process_unknown, teardown_process) - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_commands.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_commands.c deleted file mode 100644 index 38800114845..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_commands.c +++ /dev/null @@ -1,1781 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_manager.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_tasks.h" -#include "../../headers/shared.h" - -int wm_agent_upgrade_analyze_agent(int agent_id, wm_agent_task *agent_task); -int wm_agent_upgrade_validate_agent_task(const wm_agent_task *agent_task); -int wm_agent_upgrade_create_upgrade_tasks(cJSON *data_array, wm_upgrade_command command); - -// Setup / teardown - -static int teardown_json(void **state) { - cJSON *json = *state; - cJSON_Delete(json); - return 0; -} - -static int teardown_string(void **state) { - char *string = *state; - os_free(string); - return 0; -} - -static int setup_agent_task(void **state) { - wm_agent_task *agent_task = NULL; - agent_task = wm_agent_upgrade_init_agent_task(); - agent_task->agent_info = wm_agent_upgrade_init_agent_info(); - agent_task->task_info = wm_agent_upgrade_init_task_info(); - *state = (void *)agent_task; - return 0; -} - -static int teardown_agent_task(void **state) { - wm_agent_task *agent_task = *state; - wm_agent_upgrade_free_agent_task(agent_task); - return 0; -} - -static int setup_analyze_agent_task(void **state) { - setup_hash_table(NULL); - wm_agent_task *agent_task = NULL; - agent_task = wm_agent_upgrade_init_agent_task(); - agent_task->task_info = wm_agent_upgrade_init_task_info(); - *state = (void *)agent_task; - return 0; -} - -static int teardown_analyze_agent_task(void **state) { - teardown_hash_table(); - wm_agent_task *agent_task = *state; - wm_agent_upgrade_free_agent_task(agent_task); - return 0; -} - -static int teardown_agent_status_task_string(void **state) { - wm_upgrade_agent_status_task *task = state[0]; - char *string = state[1]; - wm_agent_upgrade_free_agent_status_task(task); - os_free(string); - return 0; -} - -static int setup_process_hash_table(void **state) { - setup_hash_table(wm_agent_upgrade_free_agent_task); - return 0; -} - -static int teardown_upgrade_custom_task_string(void **state) { - teardown_hash_table(); - wm_upgrade_custom_task *task = state[0]; - char *string = state[1]; - wm_agent_upgrade_free_upgrade_custom_task(task); - os_free(string); - return 0; -} - -static int teardown_upgrade_task_string(void **state) { - teardown_hash_table(); - wm_upgrade_task *task = state[0]; - char *string = state[1]; - wm_agent_upgrade_free_upgrade_task(task); - os_free(string); - return 0; -} - -// Tests - -void test_wm_agent_upgrade_cancel_pending_upgrades(void **state) -{ - (void) state; - - cJSON *request = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(request, "origin", origin); - cJSON_AddStringToObject(request, "command", "upgrade_cancel_tasks"); - cJSON_AddItemToObject(request, "parameters", parameters); - - cJSON *task_response = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task_response, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_CANCEL_TASKS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request, sizeof(request)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - wm_agent_upgrade_cancel_pending_upgrades(); -} - -void test_wm_agent_upgrade_validate_agent_task_upgrade_ok(void **state) -{ - (void) state; - - int agent = 44; - char *platform = "ubuntu"; - char *os_major = "18"; - char *os_minor = "04"; - char *arch = "x64_86"; - char *wazuh_version = "v3.13.1"; - char *status = AGENT_CS_ACTIVE; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - agent_task->agent_info->agent_id = agent; - os_strdup(platform, agent_task->agent_info->platform); - os_strdup(os_major, agent_task->agent_info->major_version); - os_strdup(os_minor, agent_task->agent_info->minor_version); - os_strdup(arch, agent_task->agent_info->architecture); - os_strdup(wazuh_version, agent_task->agent_info->wazuh_version); - os_strdup(status, agent_task->agent_info->connection_status); - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, platform); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, os_major); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, os_minor); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, arch); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, wazuh_version); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, platform); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, agent_task->task_info->command); - will_return(__wrap_wm_agent_upgrade_validate_version, "v4.1.0"); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_SUCCESS); - - int ret = wm_agent_upgrade_validate_agent_task(agent_task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_agent_task_upgrade_custom_ok(void **state) -{ - (void) state; - - int agent = 44; - char *platform = "ubuntu"; - char *os_major = "18"; - char *os_minor = "04"; - char *arch = "x64_86"; - char *wazuh_version = "v3.13.1"; - char *status = AGENT_CS_ACTIVE; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - - wm_agent_task *agent_task = *state; - - agent_task->agent_info->agent_id = agent; - os_strdup(platform, agent_task->agent_info->platform); - os_strdup(os_major, agent_task->agent_info->major_version); - os_strdup(os_minor, agent_task->agent_info->minor_version); - os_strdup(arch, agent_task->agent_info->architecture); - os_strdup(wazuh_version, agent_task->agent_info->wazuh_version); - os_strdup(status, agent_task->agent_info->connection_status); - upgrade_custom_task = wm_agent_upgrade_init_upgrade_custom_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE_CUSTOM; - agent_task->task_info->task = upgrade_custom_task; - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, platform); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, os_major); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, os_minor); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, arch); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, wazuh_version); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, platform); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, agent_task->task_info->command); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_SUCCESS); - - int ret = wm_agent_upgrade_validate_agent_task(agent_task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_agent_task_version_err(void **state) -{ - (void) state; - - int agent = 44; - char *platform = "ubuntu"; - char *os_major = "18"; - char *os_minor = "04"; - char *arch = "x64_86"; - char *wazuh_version = "v3.13.1"; - char *status = AGENT_CS_ACTIVE; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - agent_task->agent_info->agent_id = agent; - os_strdup(platform, agent_task->agent_info->platform); - os_strdup(os_major, agent_task->agent_info->major_version); - os_strdup(os_minor, agent_task->agent_info->minor_version); - os_strdup(arch, agent_task->agent_info->architecture); - os_strdup(wazuh_version, agent_task->agent_info->wazuh_version); - os_strdup(status, agent_task->agent_info->connection_status); - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, platform); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, os_major); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, os_minor); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, arch); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, wazuh_version); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, platform); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, agent_task->task_info->command); - will_return(__wrap_wm_agent_upgrade_validate_version, ""); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_GLOBAL_DB_FAILURE); - - int ret = wm_agent_upgrade_validate_agent_task(agent_task); - - assert_int_equal(ret, WM_UPGRADE_GLOBAL_DB_FAILURE); -} - -void test_wm_agent_upgrade_validate_agent_task_system_err(void **state) -{ - (void) state; - - int agent = 44; - char *platform = "ubuntu"; - char *os_major = "18"; - char *os_minor = "04"; - char *arch = "x64_86"; - char *wazuh_version = "v3.13.1"; - char *status = AGENT_CS_ACTIVE; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - agent_task->agent_info->agent_id = agent; - os_strdup(platform, agent_task->agent_info->platform); - os_strdup(os_major, agent_task->agent_info->major_version); - os_strdup(os_minor, agent_task->agent_info->minor_version); - os_strdup(arch, agent_task->agent_info->architecture); - os_strdup(wazuh_version, agent_task->agent_info->wazuh_version); - os_strdup(status, agent_task->agent_info->connection_status); - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, platform); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, os_major); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, os_minor); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, arch); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_GLOBAL_DB_FAILURE); - - int ret = wm_agent_upgrade_validate_agent_task(agent_task); - - assert_int_equal(ret, WM_UPGRADE_GLOBAL_DB_FAILURE); -} - -void test_wm_agent_upgrade_validate_agent_task_status_err(void **state) -{ - (void) state; - - int agent = 44; - char *platform = "ubuntu"; - char *os_major = "18"; - char *os_minor = "04"; - char *arch = "x64_86"; - char *wazuh_version = "v3.13.1"; - char *status = AGENT_CS_DISCONNECTED; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - agent_task->agent_info->agent_id = agent; - os_strdup(platform, agent_task->agent_info->platform); - os_strdup(os_major, agent_task->agent_info->major_version); - os_strdup(os_minor, agent_task->agent_info->minor_version); - os_strdup(arch, agent_task->agent_info->architecture); - os_strdup(wazuh_version, agent_task->agent_info->wazuh_version); - os_strdup(status, agent_task->agent_info->connection_status); - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_AGENT_IS_NOT_ACTIVE); - - int ret = wm_agent_upgrade_validate_agent_task(agent_task); - - assert_int_equal(ret, WM_UPGRADE_AGENT_IS_NOT_ACTIVE); -} - -void test_wm_agent_upgrade_validate_agent_task_agent_id_err(void **state) -{ - (void) state; - - int agent = 44; - char *platform = "ubuntu"; - char *os_major = "18"; - char *os_minor = "04"; - char *arch = "x64_86"; - char *wazuh_version = "v3.13.1"; - char *status = AGENT_CS_NEVER_CONNECTED; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - agent_task->agent_info->agent_id = agent; - os_strdup(platform, agent_task->agent_info->platform); - os_strdup(os_major, agent_task->agent_info->major_version); - os_strdup(os_minor, agent_task->agent_info->minor_version); - os_strdup(arch, agent_task->agent_info->architecture); - os_strdup(wazuh_version, agent_task->agent_info->wazuh_version); - os_strdup(status, agent_task->agent_info->connection_status); - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_INVALID_ACTION_FOR_MANAGER); - - int ret = wm_agent_upgrade_validate_agent_task(agent_task); - - assert_int_equal(ret, WM_UPGRADE_INVALID_ACTION_FOR_MANAGER); -} - -void test_wm_agent_upgrade_analyze_agent_ok(void **state) -{ - (void) state; - - wm_upgrade_error_code error_code = WM_UPGRADE_SUCCESS; - int agent = 119; - char *platform = "ubuntu"; - char *major = "18"; - char *minor = "04"; - char *arch = "x86_64"; - char *version = "v3.13.1"; - const char *connection_status = AGENT_CS_ACTIVE; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "os_platform", platform); - cJSON_AddStringToObject(agent_info, "os_major", major); - cJSON_AddStringToObject(agent_info, "os_minor", minor); - cJSON_AddStringToObject(agent_info, "os_arch", arch); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddStringToObject(agent_info, "connection_status", connection_status); - cJSON_AddItemToArray(agent_info_array, agent_info); - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agent); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, connection_status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, platform); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, major); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, minor); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, arch); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, version); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, platform); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, agent_task->task_info->command); - will_return(__wrap_wm_agent_upgrade_validate_version, "v4.1.0"); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_create_task_entry - expect_value(__wrap_wm_agent_upgrade_create_task_entry, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_create_task_entry, OSHASH_SUCCESS); - - error_code = wm_agent_upgrade_analyze_agent(agent, agent_task); - - assert_int_equal(error_code, WM_UPGRADE_SUCCESS); - assert_non_null(agent_task->agent_info); - assert_string_equal(agent_task->agent_info->platform, platform); - assert_string_equal(agent_task->agent_info->major_version, major); - assert_string_equal(agent_task->agent_info->minor_version, minor); - assert_string_equal(agent_task->agent_info->architecture, arch); - assert_string_equal(agent_task->agent_info->wazuh_version, version); - assert_string_equal(agent_task->agent_info->connection_status, connection_status); -} - -void test_wm_agent_upgrade_analyze_agent_duplicated_err(void **state) -{ - (void) state; - - wm_upgrade_error_code error_code = WM_UPGRADE_SUCCESS; - int agent = 120; - char *platform = "ubuntu"; - char *major = "18"; - char *minor = "04"; - char *arch = "x86_64"; - char *version = "v3.13.1"; - const char *connection_status = AGENT_CS_ACTIVE; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "os_platform", platform); - cJSON_AddStringToObject(agent_info, "os_major", major); - cJSON_AddStringToObject(agent_info, "os_minor", minor); - cJSON_AddStringToObject(agent_info, "os_arch", arch); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddStringToObject(agent_info, "connection_status", connection_status); - cJSON_AddItemToArray(agent_info_array, agent_info); - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agent); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, connection_status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, platform); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, major); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, minor); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, arch); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, version); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, platform); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, agent_task->task_info->command); - will_return(__wrap_wm_agent_upgrade_validate_version, "v4.1.0"); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_create_task_entry - expect_value(__wrap_wm_agent_upgrade_create_task_entry, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_create_task_entry, OSHASH_DUPLICATE); - - error_code = wm_agent_upgrade_analyze_agent(agent, agent_task); - - assert_int_equal(error_code, WM_UPGRADE_UPGRADE_ALREADY_IN_PROGRESS); - assert_non_null(agent_task->agent_info); - assert_string_equal(agent_task->agent_info->platform, platform); - assert_string_equal(agent_task->agent_info->major_version, major); - assert_string_equal(agent_task->agent_info->minor_version, minor); - assert_string_equal(agent_task->agent_info->architecture, arch); - assert_string_equal(agent_task->agent_info->wazuh_version, version); - assert_string_equal(agent_task->agent_info->connection_status, connection_status); -} - -void test_wm_agent_upgrade_analyze_agent_unknown_err(void **state) -{ - (void) state; - - wm_upgrade_error_code error_code = WM_UPGRADE_SUCCESS; - int agent = 121; - char *platform = "ubuntu"; - char *major = "18"; - char *minor = "04"; - char *arch = "x86_64"; - char *version = "v3.13.1"; - const char *connection_status = AGENT_CS_ACTIVE; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "os_platform", platform); - cJSON_AddStringToObject(agent_info, "os_major", major); - cJSON_AddStringToObject(agent_info, "os_minor", minor); - cJSON_AddStringToObject(agent_info, "os_arch", arch); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddStringToObject(agent_info, "connection_status", connection_status); - cJSON_AddItemToArray(agent_info_array, agent_info); - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agent); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, connection_status); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, platform); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, major); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, minor); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, arch); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, version); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, platform); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, agent_task->task_info->command); - will_return(__wrap_wm_agent_upgrade_validate_version, "v4.1.0"); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_create_task_entry - expect_value(__wrap_wm_agent_upgrade_create_task_entry, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_create_task_entry, OS_INVALID); - - error_code = wm_agent_upgrade_analyze_agent(agent, agent_task); - - assert_int_equal(error_code, WM_UPGRADE_UNKNOWN_ERROR); - assert_non_null(agent_task->agent_info); - assert_string_equal(agent_task->agent_info->platform, platform); - assert_string_equal(agent_task->agent_info->major_version, major); - assert_string_equal(agent_task->agent_info->minor_version, minor); - assert_string_equal(agent_task->agent_info->architecture, arch); - assert_string_equal(agent_task->agent_info->wazuh_version, version); - assert_string_equal(agent_task->agent_info->connection_status, connection_status); -} - -void test_wm_agent_upgrade_analyze_agent_validate_err(void **state) -{ - (void) state; - - wm_upgrade_error_code error_code = WM_UPGRADE_SUCCESS; - int agent = 119; - char *platform = "ubuntu"; - char *major = "18"; - char *minor = "04"; - char *arch = "x86_64"; - char *version = "v3.13.1"; - const char *connection_status = AGENT_CS_NEVER_CONNECTED; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task = *state; - - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - cJSON *agent_info_array = cJSON_CreateArray(); - cJSON *agent_info = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info, "os_platform", platform); - cJSON_AddStringToObject(agent_info, "os_major", major); - cJSON_AddStringToObject(agent_info, "os_minor", minor); - cJSON_AddStringToObject(agent_info, "os_arch", arch); - cJSON_AddStringToObject(agent_info, "version", version); - cJSON_AddStringToObject(agent_info, "connection_status", connection_status); - cJSON_AddItemToArray(agent_info_array, agent_info); - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agent); - will_return(__wrap_wdb_get_agent_info, agent_info_array); - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agent); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_INVALID_ACTION_FOR_MANAGER); - - error_code = wm_agent_upgrade_analyze_agent(agent, agent_task); - - assert_int_equal(error_code, WM_UPGRADE_INVALID_ACTION_FOR_MANAGER); - assert_non_null(agent_task->agent_info); - assert_string_equal(agent_task->agent_info->platform, platform); - assert_string_equal(agent_task->agent_info->major_version, major); - assert_string_equal(agent_task->agent_info->minor_version, minor); - assert_string_equal(agent_task->agent_info->architecture, arch); - assert_string_equal(agent_task->agent_info->wazuh_version, version); - assert_string_equal(agent_task->agent_info->connection_status, connection_status); -} - -void test_wm_agent_upgrade_analyze_agent_global_db_err(void **state) -{ - (void) state; - - wm_upgrade_error_code error_code = WM_UPGRADE_SUCCESS; - int agent = 119; - wm_upgrade_task *upgrade_task = NULL; - - wm_agent_task *agent_task =*state; - - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - agent_task->task_info->task = upgrade_task; - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agent); - will_return(__wrap_wdb_get_agent_info, NULL); - - error_code = wm_agent_upgrade_analyze_agent(agent, agent_task); - - assert_int_equal(error_code, WM_UPGRADE_GLOBAL_DB_FAILURE); - assert_non_null(agent_task->agent_info); - assert_null(agent_task->agent_info->platform); - assert_null(agent_task->agent_info->major_version); - assert_null(agent_task->agent_info->minor_version); - assert_null(agent_task->agent_info->architecture); - assert_null(agent_task->agent_info->wazuh_version); -} - -void test_wm_agent_upgrade_create_upgrade_tasks_ok(void **state) -{ - cJSON *data_array = cJSON_CreateArray(); - int agent1 = 55; - - cJSON *agents_array1 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array1, cJSON_CreateNumber(agent1)); - - cJSON *agents_array2 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array2, cJSON_CreateNumber(agent1)); - - cJSON *status_request = cJSON_CreateObject(); - cJSON *status_origin = cJSON_CreateObject(); - cJSON *status_parameters = cJSON_CreateObject(); - cJSON *status_agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(status_origin, "module", "upgrade_module"); - cJSON_AddItemToObject(status_request, "origin", status_origin); - cJSON_AddStringToObject(status_request, "command", "upgrade_get_status"); - cJSON_AddItemToArray(status_agents, cJSON_CreateNumber(agent1)); - cJSON_AddItemToObject(status_parameters, "agents", status_agents); - cJSON_AddItemToObject(status_request, "parameters", status_parameters); - - cJSON *request_json = cJSON_CreateObject(); - cJSON *origin_json = cJSON_CreateObject(); - cJSON *parameters_json= cJSON_CreateObject(); - cJSON *agents_json = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin_json, "module", "upgrade_module"); - cJSON_AddItemToObject(request_json, "origin", origin_json); - cJSON_AddStringToObject(request_json, "command", "upgrade_custom"); - cJSON_AddItemToArray(agents_json, cJSON_CreateNumber(agent1)); - cJSON_AddItemToObject(parameters_json, "agents", agents_json); - cJSON_AddItemToObject(request_json, "parameters", parameters_json); - - cJSON *task_response = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response, "agent", agent1); - cJSON_AddNumberToObject(task_response, "task_id", 100); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array1); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_GET_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, status_request); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, status_request, sizeof(status_request)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, NULL); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array2); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_UPGRADE_CUSTOM); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request_json); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request_json, sizeof(request_json)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_prepare_upgrades - - will_return(__wrap_wm_agent_upgrade_prepare_upgrades, 1); - - int ret = wm_agent_upgrade_create_upgrade_tasks(data_array, WM_UPGRADE_UPGRADE_CUSTOM); - - *state = data_array; - - assert_int_equal(ret, 1); - assert_int_equal(cJSON_GetArraySize(data_array), 1); - assert_memory_equal(cJSON_GetArrayItem(data_array, 0), task_response, sizeof(task_response)); -} - -void test_wm_agent_upgrade_create_upgrade_tasks_upgrade_err(void **state) -{ - cJSON *data_array = cJSON_CreateArray(); - int agent1 = 55; - - cJSON *agents_array1 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array1, cJSON_CreateNumber(agent1)); - - cJSON *agents_array2 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array2, cJSON_CreateNumber(agent1)); - - cJSON *status_request = cJSON_CreateObject(); - cJSON *status_origin = cJSON_CreateObject(); - cJSON *status_parameters = cJSON_CreateObject(); - cJSON *status_agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(status_origin, "module", "upgrade_module"); - cJSON_AddItemToObject(status_request, "origin", status_origin); - cJSON_AddStringToObject(status_request, "command", "upgrade_get_status"); - cJSON_AddItemToArray(status_agents, cJSON_CreateNumber(agent1)); - cJSON_AddItemToObject(status_parameters, "agents", status_agents); - cJSON_AddItemToObject(status_request, "parameters", status_parameters); - - cJSON *request_json = cJSON_CreateObject(); - cJSON *origin_json = cJSON_CreateObject(); - cJSON *parameters_json= cJSON_CreateObject(); - cJSON *agents_json = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin_json, "module", "upgrade_module"); - cJSON_AddItemToObject(request_json, "origin", origin_json); - cJSON_AddStringToObject(request_json, "command", "upgrade_custom"); - cJSON_AddItemToArray(agents_json, cJSON_CreateNumber(agent1)); - cJSON_AddItemToObject(parameters_json, "agents", agents_json); - cJSON_AddItemToObject(request_json, "parameters", parameters_json); - - cJSON *task_response = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response, "agent", agent1); - cJSON_AddNumberToObject(task_response, "task_id", 100); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array1); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_GET_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, status_request); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, status_request, sizeof(status_request)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, NULL); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array2); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_UPGRADE_CUSTOM); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request_json); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request_json, sizeof(request_json)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response); - will_return(__wrap_wm_agent_upgrade_task_module_callback, OS_INVALID); - - int ret = wm_agent_upgrade_create_upgrade_tasks(data_array, WM_UPGRADE_UPGRADE_CUSTOM); - - *state = data_array; - - assert_int_equal(ret, 0); - assert_int_equal(cJSON_GetArraySize(data_array), 1); - assert_memory_equal(cJSON_GetArrayItem(data_array, 0), task_response, sizeof(task_response)); -} - -void test_wm_agent_upgrade_create_upgrade_tasks_upgrade_no_agents(void **state) -{ - cJSON *data_array = cJSON_CreateArray(); - int agent1 = 55; - - cJSON *agents_array1 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array1, cJSON_CreateNumber(agent1)); - - cJSON *status_request = cJSON_CreateObject(); - cJSON *status_origin = cJSON_CreateObject(); - cJSON *status_parameters = cJSON_CreateObject(); - cJSON *status_agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(status_origin, "module", "upgrade_module"); - cJSON_AddItemToObject(status_request, "origin", status_origin); - cJSON_AddStringToObject(status_request, "command", "upgrade_get_status"); - cJSON_AddItemToArray(status_agents, cJSON_CreateNumber(agent1)); - cJSON_AddItemToObject(status_parameters, "agents", status_agents); - cJSON_AddItemToObject(status_request, "parameters", status_parameters); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array1); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_GET_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, status_request); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, status_request, sizeof(status_request)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, NULL); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, NULL); - - int ret = wm_agent_upgrade_create_upgrade_tasks(data_array, WM_UPGRADE_UPGRADE_CUSTOM); - - *state = data_array; - - assert_int_equal(ret, 0); - assert_int_equal(cJSON_GetArraySize(data_array), 0); -} - -void test_wm_agent_upgrade_create_upgrade_tasks_get_status_err(void **state) -{ - cJSON *data_array = cJSON_CreateArray(); - int agent1 = 55; - - cJSON *agents_array1 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array1, cJSON_CreateNumber(agent1)); - - cJSON *status_request = cJSON_CreateObject(); - cJSON *status_origin = cJSON_CreateObject(); - cJSON *status_parameters = cJSON_CreateObject(); - cJSON *status_agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(status_origin, "module", "upgrade_module"); - cJSON_AddItemToObject(status_request, "origin", status_origin); - cJSON_AddStringToObject(status_request, "command", "upgrade_get_status"); - cJSON_AddItemToArray(status_agents, cJSON_CreateNumber(agent1)); - cJSON_AddItemToObject(status_parameters, "agents", status_agents); - cJSON_AddItemToObject(status_request, "parameters", status_parameters); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array1); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_GET_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, status_request); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, status_request, sizeof(status_request)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, NULL); - will_return(__wrap_wm_agent_upgrade_task_module_callback, OS_INVALID); - - int ret = wm_agent_upgrade_create_upgrade_tasks(data_array, WM_UPGRADE_UPGRADE_CUSTOM); - - *state = data_array; - - assert_int_equal(ret, 0); - assert_int_equal(cJSON_GetArraySize(data_array), 0); -} - -void test_wm_agent_upgrade_create_upgrade_tasks_get_status_no_agents(void **state) -{ - cJSON *data_array = cJSON_CreateArray(); - int agent1 = 55; - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, NULL); - - int ret = wm_agent_upgrade_create_upgrade_tasks(data_array, WM_UPGRADE_UPGRADE_CUSTOM); - - *state = data_array; - - assert_int_equal(ret, 0); - assert_int_equal(cJSON_GetArraySize(data_array), 0); -} - -void test_wm_agent_upgrade_process_upgrade_result_command_ok(void **state) -{ - (void) state; - - int agents[2]; - int task_id = 15; - int create_time = 123456; - int update_time = 123465; - char *node = "node05"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = "Done"; - char *error = "Error message"; - - agents[0] = 25; - agents[1] = OS_INVALID; - - cJSON *request_result = cJSON_CreateObject(); - cJSON *origin_result = cJSON_CreateObject(); - cJSON *parameters_result = cJSON_CreateObject(); - cJSON *agents_result = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin_result, "module", "upgrade_module"); - cJSON_AddItemToObject(request_result, "origin", origin_result); - cJSON_AddStringToObject(request_result, "command", "upgrade_result"); - cJSON_AddItemToArray(agents_result, cJSON_CreateNumber(agents[0])); - cJSON_AddItemToObject(parameters_result, "agents", agents_result); - cJSON_AddItemToObject(request_result, "parameters", parameters_result); - - cJSON *result_response = cJSON_CreateObject(); - - cJSON_AddNumberToObject(result_response, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(result_response, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(result_response, "agent", agents[0]); - cJSON_AddNumberToObject(result_response, "task_id", task_id); - cJSON_AddNumberToObject(result_response, "create_time", create_time); - cJSON_AddNumberToObject(result_response, "update_time", update_time); - cJSON_AddStringToObject(result_response, "node", node); - cJSON_AddStringToObject(result_response, "module", module); - cJSON_AddStringToObject(result_response, "command", command); - cJSON_AddStringToObject(result_response, "status", status); - cJSON_AddStringToObject(result_response, "error", error); - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_RESULT); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request_result); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request_result, sizeof(request_result)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, result_response); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_parse_response - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_SUCCESS); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - char *result = wm_agent_upgrade_process_upgrade_result_command(agents); - - *state = (void *)result; - - assert_non_null(result); - assert_string_equal(result, "{\"error\":0,\"message\":\"Success\",\"data\":[{\"error\":0,\"message\":\"Success\",\"agent\":25,\"task_id\":15,\"create_time\":123456,\"update_time\":123465,\"node\":\"node05\",\"module\":\"upgrade_module\",\"command\":\"upgrade\",\"status\":\"Done\",\"error\":\"Error message\"}]}"); -} - -void test_wm_agent_upgrade_process_agent_result_command_done(void **state) -{ - (void) state; - - int agents[2]; - wm_upgrade_agent_status_task *upgrade_agent_status_task = NULL; - char *agent_status = "Done"; - - agents[0] = 25; - agents[1] = OS_INVALID; - - upgrade_agent_status_task = wm_agent_upgrade_init_agent_status_task(); - upgrade_agent_status_task->error_code = 0; - os_strdup("Success", upgrade_agent_status_task->message); - os_strdup(agent_status, upgrade_agent_status_task->status); - - state[0] = (void *)upgrade_agent_status_task; - - cJSON *request_status = cJSON_CreateObject(); - cJSON *origin_status = cJSON_CreateObject(); - cJSON *parameters_status = cJSON_CreateObject(); - cJSON *agents_status = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin_status, "module", "upgrade_module"); - cJSON_AddItemToObject(request_status, "origin", origin_status); - cJSON_AddStringToObject(request_status, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents_status, cJSON_CreateNumber(agents[0])); - cJSON_AddItemToObject(parameters_status, "agents", agents_status); - cJSON_AddItemToObject(request_status, "parameters", parameters_status); - - cJSON *status_response = cJSON_CreateObject(); - - cJSON_AddNumberToObject(status_response, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(status_response, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(status_response, "agent", agents[0]); - cJSON_AddStringToObject(status_response, "status", agent_status); - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtinfo, formatted_msg, "(8164): Received upgrade notification from agent '25'. Error code: '0', message: 'Success'"); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request_status); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, agent_status); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request_status, sizeof(request_status)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, status_response); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_parse_response - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_SUCCESS); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - char *result = wm_agent_upgrade_process_agent_result_command(agents, upgrade_agent_status_task); - - state[1] = (void *)result; - - assert_non_null(result); - assert_string_equal(result, "{\"error\":0,\"message\":\"Success\",\"data\":[{\"error\":0,\"message\":\"Success\",\"agent\":25,\"status\":\"Done\"}]}"); -} - -void test_wm_agent_upgrade_process_agent_result_command_failed(void **state) -{ - (void) state; - - int agents[2]; - wm_upgrade_agent_status_task *upgrade_agent_status_task = NULL; - char *agent_status = "Failed"; - char *agent_error = "Upgrade procedure exited with error code"; - - agents[0] = 25; - agents[1] = OS_INVALID; - - upgrade_agent_status_task = wm_agent_upgrade_init_agent_status_task(); - upgrade_agent_status_task->error_code = 2; - os_strdup("Error message", upgrade_agent_status_task->message); - os_strdup(agent_status, upgrade_agent_status_task->status); - - state[0] = (void *)upgrade_agent_status_task; - - cJSON *request_status = cJSON_CreateObject(); - cJSON *origin_status = cJSON_CreateObject(); - cJSON *parameters_status = cJSON_CreateObject(); - cJSON *agents_status = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin_status, "module", "upgrade_module"); - cJSON_AddItemToObject(request_status, "origin", origin_status); - cJSON_AddStringToObject(request_status, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents_status, cJSON_CreateNumber(agents[0])); - cJSON_AddItemToObject(parameters_status, "agents", agents_status); - cJSON_AddItemToObject(request_status, "parameters", parameters_status); - - cJSON *status_response = cJSON_CreateObject(); - - cJSON_AddNumberToObject(status_response, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(status_response, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(status_response, "agent", agents[0]); - cJSON_AddStringToObject(status_response, "status", agent_status); - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtinfo, formatted_msg, "(8164): Received upgrade notification from agent '25'. Error code: '2', message: 'Error message'"); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request_status); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, agent_status); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, error, agent_error); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request_status, sizeof(request_status)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, status_response); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_parse_response - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_SUCCESS); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - char *result = wm_agent_upgrade_process_agent_result_command(agents, upgrade_agent_status_task); - - state[1] = (void *)result; - - assert_non_null(result); - assert_string_equal(result, "{\"error\":0,\"message\":\"Success\",\"data\":[{\"error\":0,\"message\":\"Success\",\"agent\":25,\"status\":\"Failed\"}]}"); -} - -void test_wm_agent_upgrade_process_upgrade_custom_command(void **state) -{ - (void) state; - - int agents[3]; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - - char *custom_file_path = "/tmp/test.wpk"; - char *custom_installer = "test.sh"; - - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - upgrade_custom_task = wm_agent_upgrade_init_upgrade_custom_task(); - os_strdup(custom_file_path, upgrade_custom_task->custom_file_path); - os_strdup(custom_installer, upgrade_custom_task->custom_installer); - - state[0] = (void *)upgrade_custom_task; - - cJSON *agent_info_array1 = cJSON_CreateArray(); - cJSON *agent_info1 = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info1, "os_platform", "ubuntu"); - cJSON_AddStringToObject(agent_info1, "os_major", "18"); - cJSON_AddStringToObject(agent_info1, "os_minor", "04"); - cJSON_AddStringToObject(agent_info1, "os_arch", "x86_64"); - cJSON_AddStringToObject(agent_info1, "version", "v3.13.1"); - cJSON_AddStringToObject(agent_info1, "connection_status", AGENT_CS_ACTIVE); - cJSON_AddItemToArray(agent_info_array1, agent_info1); - - cJSON *agents_array1 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array1, cJSON_CreateNumber(agents[0])); - - cJSON *agents_array2 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array2, cJSON_CreateNumber(agents[0])); - - cJSON *status_request = cJSON_CreateObject(); - cJSON *status_origin = cJSON_CreateObject(); - cJSON *status_parameters = cJSON_CreateObject(); - cJSON *status_agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(status_origin, "module", "upgrade_module"); - cJSON_AddItemToObject(status_request, "origin", status_origin); - cJSON_AddStringToObject(status_request, "command", "upgrade_get_status"); - cJSON_AddItemToArray(status_agents, cJSON_CreateNumber(agents[0])); - cJSON_AddItemToObject(status_parameters, "agents", status_agents); - cJSON_AddItemToObject(status_request, "parameters", status_parameters); - - cJSON *task_response1 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response1, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response1, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response1, "agent", agents[0]); - cJSON_AddNumberToObject(task_response1, "task_id", 100); - - cJSON *task_response2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task_response2, "error", WM_UPGRADE_GLOBAL_DB_FAILURE); - cJSON_AddStringToObject(task_response2, "message", upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - cJSON_AddNumberToObject(task_response2, "agent", agents[1]); - - cJSON *request_json = cJSON_CreateObject(); - cJSON *origin_json = cJSON_CreateObject(); - cJSON *parameters_json= cJSON_CreateObject(); - cJSON *agents_json = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin_json, "module", "upgrade_module"); - cJSON_AddItemToObject(request_json, "origin", origin_json); - cJSON_AddStringToObject(request_json, "command", "upgrade_custom"); - cJSON_AddItemToArray(agents_json, cJSON_CreateNumber(agents[0])); - cJSON_AddItemToObject(parameters_json, "agents", agents_json); - cJSON_AddItemToObject(request_json, "parameters", parameters_json); - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - // Analize agent[0] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[0]); - will_return(__wrap_wdb_get_agent_info, agent_info_array1); - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agents[0]); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, AGENT_CS_ACTIVE); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, "ubuntu"); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, "18"); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, "04"); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, "x86_64"); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, "v3.13.1"); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, "ubuntu"); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, WM_UPGRADE_UPGRADE_CUSTOM); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_create_task_entry - expect_value(__wrap_wm_agent_upgrade_create_task_entry, agent_id, agents[0]); - will_return(__wrap_wm_agent_upgrade_create_task_entry, OSHASH_SUCCESS); - - // Analize agent[1] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[1]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_GLOBAL_DB_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agents[1]); - will_return(__wrap_wm_agent_upgrade_parse_data_response, task_response2); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array1); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_GET_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, status_request); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, status_request, sizeof(status_request)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, NULL); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array2); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_UPGRADE_CUSTOM); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request_json); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request_json, sizeof(request_json)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response1); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_prepare_upgrades - - will_return(__wrap_wm_agent_upgrade_prepare_upgrades, 1); - - // wm_agent_upgrade_parse_response - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_SUCCESS); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - char *result = wm_agent_upgrade_process_upgrade_custom_command(agents, upgrade_custom_task); - - state[1] = (void *)result; - - assert_non_null(result); - assert_string_equal(result, "{\"error\":0,\"message\":\"Success\",\"data\":[{\"error\":6,\"message\":\"Agent information not found in database\",\"agent\":2},{\"message\":\"Success\",\"agent\":1,\"task_id\":100}]}"); -} - -void test_wm_agent_upgrade_process_upgrade_custom_command_no_agents(void **state) -{ - (void) state; - - int agents[3]; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - - char *custom_file_path = "/tmp/test.wpk"; - char *custom_installer = "test.sh"; - - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - upgrade_custom_task = wm_agent_upgrade_init_upgrade_custom_task(); - os_strdup(custom_file_path, upgrade_custom_task->custom_file_path); - os_strdup(custom_installer, upgrade_custom_task->custom_installer); - - state[0] = (void *)upgrade_custom_task; - - cJSON *task_response1 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task_response1, "error", WM_UPGRADE_GLOBAL_DB_FAILURE); - cJSON_AddStringToObject(task_response1, "message", upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - cJSON_AddNumberToObject(task_response1, "agent", agents[0]); - - cJSON *task_response2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task_response2, "error", WM_UPGRADE_GLOBAL_DB_FAILURE); - cJSON_AddStringToObject(task_response2, "message", upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - cJSON_AddNumberToObject(task_response2, "agent", agents[1]); - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - // Analize agent[0] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[0]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_GLOBAL_DB_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agents[0]); - will_return(__wrap_wm_agent_upgrade_parse_data_response, task_response1); - - // Analize agent[1] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[1]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_GLOBAL_DB_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agents[1]); - will_return(__wrap_wm_agent_upgrade_parse_data_response, task_response2); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, NULL); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtwarn, formatted_msg, "(8160): There are no valid agents to upgrade."); - - // wm_agent_upgrade_parse_response - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_SUCCESS); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - char *result = wm_agent_upgrade_process_upgrade_custom_command(agents, upgrade_custom_task); - - state[1] = (void *)result; - - assert_non_null(result); - assert_string_equal(result, "{\"error\":0,\"message\":\"Success\",\"data\":[{\"error\":6,\"message\":\"Agent information not found in database\",\"agent\":1},{\"error\":6,\"message\":\"Agent information not found in database\",\"agent\":2}]}"); -} - -void test_wm_agent_upgrade_process_upgrade_command(void **state) -{ - (void) state; - - int agents[3]; - wm_upgrade_task *upgrade_task = NULL; - - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - - state[0] = (void *)upgrade_task; - - cJSON *agent_info_array1 = cJSON_CreateArray(); - cJSON *agent_info1 = cJSON_CreateObject(); - cJSON_AddStringToObject(agent_info1, "os_platform", "ubuntu"); - cJSON_AddStringToObject(agent_info1, "os_major", "18"); - cJSON_AddStringToObject(agent_info1, "os_minor", "04"); - cJSON_AddStringToObject(agent_info1, "os_arch", "x86_64"); - cJSON_AddStringToObject(agent_info1, "version", "v3.13.1"); - cJSON_AddStringToObject(agent_info1, "connection_status", AGENT_CS_ACTIVE); - cJSON_AddItemToArray(agent_info_array1, agent_info1); - - cJSON *agents_array1 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array1, cJSON_CreateNumber(agents[0])); - - cJSON *agents_array2 = cJSON_CreateArray(); - cJSON_AddItemToArray(agents_array2, cJSON_CreateNumber(agents[0])); - - cJSON *status_request = cJSON_CreateObject(); - cJSON *status_origin = cJSON_CreateObject(); - cJSON *status_parameters = cJSON_CreateObject(); - cJSON *status_agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(status_origin, "module", "upgrade_module"); - cJSON_AddItemToObject(status_request, "origin", status_origin); - cJSON_AddStringToObject(status_request, "command", "upgrade_get_status"); - cJSON_AddItemToArray(status_agents, cJSON_CreateNumber(agents[0])); - cJSON_AddItemToObject(status_parameters, "agents", status_agents); - cJSON_AddItemToObject(status_request, "parameters", status_parameters); - - cJSON *task_response1 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response1, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response1, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response1, "agent", agents[0]); - cJSON_AddNumberToObject(task_response1, "task_id", 110); - - cJSON *task_response2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task_response2, "error", WM_UPGRADE_GLOBAL_DB_FAILURE); - cJSON_AddStringToObject(task_response2, "message", upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - cJSON_AddNumberToObject(task_response2, "agent", agents[1]); - - cJSON *request_json = cJSON_CreateObject(); - cJSON *origin_json = cJSON_CreateObject(); - cJSON *parameters_json= cJSON_CreateObject(); - cJSON *agents_json = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin_json, "module", "upgrade_module"); - cJSON_AddItemToObject(request_json, "origin", origin_json); - cJSON_AddStringToObject(request_json, "command", "upgrade"); - cJSON_AddItemToArray(agents_json, cJSON_CreateNumber(agents[0])); - cJSON_AddItemToObject(parameters_json, "agents", agents_json); - cJSON_AddItemToObject(request_json, "parameters", parameters_json); - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - // Analize agent[0] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[0]); - will_return(__wrap_wdb_get_agent_info, agent_info_array1); - - // wm_agent_upgrade_validate_id - - expect_value(__wrap_wm_agent_upgrade_validate_id, agent_id, agents[0]); - will_return(__wrap_wm_agent_upgrade_validate_id, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_status - - expect_string(__wrap_wm_agent_upgrade_validate_status, connection_status, AGENT_CS_ACTIVE); - will_return(__wrap_wm_agent_upgrade_validate_status, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_system - - expect_string(__wrap_wm_agent_upgrade_validate_system, platform, "ubuntu"); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_major, "18"); - expect_string(__wrap_wm_agent_upgrade_validate_system, os_minor, "04"); - expect_string(__wrap_wm_agent_upgrade_validate_system, arch, "x86_64"); - will_return(__wrap_wm_agent_upgrade_validate_system, "deb"); - will_return(__wrap_wm_agent_upgrade_validate_system, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_version - - expect_string(__wrap_wm_agent_upgrade_validate_version, wazuh_version, "v3.13.1"); - expect_string(__wrap_wm_agent_upgrade_validate_version, platform, "ubuntu"); - expect_value(__wrap_wm_agent_upgrade_validate_version, command, WM_UPGRADE_UPGRADE); - will_return(__wrap_wm_agent_upgrade_validate_version, "v4.1.0"); - will_return(__wrap_wm_agent_upgrade_validate_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_create_task_entry - expect_value(__wrap_wm_agent_upgrade_create_task_entry, agent_id, agents[0]); - will_return(__wrap_wm_agent_upgrade_create_task_entry, OSHASH_SUCCESS); - - // Analize agent[1] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[1]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_GLOBAL_DB_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agents[1]); - will_return(__wrap_wm_agent_upgrade_parse_data_response, task_response2); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array1); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_GET_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, status_request); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, status_request, sizeof(status_request)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, NULL); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, agents_array2); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_UPGRADE); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, request_json); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, request_json, sizeof(request_json)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response1); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_prepare_upgrades - - will_return(__wrap_wm_agent_upgrade_prepare_upgrades, 1); - - // wm_agent_upgrade_parse_response - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_SUCCESS); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - char *result = wm_agent_upgrade_process_upgrade_command(agents, upgrade_task); - - state[1] = (void *)result; - - assert_non_null(result); - assert_string_equal(result, "{\"error\":0,\"message\":\"Success\",\"data\":[{\"error\":6,\"message\":\"Agent information not found in database\",\"agent\":2},{\"message\":\"Success\",\"agent\":1,\"task_id\":110}]}"); -} - -void test_wm_agent_upgrade_process_upgrade_command_no_agents(void **state) -{ - (void) state; - - int agents[3]; - wm_upgrade_task *upgrade_task = NULL; - - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - - state[0] = (void *)upgrade_task; - - cJSON *task_response1 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task_response1, "error", WM_UPGRADE_GLOBAL_DB_FAILURE); - cJSON_AddStringToObject(task_response1, "message", upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - cJSON_AddNumberToObject(task_response1, "agent", agents[0]); - - cJSON *task_response2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task_response2, "error", WM_UPGRADE_GLOBAL_DB_FAILURE); - cJSON_AddStringToObject(task_response2, "message", upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - cJSON_AddNumberToObject(task_response2, "agent", agents[1]); - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - - // Analize agent[0] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[0]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_GLOBAL_DB_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agents[0]); - will_return(__wrap_wm_agent_upgrade_parse_data_response, task_response1); - - // Analize agent[1] - - // wdb_agent_info - - expect_value(__wrap_wdb_get_agent_info, id, agents[1]); - will_return(__wrap_wdb_get_agent_info, NULL); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_GLOBAL_DB_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_GLOBAL_DB_FAILURE]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agents[1]); - will_return(__wrap_wm_agent_upgrade_parse_data_response, task_response2); - - // wm_agent_upgrade_get_agent_ids - - will_return(__wrap_wm_agent_upgrade_get_agent_ids, NULL); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtwarn, formatted_msg, "(8160): There are no valid agents to upgrade."); - - // wm_agent_upgrade_parse_response - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_SUCCESS); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - char *result = wm_agent_upgrade_process_upgrade_command(agents, upgrade_task); - - state[1] = (void *)result; - - assert_non_null(result); - assert_string_equal(result, "{\"error\":0,\"message\":\"Success\",\"data\":[{\"error\":6,\"message\":\"Agent information not found in database\",\"agent\":1},{\"error\":6,\"message\":\"Agent information not found in database\",\"agent\":2}]}"); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_cancel_pending_upgrades - cmocka_unit_test(test_wm_agent_upgrade_cancel_pending_upgrades), - // wm_agent_upgrade_validate_agent_task - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_agent_task_upgrade_ok, setup_agent_task, teardown_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_agent_task_upgrade_custom_ok, setup_agent_task, teardown_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_agent_task_version_err, setup_agent_task, teardown_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_agent_task_system_err, setup_agent_task, teardown_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_agent_task_status_err, setup_agent_task, teardown_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_agent_task_agent_id_err, setup_agent_task, teardown_agent_task), - // wm_agent_upgrade_analyze_agent - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_analyze_agent_ok, setup_analyze_agent_task, teardown_analyze_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_analyze_agent_duplicated_err, setup_analyze_agent_task, teardown_analyze_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_analyze_agent_unknown_err, setup_analyze_agent_task, teardown_analyze_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_analyze_agent_validate_err, setup_analyze_agent_task, teardown_analyze_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_analyze_agent_global_db_err, setup_analyze_agent_task, teardown_analyze_agent_task), - // wm_agent_upgrade_create_upgrade_tasks - cmocka_unit_test_teardown(test_wm_agent_upgrade_create_upgrade_tasks_ok, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_create_upgrade_tasks_upgrade_err, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_create_upgrade_tasks_upgrade_no_agents, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_create_upgrade_tasks_get_status_err, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_create_upgrade_tasks_get_status_no_agents, teardown_json), - // wm_agent_upgrade_process_upgrade_result_command - cmocka_unit_test_teardown(test_wm_agent_upgrade_process_upgrade_result_command_ok, teardown_string), - // wm_agent_upgrade_process_agent_result_command - cmocka_unit_test_teardown(test_wm_agent_upgrade_process_agent_result_command_done, teardown_agent_status_task_string), - cmocka_unit_test_teardown(test_wm_agent_upgrade_process_agent_result_command_failed, teardown_agent_status_task_string), - // wm_agent_upgrade_process_upgrade_custom_command - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_upgrade_custom_command, setup_process_hash_table, teardown_upgrade_custom_task_string), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_upgrade_custom_command_no_agents, setup_process_hash_table, teardown_upgrade_custom_task_string), - // wm_agent_upgrade_process_upgrade_command - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_upgrade_command, setup_process_hash_table, teardown_upgrade_task_string), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_process_upgrade_command_no_agents, setup_process_hash_table, teardown_upgrade_task_string), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_manager.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_manager.c deleted file mode 100644 index 0d7e5542e3f..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_manager.c +++ /dev/null @@ -1,945 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/posix/pthread_wrappers.h" -#include "../../wrappers/posix/select_wrappers.h" -#include "../../wrappers/posix/unistd_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_manager.h" -#include "../../headers/shared.h" - -void wm_agent_upgrade_listen_messages(const wm_manager_configs* manager_configs); - -// Setup / teardown - -static int setup_group(void **state) { - wm_manager_configs *config = NULL; - os_calloc(1, sizeof(wm_manager_configs), config); - *state = config; - return 0; -} - -static int teardown_group(void **state) { - wm_manager_configs *config = *state; - os_free(config); - return 0; -} - -// Wrappers - -int __wrap_accept() { - return mock(); -} - -// Tests - -void test_wm_agent_upgrade_listen_messages_upgrade_command(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - - char *input = "{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1]," - " \"wpk_repo\": \"packages.wazuh.com/wpk\"" - " }" - "}"; - - size_t input_size = strlen(input) + 1; - wm_upgrade_task *upgrade_task = NULL; - int *agents = NULL; - char *response = NULL; - - os_calloc(1, sizeof(wm_upgrade_task), upgrade_task); - os_calloc(2, sizeof(int), agents); - os_calloc(OS_SIZE_256, sizeof(char), response); - - agents[0] = 1; - agents[1] = -1; - - sprintf(response, "{" - " \"error\":0," - " \"data\":[" - " {" - " \"error\":0," - " \"message\":\"Success\"," - " \"agent\":1," - " \"task_id\":1" - " }" - " ]," - " \"message\":\"Success\"" - "}"); - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8155): Incomming message: '{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1]," - " \"wpk_repo\": \"packages.wazuh.com/wpk\"" - " }" - "}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_message, buffer, input); - will_return(__wrap_wm_agent_upgrade_parse_message, (void*)upgrade_task); - will_return(__wrap_wm_agent_upgrade_parse_message, agents); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, WM_UPGRADE_UPGRADE); - - expect_value(__wrap_wm_agent_upgrade_process_upgrade_command, agent_ids, agents); - expect_value(__wrap_wm_agent_upgrade_process_upgrade_command, task, upgrade_task); - will_return(__wrap_wm_agent_upgrade_process_upgrade_command, response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8156): Response message: '{" - " \"error\":0," - " \"data\":[" - " {" - " \"error\":0," - " \"message\":\"Success\"," - " \"agent\":1," - " \"task_id\":1" - " }" - " ]," - " \"message\":\"Success\"" - "}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_upgrade_custom_command(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - - char *input = "{" - " \"command\": \"upgrade_custom\"," - " \"parameters\": {" - " \"agents\": [2]," - " \"file_path\":\"/test/wazuh.wpk\"" - " }" - "}"; - - size_t input_size = strlen(input) + 1; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - int *agents = NULL; - char *response = NULL; - - os_calloc(1, sizeof(wm_upgrade_custom_task), upgrade_custom_task); - os_calloc(2, sizeof(int), agents); - os_calloc(OS_SIZE_256, sizeof(char), response); - - agents[0] = 2; - agents[1] = -1; - - sprintf(response, "{" - " \"error\":0," - " \"data\":[" - " {" - " \"error\":0," - " \"message\":\"Success\"," - " \"agent\":2," - " \"task_id\":2" - " }" - " ]," - " \"message\":\"Success\"" - "}"); - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8155): Incomming message: '{" - " \"command\": \"upgrade_custom\"," - " \"parameters\": {" - " \"agents\": [2]," - " \"file_path\":\"/test/wazuh.wpk\"" - " }" - "}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_message, buffer, input); - will_return(__wrap_wm_agent_upgrade_parse_message, (void*)upgrade_custom_task); - will_return(__wrap_wm_agent_upgrade_parse_message, agents); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, WM_UPGRADE_UPGRADE_CUSTOM); - - expect_value(__wrap_wm_agent_upgrade_process_upgrade_custom_command, agent_ids, agents); - expect_value(__wrap_wm_agent_upgrade_process_upgrade_custom_command, task, upgrade_custom_task); - will_return(__wrap_wm_agent_upgrade_process_upgrade_custom_command, response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8156): Response message: '{" - " \"error\":0," - " \"data\":[" - " {" - " \"error\":0," - " \"message\":\"Success\"," - " \"agent\":2," - " \"task_id\":2" - " }" - " ]," - " \"message\":\"Success\"" - "}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_agent_update_status_command(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - - char *input = "{" - " \"command\": \"upgrade_update_status\"," - " \"parameters\": {" - " \"agents\": [2]," - " \"error\":0," - " \"message\":\"Upgrade was successful\"," - " \"status\":\"Done\"" - " }" - "}"; - - size_t input_size = strlen(input) + 1; - wm_upgrade_agent_status_task *upgrade_agent_status_task = NULL; - int *agents = NULL; - char *response = NULL; - - os_calloc(1, sizeof(wm_upgrade_agent_status_task), upgrade_agent_status_task); - os_calloc(2, sizeof(int), agents); - os_calloc(OS_SIZE_256, sizeof(char), response); - - agents[0] = 3; - agents[1] = -1; - - sprintf(response, "{" - " \"error\":0," - " \"data\":[" - " {" - " \"error\":0," - " \"message\":\"Success\"," - " \"agent\":3" - " }" - " ]," - " \"message\":\"Success\"" - "}"); - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8155): Incomming message: '{" - " \"command\": \"upgrade_update_status\"," - " \"parameters\": {" - " \"agents\": [2]," - " \"error\":0," - " \"message\":\"Upgrade was successful\"," - " \"status\":\"Done\"" - " }" - "}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_message, buffer, input); - will_return(__wrap_wm_agent_upgrade_parse_message, (void*)upgrade_agent_status_task); - will_return(__wrap_wm_agent_upgrade_parse_message, agents); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, WM_UPGRADE_AGENT_UPDATE_STATUS); - - expect_value(__wrap_wm_agent_upgrade_process_agent_result_command, agent_ids, agents); - expect_value(__wrap_wm_agent_upgrade_process_agent_result_command, task, upgrade_agent_status_task); - will_return(__wrap_wm_agent_upgrade_process_agent_result_command, response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8156): Response message: '{" - " \"error\":0," - " \"data\":[" - " {" - " \"error\":0," - " \"message\":\"Success\"," - " \"agent\":3" - " }" - " ]," - " \"message\":\"Success\"" - "}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_upgrade_result_command(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - - char *input = "{" - " \"command\": \"upgrade_result\"," - " \"parameters\": {" - " \"agents\": [2]" - " }" - "}"; - - size_t input_size = strlen(input) + 1; - void *task = NULL; - int *agents = NULL; - char *response = NULL; - - os_calloc(2, sizeof(int), agents); - os_calloc(OS_SIZE_512, sizeof(char), response); - - agents[0] = 3; - agents[1] = -1; - - sprintf(response, "{" - " \"error\":0," - " \"data\":[" - " {" - " \"task_id\":38," - " \"node\":\"node01\"," - " \"module\":\"api\"," - " \"command\":\"upgrade\"," - " \"create_time\":789456123," - " \"update_time\":987654321," - " \"status\":\"Updating\"," - " \"error_msg\":\"Error string\"" - " }" - " ]," - " \"message\":\"Success\"" - "}"); - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8155): Incomming message: '{" - " \"command\": \"upgrade_result\"," - " \"parameters\": {" - " \"agents\": [2]" - " }" - "}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_message, buffer, input); - will_return(__wrap_wm_agent_upgrade_parse_message, task); - will_return(__wrap_wm_agent_upgrade_parse_message, agents); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, WM_UPGRADE_RESULT); - - expect_value(__wrap_wm_agent_upgrade_process_upgrade_result_command, agent_ids, agents); - will_return(__wrap_wm_agent_upgrade_process_upgrade_result_command, response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8156): Response message: '{" - " \"error\":0," - " \"data\":[" - " {" - " \"task_id\":38," - " \"node\":\"node01\"," - " \"module\":\"api\"," - " \"command\":\"upgrade\"," - " \"create_time\":789456123," - " \"update_time\":987654321," - " \"status\":\"Updating\"," - " \"error_msg\":\"Error string\"" - " }" - " ]," - " \"message\":\"Success\"" - "}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_parse_error(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - size_t input_size = strlen(input) + 1; - - cJSON *response_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response_json, "error", WM_UPGRADE_UNKNOWN_ERROR); - cJSON_AddStringToObject(response_json, "message", upgrade_error_codes[WM_UPGRADE_UNKNOWN_ERROR]); - - char *response = "{\"error\":26,\"message\":\"Upgrade procedure could not start\",\"data\":[{\"error\":26,\"message\":\"Upgrade procedure could not start\"}]}"; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8155): Incomming message: 'Bad JSON'"); - - expect_string(__wrap_wm_agent_upgrade_parse_message, buffer, input); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, OS_INVALID); - - expect_value(__wrap_wm_agent_upgrade_parse_response, error_id, WM_UPGRADE_UNKNOWN_ERROR); - will_return(__wrap_wm_agent_upgrade_parse_response, response_json); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8156): Response message: '{\"error\":26,\"message\":\"Upgrade procedure could not start\",\"data\":[{\"error\":26,\"message\":\"Upgrade procedure could not start\"}]}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_parse_error_with_message(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - size_t input_size = strlen(input) + 1; - char *response = NULL; - - os_calloc(OS_SIZE_128, sizeof(char), response); - - sprintf(response, "{\"error\":1,\"data\":[{\"error\":1,\"message\":\"Could not parse message JSON\"}],\"message\":\"Could not parse message JSON\"}"); - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, input_size); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8155): Incomming message: 'Bad JSON'"); - - expect_string(__wrap_wm_agent_upgrade_parse_message, buffer, input); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, NULL); - will_return(__wrap_wm_agent_upgrade_parse_message, response); - will_return(__wrap_wm_agent_upgrade_parse_message, OS_INVALID); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8156): Response message: '{\"error\":1,\"data\":[{\"error\":1,\"message\":\"Could not parse message JSON\"}],\"message\":\"Could not parse message JSON\"}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_receive_empty(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8159): Empty message from local client."); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_receive_error(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8111): Error in recv(): 'Success'"); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_receive_sock_error(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_accept_error_eintr(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - errno = EINTR; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, -1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_accept_error(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - errno = 1; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8110): Error in accept(): 'Operation not permitted'"); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_select_zero(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, 0); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_select_error_eintr(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - int peer = 1111; - char *input = "Bad JSON"; - errno = EINTR; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, -1); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, input); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_select_error(void **state) -{ - wm_manager_configs *config = *state; - int socket = 0; - errno = 1; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, socket); - - expect_value(__wrap_sleep, seconds, WM_AGENT_UPGRADE_START_WAIT_TIME); - - will_return(__wrap_wm_agent_upgrade_cancel_pending_upgrades, 1); - - will_return(__wrap_select, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8109): Error in select(): 'Operation not permitted'. Exiting..."); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_listen_messages_bind_error(void **state) -{ - wm_manager_configs *config = *state; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8108): Unable to bind to socket 'queue/tasks/upgrade': 'Operation not permitted'"); - - wm_agent_upgrade_listen_messages(config); -} - -void test_wm_agent_upgrade_start_manager_module_enabled(void **state) -{ - wm_manager_configs *config = *state; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtinfo, formatted_msg, "(8153): Module Agent Upgrade started."); - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8108): Unable to bind to socket 'queue/tasks/upgrade': 'Operation not permitted'"); - - wm_agent_upgrade_start_manager_module(config, 1); -} - -void test_wm_agent_upgrade_start_manager_module_disabled(void **state) -{ - wm_manager_configs *config = *state; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtinfo, formatted_msg, "(8152): Module Agent Upgrade disabled. Exiting..."); - - will_return(__wrap_pthread_exit, OS_INVALID); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtinfo, formatted_msg, "(8153): Module Agent Upgrade started."); - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, WM_UPGRADE_SOCK); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - will_return(__wrap_OS_BindUnixDomainWithPerms, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8108): Unable to bind to socket 'queue/tasks/upgrade': 'Operation not permitted'"); - - wm_agent_upgrade_start_manager_module(config, 0); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_listen_messages - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_upgrade_command), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_upgrade_custom_command), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_agent_update_status_command), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_upgrade_result_command), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_parse_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_parse_error_with_message), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_receive_empty), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_receive_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_receive_sock_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_accept_error_eintr), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_accept_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_select_zero), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_select_error_eintr), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_select_error), - cmocka_unit_test(test_wm_agent_upgrade_listen_messages_bind_error), - // wm_agent_upgrade_start_manager_module - cmocka_unit_test(test_wm_agent_upgrade_start_manager_module_enabled), - cmocka_unit_test(test_wm_agent_upgrade_start_manager_module_disabled) - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_parsing.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_parsing.c deleted file mode 100644 index 4ba2b8b0a73..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_parsing.c +++ /dev/null @@ -1,1574 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_parsing.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_tasks.h" -#include "../../headers/shared.h" - -int* wm_agent_upgrade_parse_agents(const cJSON* agents, char** error_message); -wm_upgrade_task* wm_agent_upgrade_parse_upgrade_command(const cJSON* params, char** error_message); -wm_upgrade_custom_task* wm_agent_upgrade_parse_upgrade_custom_command(const cJSON* params, char** error_message); -wm_upgrade_agent_status_task* wm_agent_upgrade_parse_upgrade_agent_status(const cJSON* params, char** error_message); - -// Wrappers - -int __wrap_OS_ReadXML(const char *file, OS_XML *_lxml) { - return mock(); -} - -char* __wrap_OS_GetOneContentforElement(OS_XML *_lxml, const char **element_name) { - return mock_type(char *); -} - -void __wrap_OS_ClearXML(OS_XML *_lxml) { - return; -} - -// Setup / teardown - -static int teardown_json(void **state) { - if (*state) { - cJSON *json = *state; - cJSON_Delete(json); - } - return 0; -} - -static int teardown_string(void **state) { - char *string = *state; - os_free(string); - return 0; -} - -static int teardown_parse_agents(void **state) { - if (state[0]) { - char *error = (char*)state[0]; - os_free(error); - } - if (state[1]) { - int *ids = (int*)state[1]; - os_free(ids); - } - return 0; -} - -static int teardown_parse_upgrade(void **state) { - if (state[0]) { - char *error = (char*)state[0]; - os_free(error); - } - if (state[1]) { - wm_upgrade_task *task = (wm_upgrade_task*)state[1]; - wm_agent_upgrade_free_upgrade_task(task); - } - return 0; -} - -static int teardown_parse_upgrade_custom(void **state) { - if (state[0]) { - char *error = (char*)state[0]; - os_free(error); - } - if (state[1]) { - wm_upgrade_custom_task *task = (wm_upgrade_custom_task*)state[1]; - wm_agent_upgrade_free_upgrade_custom_task(task); - } - return 0; -} - -static int teardown_parse_upgrade_agent_status(void **state) { - if (state[0]) { - char *error = (char*)state[0]; - os_free(error); - } - if (state[1]) { - wm_upgrade_agent_status_task *task = (wm_upgrade_agent_status_task*)state[1]; - wm_agent_upgrade_free_agent_status_task(task); - } - return 0; -} - -// Tests - -void test_wm_agent_upgrade_parse_data_response_complete(void **state) -{ - int error_code = 5; - char *message = "Error code invalid data."; - int agent_id = 10; - - cJSON *response = wm_agent_upgrade_parse_data_response(error_code, message, &agent_id); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, message); - assert_non_null(cJSON_GetObjectItem(response, "agent")); - assert_int_equal(cJSON_GetObjectItem(response, "agent")->valueint, agent_id); -} - -void test_wm_agent_upgrade_parse_data_response_without_agent_id(void **state) -{ - int error_code = 5; - char *message = "Error code invalid data."; - - cJSON *response = wm_agent_upgrade_parse_data_response(error_code, message, NULL); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, message); - assert_null(cJSON_GetObjectItem(response, "agent")); -} - -void test_wm_agent_upgrade_parse_response_data_array(void **state) { - int error_code = 0; - cJSON *data = cJSON_CreateArray(); - - cJSON *response = wm_agent_upgrade_parse_response(error_code, data); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(response, "data")); - assert_memory_equal(cJSON_GetObjectItem(response, "data"), data, sizeof(data)); -} - -void test_wm_agent_upgrade_parse_response_data_object(void **state) { - int error_code = 0; - cJSON *data = cJSON_CreateObject(); - - cJSON *response = wm_agent_upgrade_parse_response(error_code, data); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(response, "data")); - assert_memory_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(response, "data"), 0), data, sizeof(data)); -} - -void test_wm_agent_upgrade_parse_task_module_request_complete(void **state) -{ - int command = 1; - char *node = NULL; - char *status = "Failed"; - char *error = "Error string"; - - os_strdup("node00", node); - - cJSON *agent_array = cJSON_CreateArray(); - cJSON_AddItemToArray(agent_array, cJSON_CreateNumber(10)); - cJSON_AddItemToArray(agent_array, cJSON_CreateNumber(11)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - cJSON *response = wm_agent_upgrade_parse_task_module_request(command, agent_array, status, error); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "origin")); - cJSON *origin = cJSON_GetObjectItem(response, "origin"); - assert_non_null(cJSON_GetObjectItem(origin, "name")); - assert_string_equal(cJSON_GetObjectItem(origin, "name")->valuestring, "node00"); - assert_non_null(cJSON_GetObjectItem(origin, "module")); - assert_string_equal(cJSON_GetObjectItem(origin, "module")->valuestring, "upgrade_module"); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, "upgrade_custom"); - assert_non_null(cJSON_GetObjectItem(response, "parameters")); - cJSON *parameters = cJSON_GetObjectItem(response, "parameters"); - assert_non_null(cJSON_GetObjectItem(parameters, "agents")); - assert_int_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 0)->valueint, 10); - assert_int_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 1)->valueint, 11); - assert_null(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 2)); - assert_non_null(cJSON_GetObjectItem(parameters, "status")); - assert_string_equal(cJSON_GetObjectItem(parameters, "status")->valuestring, status); - assert_non_null(cJSON_GetObjectItem(parameters, "error_msg")); - assert_string_equal(cJSON_GetObjectItem(parameters, "error_msg")->valuestring, error); -} - -void test_wm_agent_upgrade_parse_task_module_request_without_status_and_error(void **state) -{ - int command = 1; - char *node = NULL; - - os_strdup("node00", node); - - cJSON *agent_array = cJSON_CreateArray(); - cJSON_AddItemToArray(agent_array, cJSON_CreateNumber(10)); - cJSON_AddItemToArray(agent_array, cJSON_CreateNumber(11)); - - will_return(__wrap_OS_ReadXML, 1); - - will_return(__wrap_OS_GetOneContentforElement, node); - - cJSON *response = wm_agent_upgrade_parse_task_module_request(command, agent_array, NULL, NULL); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "origin")); - cJSON *origin = cJSON_GetObjectItem(response, "origin"); - assert_non_null(cJSON_GetObjectItem(origin, "name")); - assert_string_equal(cJSON_GetObjectItem(origin, "name")->valuestring, "node00"); - assert_non_null(cJSON_GetObjectItem(origin, "module")); - assert_string_equal(cJSON_GetObjectItem(origin, "module")->valuestring, "upgrade_module"); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, "upgrade_custom"); - assert_non_null(cJSON_GetObjectItem(response, "parameters")); - cJSON *parameters = cJSON_GetObjectItem(response, "parameters"); - assert_non_null(cJSON_GetObjectItem(parameters, "agents")); - assert_int_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 0)->valueint, 10); - assert_int_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 1)->valueint, 11); - assert_null(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 2)); - assert_null(cJSON_GetObjectItem(parameters, "status")); - assert_null(cJSON_GetObjectItem(parameters, "error_msg")); -} - -void test_wm_agent_upgrade_parse_task_module_request_xml_error(void **state) -{ - int command = 1; - - cJSON *agent_array = cJSON_CreateArray(); - cJSON_AddItemToArray(agent_array, cJSON_CreateNumber(10)); - cJSON_AddItemToArray(agent_array, cJSON_CreateNumber(11)); - - will_return(__wrap_OS_ReadXML, -1); - - cJSON *response = wm_agent_upgrade_parse_task_module_request(command, agent_array, NULL, NULL); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "origin")); - cJSON *origin = cJSON_GetObjectItem(response, "origin"); - assert_non_null(cJSON_GetObjectItem(origin, "name")); - assert_string_equal(cJSON_GetObjectItem(origin, "name")->valuestring, ""); - assert_non_null(cJSON_GetObjectItem(origin, "module")); - assert_string_equal(cJSON_GetObjectItem(origin, "module")->valuestring, "upgrade_module"); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, "upgrade_custom"); - assert_non_null(cJSON_GetObjectItem(response, "parameters")); - cJSON *parameters = cJSON_GetObjectItem(response, "parameters"); - assert_non_null(cJSON_GetObjectItem(parameters, "agents")); - assert_int_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 0)->valueint, 10); - assert_int_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 1)->valueint, 11); - assert_null(cJSON_GetArrayItem(cJSON_GetObjectItem(parameters, "agents"), 2)); - assert_null(cJSON_GetObjectItem(parameters, "status")); - assert_null(cJSON_GetObjectItem(parameters, "error_msg")); -} - -void test_wm_agent_upgrade_parse_agent_response_ok_with_data(void **state) -{ - (void) state; - char *response = "ok 1234567890"; - char *data = NULL; - - int ret = wm_agent_upgrade_parse_agent_response(response, &data); - - *state = data; - - assert_int_equal(ret, 0); - assert_string_equal(data, "1234567890"); -} - -void test_wm_agent_upgrade_parse_agent_response_ok_without_data(void **state) -{ - (void) state; - char *response = "ok "; - char *data = NULL; - - int ret = wm_agent_upgrade_parse_agent_response(response, &data); - - *state = data; - - assert_int_equal(ret, 0); - assert_string_equal(data, ""); -} - -void test_wm_agent_upgrade_parse_agent_response_ok_null_data(void **state) -{ - (void) state; - char *response = "ok 1234567890"; - - int ret = wm_agent_upgrade_parse_agent_response(response, NULL); - - assert_int_equal(ret, 0); -} - -void test_wm_agent_upgrade_parse_agent_response_err_with_data(void **state) -{ - (void) state; - char *response = "err invalid request"; - char *data = NULL; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8116): Error response from agent: 'invalid request'"); - - int ret = wm_agent_upgrade_parse_agent_response(response, &data); - - assert_int_equal(ret, -1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agent_response_err_without_data(void **state) -{ - (void) state; - char *response = "err "; - char *data = NULL; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8116): Error response from agent: ''"); - - int ret = wm_agent_upgrade_parse_agent_response(response, &data); - - assert_int_equal(ret, -1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agent_response_unknown_response(void **state) -{ - (void) state; - char *response = "unknown"; - char *data = NULL; - - int ret = wm_agent_upgrade_parse_agent_response(response, &data); - - assert_int_equal(ret, -1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agent_response_invalid_response(void **state) -{ - (void) state; - char *data = NULL; - - int ret = wm_agent_upgrade_parse_agent_response(NULL, &data); - - assert_int_equal(ret, -1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agent_upgrade_command_response_ok_with_data(void **state) -{ - (void) state; - char *response = "{" - " \"error\":0," - " \"message\":\"1234567890\"" - "}"; - char *data = NULL; - - int ret = wm_agent_upgrade_parse_agent_upgrade_command_response(response, &data); - - *state = data; - - assert_int_equal(ret, 0); - assert_string_equal(data, "1234567890"); -} - -void test_wm_agent_upgrade_parse_agent_upgrade_command_response_ok_without_data(void **state) -{ - (void) state; - char *response = "{" - " \"error\":0," - " \"message\":\"\"" - "}"; - char *data = NULL; - - int ret = wm_agent_upgrade_parse_agent_upgrade_command_response(response, &data); - - *state = data; - - assert_int_equal(ret, 0); - assert_string_equal(data, ""); -} - -void test_wm_agent_upgrade_parse_agent_upgrade_command_response_ok_null_data(void **state) -{ - (void) state; - char *response = "{" - " \"error\":0," - " \"message\":\"1234567890\"" - "}"; - - int ret = wm_agent_upgrade_parse_agent_upgrade_command_response(response, NULL); - - assert_int_equal(ret, 0); -} - -void test_wm_agent_upgrade_parse_agent_upgrade_command_response_err_with_data(void **state) -{ - (void) state; - char *response = "{" - " \"error\":1," - " \"message\":\"invalid request\"" - "}"; - char *data = NULL; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8116): Error response from agent: 'invalid request'"); - - int ret = wm_agent_upgrade_parse_agent_upgrade_command_response(response, &data); - - assert_int_equal(ret, 1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agent_upgrade_command_response_err_without_data(void **state) -{ - (void) state; - char *response = "{" - " \"error\":1," - " \"message\":\"\"" - "}"; - char *data = NULL; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8116): Error response from agent: ''"); - - int ret = wm_agent_upgrade_parse_agent_upgrade_command_response(response, &data); - - assert_int_equal(ret, 1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agent_upgrade_command_response_unknown_response(void **state) -{ - (void) state; - char *response = "{" - " \"unknown\":1" - "}"; - char *data = NULL; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8117): Unknown error from agent."); - - int ret = wm_agent_upgrade_parse_agent_upgrade_command_response(response, &data); - - assert_int_equal(ret, -1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agent_upgrade_command_response_invalid_response(void **state) -{ - (void) state; - char *data = NULL; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8117): Unknown error from agent."); - - int ret = wm_agent_upgrade_parse_agent_upgrade_command_response(NULL, &data); - - assert_int_equal(ret, -1); - assert_null(data); -} - -void test_wm_agent_upgrade_parse_agents_success(void **state) -{ - char *error = NULL; - - cJSON *agents = cJSON_CreateArray(); - cJSON *agent1 = cJSON_CreateNumber(15); - cJSON *agent2 = cJSON_CreateNumber(23); - cJSON *agent3 = cJSON_CreateNumber(8); - cJSON_AddItemToArray(agents, agent1); - cJSON_AddItemToArray(agents, agent2); - cJSON_AddItemToArray(agents, agent3); - - int* agent_ids = wm_agent_upgrade_parse_agents(agents, &error); - - cJSON_Delete(agents); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 15); - assert_int_equal(agent_ids[1], 23); - assert_int_equal(agent_ids[2], 8); - assert_int_equal(agent_ids[3], -1); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_agents_type_error(void **state) -{ - char *error = NULL; - - cJSON *agents = cJSON_CreateArray(); - cJSON *agent1 = cJSON_CreateNumber(15); - cJSON *agent2 = cJSON_CreateString("23"); - cJSON *agent3 = cJSON_CreateNumber(8); - cJSON_AddItemToArray(agents, agent1); - cJSON_AddItemToArray(agents, agent2); - cJSON_AddItemToArray(agents, agent3); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Agent id not recognized'"); - - int* agent_ids = wm_agent_upgrade_parse_agents(agents, &error); - - cJSON_Delete(agents); - - state[0] = (void*)error; - state[1] = NULL; - - assert_string_equal(error, "Agent id not recognized"); -} - -void test_wm_agent_upgrade_parse_agents_empty(void **state) -{ - char *error = NULL; - - cJSON *agents = cJSON_CreateArray(); - - int* agent_ids = wm_agent_upgrade_parse_agents(agents, &error); - - cJSON_Delete(agents); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], -1); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_upgrade_command_success(void **state) -{ - char *error = NULL; - char *repo = "wazuh.com"; - char *ver = "v4.0.0"; - char *package_type = "rpm"; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddStringToObject(params, "wpk_repo", repo); - cJSON_AddStringToObject(params, "version", ver); - cJSON_AddTrueToObject(params, "use_http"); - cJSON_AddTrueToObject(params, "force_upgrade"); - cJSON_AddStringToObject(params, "package_type", package_type); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = (void*)upgrade_task; - state[2] = NULL; - - assert_non_null(upgrade_task); - assert_string_equal(upgrade_task->wpk_repository, repo); - assert_string_equal(upgrade_task->custom_version, ver); - assert_int_equal(upgrade_task->use_http, true); - assert_int_equal(upgrade_task->force_upgrade, true); - assert_string_equal(upgrade_task->package_type, package_type); - assert_null(upgrade_task->wpk_file); - assert_null(upgrade_task->wpk_sha1); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_upgrade_command_default(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = (void*)upgrade_task; - state[2] = NULL; - - assert_non_null(upgrade_task); - assert_null(upgrade_task->wpk_repository); - assert_null(upgrade_task->custom_version); - assert_int_equal(upgrade_task->use_http, false); - assert_int_equal(upgrade_task->force_upgrade, false); - assert_null(upgrade_task->package_type); - assert_null(upgrade_task->wpk_file); - assert_null(upgrade_task->wpk_sha1); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_upgrade_command_invalid_repo_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddTrueToObject(params, "use_http"); - cJSON_AddFalseToObject(params, "force_upgrade"); - cJSON_AddNumberToObject(params, "wpk_repo", 555); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"wpk_repo\" should be a string'"); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"wpk_repo\" should be a string"); -} - -void test_wm_agent_upgrade_parse_upgrade_command_invalid_version_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddFalseToObject(params, "use_http"); - cJSON_AddTrueToObject(params, "force_upgrade"); - cJSON_AddNumberToObject(params, "version", 111); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"version\" should be a string'"); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"version\" should be a string"); -} - -void test_wm_agent_upgrade_parse_upgrade_command_invalid_http(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "use_http", 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"use_http\" should be true or false'"); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"use_http\" should be true or false"); -} - -void test_wm_agent_upgrade_parse_upgrade_command_invalid_force(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "force_upgrade", 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"force_upgrade\" should be true or false'"); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"force_upgrade\" should be true or false"); -} - -void test_wm_agent_upgrade_parse_upgrade_command_invalid_package_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "package_type", 123); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"package_type\" should be a string'"); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"package_type\" should be a string"); -} - -void test_wm_agent_upgrade_parse_upgrade_command_invalid_package_type_value(void **state) -{ - char *error = NULL; - char *package_type = "msi"; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddStringToObject(params, "package_type", package_type); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Invalid parameter \"package_type\", value should be \"rpm\" or \"deb\"'"); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Invalid parameter \"package_type\", value should be \"rpm\" or \"deb\""); -} - -void test_wm_agent_upgrade_parse_upgrade_command_invalid_json(void **state) -{ - char *error = NULL; - char *repo = "wazuh.com"; - char *ver = "v4.0.0"; - bool http = false; - bool force = false; - - cJSON *params = cJSON_CreateArray(); - cJSON *wpk_repo = cJSON_CreateObject(); - cJSON *version = cJSON_CreateObject(); - cJSON *use_http = cJSON_CreateObject(); - cJSON *force_upgrade = cJSON_CreateObject(); - cJSON_AddStringToObject(wpk_repo, "wpk_repo", repo); - cJSON_AddStringToObject(version, "version", ver); - cJSON_AddNumberToObject(use_http, "use_http", http); - cJSON_AddNumberToObject(force_upgrade, "force_upgrade", force); - cJSON_AddItemToArray(params, wpk_repo); - cJSON_AddItemToArray(params, version); - cJSON_AddItemToArray(params, use_http); - cJSON_AddItemToArray(params, force_upgrade); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Invalid JSON type'"); - - wm_upgrade_task* upgrade_task = wm_agent_upgrade_parse_upgrade_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Invalid JSON type"); -} - -void test_wm_agent_upgrade_parse_upgrade_custom_command_success(void **state) -{ - char *error = NULL; - char *file = "wazuh.wpk"; - char *exe = "install.sh"; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddStringToObject(params, "file_path", file); - cJSON_AddStringToObject(params, "installer", exe); - - wm_upgrade_custom_task* upgrade_custom_task = wm_agent_upgrade_parse_upgrade_custom_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = (void*)upgrade_custom_task; - state[2] = NULL; - - assert_non_null(upgrade_custom_task); - assert_string_equal(upgrade_custom_task->custom_file_path, file); - assert_string_equal(upgrade_custom_task->custom_installer, exe); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_upgrade_custom_command_default(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - - wm_upgrade_custom_task* upgrade_custom_task = wm_agent_upgrade_parse_upgrade_custom_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = (void*)upgrade_custom_task; - state[2] = NULL; - - assert_non_null(upgrade_custom_task); - assert_null(upgrade_custom_task->custom_file_path); - assert_null(upgrade_custom_task->custom_installer); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_upgrade_custom_command_invalid_file_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "file_path", 789); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"file_path\" should be a string'"); - - wm_upgrade_custom_task* upgrade_custom_task = wm_agent_upgrade_parse_upgrade_custom_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"file_path\" should be a string"); -} - -void test_wm_agent_upgrade_parse_upgrade_custom_command_invalid_installer_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "installer", 456); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"installer\" should be a string'"); - - wm_upgrade_custom_task* upgrade_custom_task = wm_agent_upgrade_parse_upgrade_custom_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"installer\" should be a string"); -} - -void test_wm_agent_upgrade_parse_upgrade_custom_command_invalid_json(void **state) -{ - char *error = NULL; - char *file = "wazuh.wpk"; - char *exe = "install.sh"; - - cJSON *params = cJSON_CreateArray(); - cJSON *file_path = cJSON_CreateObject(); - cJSON *installer = cJSON_CreateObject(); - cJSON_AddStringToObject(file_path, "file_path", file); - cJSON_AddStringToObject(installer, "installer", exe); - cJSON_AddItemToArray(params, file_path); - cJSON_AddItemToArray(params, installer); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Invalid JSON type'"); - - wm_upgrade_custom_task* upgrade_custom_task = wm_agent_upgrade_parse_upgrade_custom_command(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Invalid JSON type"); -} - -void test_wm_agent_upgrade_parse_upgrade_agent_status_success(void **state) -{ - char *error = NULL; - int error_code = 0; - char *data = "Success"; - char *status = "Done"; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "error", error_code); - cJSON_AddStringToObject(params, "message", data); - cJSON_AddStringToObject(params, "status", status); - - wm_upgrade_agent_status_task* agent_status_task = wm_agent_upgrade_parse_upgrade_agent_status(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = (void*)agent_status_task; - state[2] = NULL; - - assert_non_null(agent_status_task); - assert_int_equal(agent_status_task->error_code, error_code); - assert_string_equal(agent_status_task->message, data); - assert_string_equal(agent_status_task->status, status); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_upgrade_agent_status_default(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - - wm_upgrade_agent_status_task* agent_status_task = wm_agent_upgrade_parse_upgrade_agent_status(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = (void*)agent_status_task; - state[2] = NULL; - - assert_non_null(agent_status_task); - assert_int_equal(agent_status_task->error_code, 0); - assert_null(agent_status_task->message); - assert_null(agent_status_task->status); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_code_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddStringToObject(params, "error", "0"); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"error\" should be a number'"); - - wm_upgrade_agent_status_task* agent_status_task = wm_agent_upgrade_parse_upgrade_agent_status(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"error\" should be a number"); -} - -void test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_data_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "message", 123); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"message\" should be a string'"); - - wm_upgrade_agent_status_task* agent_status_task = wm_agent_upgrade_parse_upgrade_agent_status(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"message\" should be a string"); -} - -void test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_status_type(void **state) -{ - char *error = NULL; - - cJSON *params = cJSON_CreateObject(); - cJSON_AddNumberToObject(params, "status", 555); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"status\" should be a string'"); - - wm_upgrade_agent_status_task* agent_status_task = wm_agent_upgrade_parse_upgrade_agent_status(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Parameter \"status\" should be a string"); -} - -void test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_json(void **state) -{ - char *error = NULL; - int error_code = 0; - char *data = "Success"; - - cJSON *params = cJSON_CreateObject(); - cJSON *code = cJSON_CreateObject(); - cJSON *path = cJSON_CreateObject(); - cJSON_AddNumberToObject(code, "error", error_code); - cJSON_AddStringToObject(path, "message", data); - cJSON_AddItemToArray(params, code); - cJSON_AddItemToArray(params, path); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Invalid JSON type'"); - - wm_upgrade_agent_status_task* agent_status_task = wm_agent_upgrade_parse_upgrade_agent_status(params, &error); - - cJSON_Delete(params); - - state[0] = (void*)error; - state[1] = NULL; - - assert_non_null(error); - assert_string_equal(error, "Invalid JSON type"); -} - -void test_wm_agent_upgrade_parse_message_upgrade_success(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_task* upgrade_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1,15,24]," - " \"wpk_repo\":\"wazuh.com\"," - " \"version\":\"v4.0.0\"," - " \"use_http\":false," - " \"force_upgrade\":true" - " }" - "}"; - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, WM_UPGRADE_UPGRADE); - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 1); - assert_int_equal(agent_ids[1], 15); - assert_int_equal(agent_ids[2], 24); - assert_int_equal(agent_ids[3], -1); - assert_non_null(upgrade_task); - assert_string_equal(upgrade_task->wpk_repository, "wazuh.com"); - assert_string_equal(upgrade_task->custom_version, "v4.0.0"); - assert_int_equal(upgrade_task->use_http, 0); - assert_int_equal(upgrade_task->force_upgrade, 1); - assert_null(upgrade_task->wpk_file); - assert_null(upgrade_task->wpk_sha1); - assert_null(error); - - wm_agent_upgrade_free_upgrade_task(upgrade_task); -} - -void test_wm_agent_upgrade_parse_message_upgrade_agent_error(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_task* upgrade_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1,15,\"24\"]," - " \"wpk_repo\":\"wazuh.com\"," - " \"version\":\"v4.0.0\"," - " \"use_http\":false," - " \"force_upgrade\":true" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Agent id not recognized'"); - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(upgrade_task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"Agent id not recognized\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_upgrade_task_error(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_task* upgrade_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1,15,24]," - " \"wpk_repo\":\"wazuh.com\"," - " \"version\":\"v4.0.0\"," - " \"use_http\":\"yes\"," - " \"force_upgrade\":true" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"use_http\" should be true or false'"); - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 1); - assert_int_equal(agent_ids[1], 15); - assert_int_equal(agent_ids[2], 24); - assert_int_equal(agent_ids[3], -1); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"Parameter \\\"use_http\\\" should be true or false\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_upgrade_custom_success(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_custom_task* upgrade_custom_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_custom\"," - " \"parameters\": {" - " \"agents\":[1,15,24]," - " \"file_path\":\"wazuh.wpk\"," - " \"installer\":\"install.sh\"" - " }" - "}"; - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_custom_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, WM_UPGRADE_UPGRADE_CUSTOM); - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 1); - assert_int_equal(agent_ids[1], 15); - assert_int_equal(agent_ids[2], 24); - assert_int_equal(agent_ids[3], -1); - assert_non_null(upgrade_custom_task); - assert_string_equal(upgrade_custom_task->custom_file_path, "wazuh.wpk"); - assert_string_equal(upgrade_custom_task->custom_installer, "install.sh"); - assert_null(error); - - wm_agent_upgrade_free_upgrade_custom_task(upgrade_custom_task); -} - -void test_wm_agent_upgrade_parse_message_upgrade_custom_agent_error(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_custom_task* upgrade_custom_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_custom\"," - " \"parameters\": {" - " \"agents\":[1,\"15\",24]," - " \"file_path\":\"wazuh.wpk\"," - " \"installer\":\"install.sh\"" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Agent id not recognized'"); - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_custom_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(upgrade_custom_task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"Agent id not recognized\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_upgrade_custom_task_error(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_custom_task* upgrade_custom_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_custom\"," - " \"parameters\": {" - " \"agents\":[1,15,24]," - " \"file_path\":\"wazuh.wpk\"," - " \"installer\":123" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"installer\" should be a string'"); - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_custom_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 1); - assert_int_equal(agent_ids[1], 15); - assert_int_equal(agent_ids[2], 24); - assert_int_equal(agent_ids[3], -1); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"Parameter \\\"installer\\\" should be a string\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_upgrade_agent_status_success(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_agent_status_task* upgrade_agent_status_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_update_status\"," - " \"parameters\": {" - " \"agents\":[10]," - " \"error\":0," - " \"message\":\"Success\"," - " \"status\":\"Done\"" - " }" - "}"; - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_agent_status_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, WM_UPGRADE_AGENT_UPDATE_STATUS); - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 10); - assert_int_equal(agent_ids[1], -1); - assert_non_null(upgrade_agent_status_task); - assert_int_equal(upgrade_agent_status_task->error_code, 0); - assert_string_equal(upgrade_agent_status_task->message, "Success"); - assert_string_equal(upgrade_agent_status_task->status, "Done"); - assert_null(error); - - wm_agent_upgrade_free_agent_status_task(upgrade_agent_status_task); -} - -void test_wm_agent_upgrade_parse_message_upgrade_agent_status_agent_error(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_agent_status_task* upgrade_agent_status_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_update_status\"," - " \"parameters\": {" - " \"agents\":[\"10\"]," - " \"error\":0," - " \"message\":\"Success\"," - " \"status\":\"Done\"" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Agent id not recognized'"); - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_agent_status_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(upgrade_agent_status_task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"Agent id not recognized\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_upgrade_agent_status_task_error(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - wm_upgrade_agent_status_task* upgrade_agent_status_task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_update_status\"," - " \"parameters\": {" - " \"agents\":[10]," - " \"error\":0," - " \"message\":666," - " \"status\":\"Done\"" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Parameter \"message\" should be a string'"); - - int command = wm_agent_upgrade_parse_message(buffer, (void*)&upgrade_agent_status_task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 10); - assert_int_equal(agent_ids[1], -1); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"Parameter \\\"message\\\" should be a string\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_upgrade_result_success(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - void* task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_result\"," - " \"parameters\": {" - " \"agents\":[10,11]" - " }" - "}"; - - int command = wm_agent_upgrade_parse_message(buffer, &task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, WM_UPGRADE_RESULT); - assert_non_null(agent_ids); - assert_int_equal(agent_ids[0], 10); - assert_int_equal(agent_ids[1], 11); - assert_int_equal(agent_ids[2], -1); - assert_null(task); - assert_null(error); -} - -void test_wm_agent_upgrade_parse_message_upgrade_result_agent_error(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - void* task = NULL; - char *buffer = "{" - " \"command\": \"upgrade_result\"," - " \"parameters\": {" - " \"agents\":[\"10\"]," - " \"error\":0," - " \"message\":\"Success\"," - " \"status\":\"Done\"" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8103): Error parsing command: 'Agent id not recognized'"); - - int command = wm_agent_upgrade_parse_message(buffer, &task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"Agent id not recognized\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_invalid_command(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - void* task = NULL; - char *buffer = "{" - " \"command\": \"unknown\"," - " \"parameters\": {" - " \"agents\":[10]" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8102): No action defined for command: 'unknown'"); - - int command = wm_agent_upgrade_parse_message(buffer, &task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":3,\"data\":[{\"error\":3,\"message\":\"JSON parameter not recognized\"}],\"message\":\"JSON parameter not recognized\"}"); -} - -void test_wm_agent_upgrade_parse_message_invalid_agents(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - void* task = NULL; - char *buffer = "{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\":[]" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8107): Required parameters in message are missing."); - - int command = wm_agent_upgrade_parse_message(buffer, &task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":2,\"data\":[{\"error\":2,\"message\":\"Required parameters in json message where not found\"}],\"message\":\"Required parameters in json message where not found\"}"); -} - -void test_wm_agent_upgrade_parse_message_invalid_json(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - void* task = NULL; - char *buffer = "unknown"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8101): Cannot parse JSON: 'unknown'"); - - int command = wm_agent_upgrade_parse_message(buffer, &task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":1,\"data\":[{\"error\":1,\"message\":\"Could not parse message JSON\"}],\"message\":\"Could not parse message JSON\"}"); -} - -void test_wm_agent_upgrade_parse_message_missing_required(void **state) -{ - char *error = NULL; - int* agent_ids = NULL; - void* task = NULL; - char *buffer = "{}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8107): Required parameters in message are missing."); - - int command = wm_agent_upgrade_parse_message(buffer, &task, &agent_ids, &error); - - state[0] = (void*)error; - state[1] = (void*)agent_ids; - state[2] = NULL; - - assert_int_equal(command, OS_INVALID); - assert_null(agent_ids); - assert_null(task); - assert_non_null(error); - assert_string_equal(error, "{\"error\":2,\"data\":[{\"error\":2,\"message\":\"Required parameters in json message where not found\"}],\"message\":\"Required parameters in json message where not found\"}"); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_parse_data_response - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_data_response_complete, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_data_response_without_agent_id, teardown_json), - // wm_agent_upgrade_parse_response - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_response_data_array, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_response_data_object, teardown_json), - // wm_agent_upgrade_parse_task_module_request - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_task_module_request_complete, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_task_module_request_without_status_and_error, teardown_json), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_task_module_request_xml_error, teardown_json), - // wm_agent_upgrade_parse_agent_response - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_agent_response_ok_with_data, teardown_string), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_agent_response_ok_without_data, teardown_string), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_response_ok_null_data), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_response_err_with_data), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_response_err_without_data), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_response_unknown_response), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_response_invalid_response), - // wm_agent_upgrade_parse_agent_upgrade_command_response - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_agent_upgrade_command_response_ok_with_data, teardown_string), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_agent_upgrade_command_response_ok_without_data, teardown_string), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_upgrade_command_response_ok_null_data), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_upgrade_command_response_err_with_data), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_upgrade_command_response_err_without_data), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_upgrade_command_response_unknown_response), - cmocka_unit_test(test_wm_agent_upgrade_parse_agent_upgrade_command_response_invalid_response), - // wm_agent_upgrade_parse_agents - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_agents_success, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_agents_type_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_agents_empty, teardown_parse_agents), - // wm_agent_upgrade_parse_upgrade_command - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_success, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_default, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_invalid_repo_type, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_invalid_version_type, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_invalid_http, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_invalid_force, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_invalid_package_type, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_invalid_package_type_value, teardown_parse_upgrade), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_command_invalid_json, teardown_parse_upgrade), - // wm_agent_upgrade_parse_upgrade_custom_command - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_custom_command_success, teardown_parse_upgrade_custom), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_custom_command_default, teardown_parse_upgrade_custom), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_custom_command_invalid_file_type, teardown_parse_upgrade_custom), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_custom_command_invalid_installer_type, teardown_parse_upgrade_custom), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_custom_command_invalid_json, teardown_parse_upgrade_custom), - // wm_agent_upgrade_parse_upgrade_agent_status - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_agent_status_success, teardown_parse_upgrade_agent_status), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_agent_status_default, teardown_parse_upgrade_agent_status), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_code_type, teardown_parse_upgrade_agent_status), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_data_type, teardown_parse_upgrade_agent_status), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_status_type, teardown_parse_upgrade_agent_status), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_upgrade_agent_status_invalid_json, teardown_parse_upgrade_agent_status), - // wm_agent_upgrade_parse_message - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_success, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_agent_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_task_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_custom_success, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_custom_agent_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_custom_task_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_agent_status_success, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_agent_status_agent_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_agent_status_task_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_result_success, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_upgrade_result_agent_error, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_invalid_command, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_invalid_agents, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_invalid_json, teardown_parse_agents), - cmocka_unit_test_teardown(test_wm_agent_upgrade_parse_message_missing_required, teardown_parse_agents) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_tasks.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_tasks.c deleted file mode 100644 index 15eb718f586..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_tasks.c +++ /dev/null @@ -1,800 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../wrappers/posix/unistd_wrappers.h" -#include "../../wrappers/wazuh/shared/agent_op_wrappers.h" -#include "../../wrappers/wazuh/shared/cluster_op_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/hash_op_wrappers.h" -#include "../../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_tasks.h" -#include "../../headers/shared.h" - -extern OSHash *task_table_by_agent_id; - -cJSON *wm_agent_send_task_information_master(const cJSON *message_object); -cJSON *wm_agent_send_task_information_worker(const cJSON *message_object); - -// Setup / teardown - -static int setup_group(void **state) { - wm_agent_upgrade_init_task_map(); - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - wm_agent_upgrade_destroy_task_map(); - test_mode = 0; - return 0; -} - -static int setup_agent_task(void **state) { - wm_agent_task *agent_task = NULL; - agent_task = wm_agent_upgrade_init_agent_task(); - *state = (void *)agent_task; - return 0; -} - -static int teardown_agent_task(void **state) { - wm_agent_task *agent_task = *state; - wm_agent_upgrade_free_agent_task(agent_task); - return 0; -} - -static int setup_node(void **state) { - OSHashNode *node = NULL; - os_calloc(1, sizeof(OSHashNode), node); - *state = (void *)node; - return 0; -} - -static int teardown_node(void **state) { - OSHashNode *node = (OSHashNode *)*state; - os_free(node); - return 0; -} - -static int teardown_jsons(void **state) { - cJSON *json = state[0]; - cJSON *json2 = state[1]; - cJSON_Delete(json); - cJSON_Delete(json2); - return 0; -} - -static int setup_nodes(void **state) { - OSHashNode *node = NULL; - OSHashNode *node_next = NULL; - os_calloc(1, sizeof(OSHashNode), node); - os_calloc(1, sizeof(OSHashNode), node_next); - node->next = node_next; - *state = (void *)node; - return 0; -} - -static int teardown_nodes(void **state) { - OSHashNode *node = (OSHashNode *)*state; - OSHashNode *node_next = node->next; - os_free(node_next->key); - os_free(node_next); - os_free(node->key); - os_free(node); - return 0; -} - -// Tests - -void test_wm_agent_upgrade_create_task_entry_ok(void **state) -{ - int agent_id = 6; - wm_agent_task *agent_task = *state; - - expect_value(__wrap_OSHash_Add_ex, self, task_table_by_agent_id); - expect_string(__wrap_OSHash_Add_ex, key, "6"); - expect_memory(__wrap_OSHash_Add_ex, data, agent_task, sizeof(agent_task)); - will_return(__wrap_OSHash_Add_ex, OSHASH_SUCCESS); - - int ret = wm_agent_upgrade_create_task_entry(agent_id, agent_task); - - assert_int_equal(ret, OSHASH_SUCCESS); -} - -void test_wm_agent_upgrade_create_task_entry_duplicate(void **state) -{ - int agent_id = 6; - wm_agent_task *agent_task = *state; - - expect_value(__wrap_OSHash_Add_ex, self, task_table_by_agent_id); - expect_string(__wrap_OSHash_Add_ex, key, "6"); - expect_memory(__wrap_OSHash_Add_ex, data, agent_task, sizeof(agent_task)); - will_return(__wrap_OSHash_Add_ex, OSHASH_DUPLICATE); - - int ret = wm_agent_upgrade_create_task_entry(agent_id, agent_task); - - assert_int_equal(ret, OSHASH_DUPLICATE); -} - -void test_wm_agent_upgrade_remove_entry_ok(void **state) -{ - int agent_id = 10; - wm_agent_task *agent_task = *state; - - expect_value(__wrap_OSHash_Delete_ex, self, task_table_by_agent_id); - expect_string(__wrap_OSHash_Delete_ex, key, "10"); - will_return(__wrap_OSHash_Delete_ex, agent_task); - - wm_agent_upgrade_remove_entry(agent_id, 1); -} - -void test_wm_agent_upgrade_remove_entry_err(void **state) -{ - int agent_id = 10; - - expect_value(__wrap_OSHash_Delete_ex, self, task_table_by_agent_id); - expect_string(__wrap_OSHash_Delete_ex, key, "10"); - will_return(__wrap_OSHash_Delete_ex, NULL); - - wm_agent_upgrade_remove_entry(agent_id, 0); -} - -void test_wm_agent_upgrade_get_first_node(void **state) -{ - int index = 0; - - expect_value(__wrap_OSHash_Begin, self, task_table_by_agent_id); - will_return(__wrap_OSHash_Begin, 1); - - OSHashNode* ret = wm_agent_upgrade_get_first_node(&index); - - assert_int_equal(ret, 1); -} - -void test_wm_agent_upgrade_get_next_node(void **state) -{ - int index = 0; - OSHashNode *node = *state; - - expect_value(__wrap_OSHash_Next, self, task_table_by_agent_id); - will_return(__wrap_OSHash_Next, 1); - - OSHashNode* ret = wm_agent_upgrade_get_next_node(&index, node); - - assert_int_equal(ret, 1); -} - -void test_wm_agent_upgrade_get_agent_ids_ok(void **state) -{ - OSHashNode *node = *state; - OSHashNode *node_next = node->next; - - os_strdup("025", node->key); - os_strdup("035", node_next->key); - - expect_value(__wrap_OSHash_Begin, self, task_table_by_agent_id); - will_return(__wrap_OSHash_Begin, node); - - expect_value(__wrap_OSHash_Next, self, task_table_by_agent_id); - will_return(__wrap_OSHash_Next, node_next); - - expect_value(__wrap_OSHash_Next, self, task_table_by_agent_id); - will_return(__wrap_OSHash_Next, NULL); - - cJSON *agents_array = wm_agent_upgrade_get_agent_ids(); - - assert_non_null(agents_array); - assert_int_equal(cJSON_GetArraySize(agents_array), 2); - assert_int_equal(cJSON_GetArrayItem(agents_array, 0)->valueint, 25); - assert_int_equal(cJSON_GetArrayItem(agents_array, 1)->valueint, 35); - - cJSON_Delete(agents_array); -} - -void test_wm_agent_upgrade_get_agent_ids_empty(void **state) -{ - (void) state; - - expect_value(__wrap_OSHash_Begin, self, task_table_by_agent_id); - will_return(__wrap_OSHash_Begin, NULL); - - cJSON *agents_array = wm_agent_upgrade_get_agent_ids(); - - assert_null(agents_array); -} - -void test_wm_agent_send_task_information_master_ok(void **state) -{ - int socket = 555; - - char *response = "[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]"; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - char *message = "[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]"; - - expect_string(__wrap_OS_ConnectUnixDomain, path, TASK_QUEUE); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8157): Sending message to task_manager module: '[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(message)); - expect_string(__wrap_OS_SendSecureTCP, msg, message); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, strlen(response) + 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8158): Receiving message from task_manager module: '[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]'"); - - cJSON *output = wm_agent_send_task_information_master(input); - - state[0] = output; - state[1] = input; - - assert_non_null(output); -} - -void test_wm_agent_send_task_information_master_json_err(void **state) -{ - int socket = 555; - - char *response = "wrong json"; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - char *message = "[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]"; - - expect_string(__wrap_OS_ConnectUnixDomain, path, TASK_QUEUE); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8157): Sending message to task_manager module: '[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(message)); - expect_string(__wrap_OS_SendSecureTCP, msg, message); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, strlen(response) + 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8105): Response from task manager does not have a valid JSON format."); - - cJSON *output = wm_agent_send_task_information_master(input); - - state[0] = output; - state[1] = input; - - assert_null(output); -} - -void test_wm_agent_send_task_information_master_recv_error(void **state) -{ - int socket = 555; - - char *response = "[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]"; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - char *message = "[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]"; - - expect_string(__wrap_OS_ConnectUnixDomain, path, TASK_QUEUE); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8157): Sending message to task_manager module: '[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(message)); - expect_string(__wrap_OS_SendSecureTCP, msg, message); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8111): Error in recv(): 'Success'"); - - cJSON *output = wm_agent_send_task_information_master(input); - - state[0] = output; - state[1] = input; - - assert_null(output); -} - -void test_wm_agent_send_task_information_master_sockterr_error(void **state) -{ - int socket = 555; - - char *response = "[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]"; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - char *message = "[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]"; - - expect_string(__wrap_OS_ConnectUnixDomain, path, TASK_QUEUE); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8157): Sending message to task_manager module: '[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(message)); - expect_string(__wrap_OS_SendSecureTCP, msg, message); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - cJSON *output = wm_agent_send_task_information_master(input); - - state[0] = output; - state[1] = input; - - assert_null(output); -} - -void test_wm_agent_send_task_information_master_connect_error(void **state) -{ - int socket = 555; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - expect_string(__wrap_OS_ConnectUnixDomain, path, TASK_QUEUE); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8104): Cannot connect to 'queue/tasks/task'. Could not reach task manager module."); - - cJSON *output = wm_agent_send_task_information_master(input); - - state[0] = output; - state[1] = input; - - assert_null(output); -} - -void test_wm_agent_send_task_information_worker(void **state) -{ - char *response = "[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]"; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - cJSON * cluster_request = cJSON_CreateObject(); - - cJSON_AddStringToObject(cluster_request, "daemon_name", TASK_MANAGER_WM_NAME); - cJSON_AddItemToObject(cluster_request, "message", input); - - char *message = "{\"daemon_name\":\"task-manager\"," - "\"message\":[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]}"; - - will_return(__wrap_cJSON_Duplicate, input); - - expect_string(__wrap_w_create_sendsync_payload, daemon_name, TASK_MANAGER_WM_NAME); - will_return(__wrap_w_create_sendsync_payload, 0); - will_return(__wrap_w_create_sendsync_payload, cluster_request); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8168): Sending sendsync message to task manager in master node: '{\"daemon_name\":\"task-manager\"," - "\"message\":[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]}'"); - - expect_string(__wrap_w_send_clustered_message, command, "sendsync"); - expect_string(__wrap_w_send_clustered_message, payload, message); - will_return(__wrap_w_send_clustered_message, response); - will_return(__wrap_w_send_clustered_message, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8158): Receiving message from task_manager module: '[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]'"); - - cJSON *output = wm_agent_send_task_information_worker(input); - - state[0] = output; - - assert_non_null(output); -} - -void test_wm_agent_upgrade_send_tasks_information_master(void **state) -{ - int socket = 555; - - char *response = "[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]"; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - char *message = "[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]"; - - will_return(__wrap_w_is_worker, 0); - - expect_string(__wrap_OS_ConnectUnixDomain, path, TASK_QUEUE); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8157): Sending message to task_manager module: '[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(message)); - expect_string(__wrap_OS_SendSecureTCP, msg, message); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, strlen(response) + 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8158): Receiving message from task_manager module: '[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]'"); - - cJSON *output = wm_agent_upgrade_send_tasks_information(input); - - state[0] = output; - state[1] = input; - - assert_non_null(output); -} - -void test_wm_agent_upgrade_send_tasks_information_worker(void **state) -{ - char *response = "[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]"; - - cJSON *input = cJSON_CreateArray(); - - cJSON *task_request1 = cJSON_CreateObject(); - cJSON *task_request2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_request1, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request1, "command", "upgrade"); - cJSON_AddNumberToObject(task_request1, "agent", 12); - - cJSON_AddStringToObject(task_request2, "module", "upgrade_module"); - cJSON_AddStringToObject(task_request2, "command", "upgrade"); - cJSON_AddNumberToObject(task_request2, "agent", 10); - - cJSON_AddItemToArray(input, task_request1); - cJSON_AddItemToArray(input, task_request2); - - cJSON * cluster_request = cJSON_CreateObject(); - - cJSON_AddStringToObject(cluster_request, "daemon_name", TASK_MANAGER_WM_NAME); - cJSON_AddItemToObject(cluster_request, "message", input); - - char *message = "{\"daemon_name\":\"task-manager\"," - "\"message\":[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]}"; - - will_return(__wrap_w_is_worker, 1); - - will_return(__wrap_cJSON_Duplicate, input); - - expect_string(__wrap_w_create_sendsync_payload, daemon_name, TASK_MANAGER_WM_NAME); - will_return(__wrap_w_create_sendsync_payload, 0); - will_return(__wrap_w_create_sendsync_payload, cluster_request); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8168): Sending sendsync message to task manager in master node: '{\"daemon_name\":\"task-manager\"," - "\"message\":[{\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":12},{" - "\"module\":\"upgrade_module\"," - "\"command\":\"upgrade\"," - "\"agent\":10}]}'"); - - expect_string(__wrap_w_send_clustered_message, command, "sendsync"); - expect_string(__wrap_w_send_clustered_message, payload, message); - will_return(__wrap_w_send_clustered_message, response); - will_return(__wrap_w_send_clustered_message, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8158): Receiving message from task_manager module: '[{\"error\":0," - "\"data\":\"Success\"," - "\"agent\":12," - "\"task_id\":100},{" - "\"error\":0," - "\"data\":\"Success\"," - "\"agent\":10," - "\"task_id\":101}]'"); - - cJSON *output = wm_agent_upgrade_send_tasks_information(input); - - state[0] = output; - - assert_non_null(output); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_upgrade_success_callback - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_create_task_entry_ok, setup_agent_task, teardown_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_create_task_entry_duplicate, setup_agent_task, teardown_agent_task), - // wm_agent_upgrade_remove_entry - cmocka_unit_test_setup(test_wm_agent_upgrade_remove_entry_ok, setup_agent_task), - cmocka_unit_test(test_wm_agent_upgrade_remove_entry_err), - // wm_agent_upgrade_get_first_node - cmocka_unit_test(test_wm_agent_upgrade_get_first_node), - // wm_agent_upgrade_get_next_node - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_get_next_node, setup_node, teardown_node), - // wm_agent_upgrade_get_agent_ids - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_get_agent_ids_ok, setup_nodes, teardown_nodes), - cmocka_unit_test(test_wm_agent_upgrade_get_agent_ids_empty), - // wm_agent_send_task_information_master - cmocka_unit_test_teardown(test_wm_agent_send_task_information_master_ok, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_send_task_information_master_json_err, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_send_task_information_master_recv_error, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_send_task_information_master_sockterr_error, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_send_task_information_master_connect_error, teardown_jsons), - // wm_agent_send_task_information_worker - cmocka_unit_test_teardown(test_wm_agent_send_task_information_worker, teardown_jsons), - // wm_agent_upgrade_send_tasks_information - cmocka_unit_test_teardown(test_wm_agent_upgrade_send_tasks_information_master, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_send_tasks_information_worker, teardown_jsons), - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_tasks_callbacks.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_tasks_callbacks.c deleted file mode 100644 index f4044a0e005..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_tasks_callbacks.c +++ /dev/null @@ -1,744 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_tasks.h" -#include "../../headers/shared.h" - -// Setup / teardown - -static int teardown_jsons(void **state) { - cJSON *json1 = state[0]; - cJSON *json2 = state[1]; - if (json1 != json2) { - cJSON_Delete(json2); - } - cJSON_Delete(json1); - return 0; -} - -// Tests - -void test_wm_agent_upgrade_upgrade_success_callback_ok(void **state) -{ - int error = 0; - int agent = 9; - int task = 35; - char *data = "Success"; - cJSON *input = cJSON_CreateObject(); - - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, task); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, data); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 1); - - cJSON *response = wm_agent_upgrade_upgrade_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)response; - - assert_int_equal(error, 0); - assert_memory_equal(response, input, sizeof(input)); -} - -void test_wm_agent_upgrade_upgrade_success_callback_no_task_id(void **state) -{ - int error = 0; - int agent = 9; - int task = 0; - char *data = "No task ID"; - cJSON *input = cJSON_CreateObject(); - cJSON *error_json = cJSON_CreateObject(); - - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, task); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, data); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 1); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, agent); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, data); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agent); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error_json); - - cJSON *response = wm_agent_upgrade_upgrade_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)response; - - assert_int_equal(error, 0); - assert_memory_equal(response, error_json, sizeof(error_json)); -} - -void test_wm_agent_upgrade_upgrade_success_callback_validate_error(void **state) -{ - int error = 0; - int agent = 9; - int task = 35; - char *data = "Error"; - cJSON *input = cJSON_CreateObject(); - - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, task); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, data); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 0); - - cJSON *response = wm_agent_upgrade_upgrade_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)response; - - assert_int_equal(error, OS_INVALID); - assert_null(response); -} - -void test_wm_agent_upgrade_get_status_success_callback_ok(void **state) -{ - int error = 0; - int agent = 9; - char *status = "Done"; - cJSON *input = cJSON_CreateObject(); - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, status); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, 1); - - cJSON *response = wm_agent_upgrade_get_status_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)response; - - assert_int_equal(error, 0); - assert_null(response); -} - -void test_wm_agent_upgrade_get_status_success_callback_status_pending(void **state) -{ - int error = 0; - int agent = 9; - char *status = "Pending"; - cJSON *input = cJSON_CreateObject(); - cJSON *error_json = cJSON_CreateObject(); - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, status); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, 1); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, agent); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_UPGRADE_ALREADY_IN_PROGRESS); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_UPGRADE_ALREADY_IN_PROGRESS]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agent); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error_json); - - cJSON *response = wm_agent_upgrade_get_status_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)response; - - assert_int_equal(error, 0); - assert_memory_equal(response, error_json, sizeof(error_json)); -} - -void test_wm_agent_upgrade_get_status_success_callback_status_in_progress(void **state) -{ - int error = 0; - int agent = 9; - char *status = "In progress"; - cJSON *input = cJSON_CreateObject(); - cJSON *error_json = cJSON_CreateObject(); - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, status); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, 1); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, agent); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_UPGRADE_ALREADY_IN_PROGRESS); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_UPGRADE_ALREADY_IN_PROGRESS]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, agent); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error_json); - - cJSON *response = wm_agent_upgrade_get_status_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)response; - - assert_int_equal(error, 0); - assert_memory_equal(response, error_json, sizeof(error_json)); -} - -void test_wm_agent_upgrade_get_status_success_callback_validate_error(void **state) -{ - int error = 0; - int agent = 9; - char *status = "Done"; - cJSON *input = cJSON_CreateObject(); - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, status); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, 0); - - cJSON *response = wm_agent_upgrade_get_status_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)response; - - assert_int_equal(error, OS_INVALID); - assert_null(response); -} - -void test_wm_agent_upgrade_update_status_success_callback_ok(void **state) -{ - int error = 0; - int agent = 15; - cJSON *input = cJSON_CreateObject(); - char *cmd = "015 upgrade {\"command\":\"clear_upgrade_result\",\"parameters\":{}}"; - char *agent_res = NULL; - - os_calloc(37, sizeof(char), agent_res); - snprintf(agent_res, 37, "{\"error\":0,\"message\":\"ok\",\"data\":[]}"); - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, 1); - - expect_string(__wrap_wm_agent_upgrade_send_command_to_agent, command, cmd); - expect_value(__wrap_wm_agent_upgrade_send_command_to_agent, command_size, strlen(cmd)); - will_return(__wrap_wm_agent_upgrade_send_command_to_agent, agent_res); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8167): Upgrade result file has been successfully erased from the agent."); - - cJSON *result = wm_agent_upgrade_update_status_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)result; - - assert_int_equal(error, 0); - assert_memory_equal(result, input, sizeof(input)); -} - -void test_wm_agent_upgrade_update_status_success_callback_delete_error(void **state) -{ - int error = 0; - int agent = 15; - cJSON *input = cJSON_CreateObject(); - char *cmd = "015 upgrade {\"command\":\"clear_upgrade_result\",\"parameters\":{}}"; - char *agent_res = NULL; - - os_calloc(37, sizeof(char), agent_res); - snprintf(agent_res, 37, "{\"error\":0,\"message\":\"ok\",\"data\":[]}"); - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, 1); - - expect_string(__wrap_wm_agent_upgrade_send_command_to_agent, command, cmd); - expect_value(__wrap_wm_agent_upgrade_send_command_to_agent, command_size, strlen(cmd)); - will_return(__wrap_wm_agent_upgrade_send_command_to_agent, agent_res); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, OS_INVALID); - - cJSON *result = wm_agent_upgrade_update_status_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)result; - - assert_int_equal(error, 0); - assert_memory_equal(result, input, sizeof(input)); -} - -void test_wm_agent_upgrade_update_status_success_validate_error(void **state) -{ - int error = 0; - int agent = 0; - cJSON *input = cJSON_CreateObject(); - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, 1); - - cJSON *result = wm_agent_upgrade_update_status_success_callback(&error, input); - - state[0] = (void *)input; - state[1] = (void *)result; - - assert_int_equal(error, OS_INVALID); - assert_null(result); -} - -void test_wm_agent_upgrade_task_module_callback_no_callbacks_ok(void **state) -{ - cJSON *output = cJSON_CreateArray(); - - cJSON *input = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(input, "origin", origin); - cJSON_AddStringToObject(input, "command", "upgrade"); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(12)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(10)); - cJSON_AddItemToObject(parameters, "agents", agents); - cJSON_AddItemToObject(input, "parameters", parameters); - - cJSON *task_response = cJSON_CreateObject(); - cJSON *data = cJSON_CreateArray(); - cJSON *task1 = cJSON_CreateObject(); - cJSON *task2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task1, "error", 0); - cJSON_AddStringToObject(task1, "message", "Success"); - cJSON_AddNumberToObject(task1, "agent", 12); - cJSON_AddItemToArray(data, task1); - - cJSON_AddNumberToObject(task2, "error", 1); - cJSON_AddStringToObject(task2, "message", "Error"); - cJSON_AddNumberToObject(task2, "agent", 10); - cJSON_AddItemToArray(data, task2); - - cJSON_AddNumberToObject(task_response, "error", 0); - cJSON_AddItemToObject(task_response, "data", data); - cJSON_AddStringToObject(task_response, "message", "Success"); - - expect_memory(__wrap_wm_agent_upgrade_send_tasks_information, message_object, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_send_tasks_information, task_response); - - int result = wm_agent_upgrade_task_module_callback(output, input, NULL, NULL); - - state[0] = (void *)input; - state[1] = (void *)output; - - assert_int_equal(result, 0); - assert_int_equal(cJSON_GetArraySize(output), 2); - cJSON *out1 = cJSON_GetArrayItem(output, 0); - assert_non_null(cJSON_GetObjectItem(out1, "error")); - assert_int_equal(cJSON_GetObjectItem(out1, "error")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(out1, "message")); - assert_string_equal(cJSON_GetObjectItem(out1, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(out1, "agent")); - assert_int_equal(cJSON_GetObjectItem(out1, "agent")->valueint, 12); - cJSON *out2 = cJSON_GetArrayItem(output, 1); - assert_non_null(cJSON_GetObjectItem(out2, "error")); - assert_int_equal(cJSON_GetObjectItem(out2, "error")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(out2, "message")); - assert_string_equal(cJSON_GetObjectItem(out2, "message")->valuestring, "Error"); - assert_non_null(cJSON_GetObjectItem(out2, "agent")); - assert_int_equal(cJSON_GetObjectItem(out2, "agent")->valueint, 10); - assert_null(cJSON_GetArrayItem(output, 2)); -} - -void test_wm_agent_upgrade_task_module_callback_success_callback_ok(void **state) -{ - cJSON *output = cJSON_CreateArray(); - - cJSON *input = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(input, "origin", origin); - cJSON_AddStringToObject(input, "command", "upgrade"); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(12)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(10)); - cJSON_AddItemToObject(parameters, "agents", agents); - cJSON_AddItemToObject(input, "parameters", parameters); - - cJSON *task_response = cJSON_CreateObject(); - cJSON *data = cJSON_CreateArray(); - cJSON *task1 = cJSON_CreateObject(); - cJSON *task2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task1, "error", 0); - cJSON_AddStringToObject(task1, "message", "Success"); - cJSON_AddNumberToObject(task1, "agent", 12); - cJSON_AddNumberToObject(task1, "task_id", 115); - cJSON_AddItemToArray(data, task1); - - cJSON_AddNumberToObject(task2, "error", 1); - cJSON_AddStringToObject(task2, "message", "Error"); - cJSON_AddNumberToObject(task2, "agent", 10); - cJSON_AddItemToArray(data, task2); - - cJSON_AddNumberToObject(task_response, "error", 0); - cJSON_AddItemToObject(task_response, "data", data); - cJSON_AddStringToObject(task_response, "message", "Success"); - - cJSON *error_json = cJSON_CreateObject(); - - cJSON_AddNumberToObject(error_json, "error", 1); - cJSON_AddStringToObject(error_json, "message", "Error"); - cJSON_AddNumberToObject(error_json, "agent", 10); - - expect_memory(__wrap_wm_agent_upgrade_send_tasks_information, message_object, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_send_tasks_information, task_response); - - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 12); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 115); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, "Success"); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 1); - - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 10); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 0); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, "Error"); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 1); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 10); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_FAILURE); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, "Error"); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, 10); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error_json); - - int result = wm_agent_upgrade_task_module_callback(output, input, wm_agent_upgrade_upgrade_success_callback, NULL); - - state[0] = (void *)input; - state[1] = (void *)output; - - assert_int_equal(result, 0); - assert_int_equal(cJSON_GetArraySize(output), 2); - cJSON *out1 = cJSON_GetArrayItem(output, 0); - assert_non_null(cJSON_GetObjectItem(out1, "error")); - assert_int_equal(cJSON_GetObjectItem(out1, "error")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(out1, "message")); - assert_string_equal(cJSON_GetObjectItem(out1, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(out1, "agent")); - assert_int_equal(cJSON_GetObjectItem(out1, "agent")->valueint, 12); - assert_non_null(cJSON_GetObjectItem(out1, "task_id")); - assert_int_equal(cJSON_GetObjectItem(out1, "task_id")->valueint, 115); - cJSON *out2 = cJSON_GetArrayItem(output, 1); - assert_non_null(cJSON_GetObjectItem(out2, "error")); - assert_int_equal(cJSON_GetObjectItem(out2, "error")->valueint, 1); - assert_non_null(cJSON_GetObjectItem(out2, "message")); - assert_string_equal(cJSON_GetObjectItem(out2, "message")->valuestring, "Error"); - assert_non_null(cJSON_GetObjectItem(out2, "agent")); - assert_int_equal(cJSON_GetObjectItem(out2, "agent")->valueint, 10); - assert_null(cJSON_GetObjectItem(out2, "task_id")); - assert_null(cJSON_GetArrayItem(output, 2)); -} - -void test_wm_agent_upgrade_task_module_callback_no_callbacks_error(void **state) -{ - cJSON *output = cJSON_CreateArray(); - - cJSON *input = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(input, "origin", origin); - cJSON_AddStringToObject(input, "command", "upgrade"); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(12)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(10)); - cJSON_AddItemToObject(parameters, "agents", agents); - cJSON_AddItemToObject(input, "parameters", parameters); - - cJSON *task_response = cJSON_CreateObject(); - cJSON *data = cJSON_CreateArray(); - - cJSON_AddNumberToObject(task_response, "error", 1); - cJSON_AddItemToObject(task_response, "data", data); - cJSON_AddStringToObject(task_response, "message", "Error"); - - cJSON *error1 = cJSON_CreateObject(); - cJSON *error2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(error1, "error", WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - cJSON_AddStringToObject(error1, "message", upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - cJSON_AddNumberToObject(error1, "agent", 12); - - cJSON_AddNumberToObject(error2, "error", WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - cJSON_AddStringToObject(error2, "message", upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - cJSON_AddNumberToObject(error2, "agent", 10); - - expect_memory(__wrap_wm_agent_upgrade_send_tasks_information, message_object, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_send_tasks_information, task_response); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, 12); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error1); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, 10); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error2); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8123): There has been an error executing the request in the tasks manager."); - - int result = wm_agent_upgrade_task_module_callback(output, input, NULL, NULL); - - state[0] = (void *)input; - state[1] = (void *)output; - - assert_int_equal(result, OS_INVALID); - assert_int_equal(cJSON_GetArraySize(output), 2); - cJSON *out1 = cJSON_GetArrayItem(output, 0); - assert_non_null(cJSON_GetObjectItem(out1, "error")); - assert_int_equal(cJSON_GetObjectItem(out1, "error")->valueint, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - assert_non_null(cJSON_GetObjectItem(out1, "message")); - assert_string_equal(cJSON_GetObjectItem(out1, "message")->valuestring, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - assert_non_null(cJSON_GetObjectItem(out1, "agent")); - assert_int_equal(cJSON_GetObjectItem(out1, "agent")->valueint, 12); - cJSON *out2 = cJSON_GetArrayItem(output, 1); - assert_non_null(cJSON_GetObjectItem(out2, "error")); - assert_int_equal(cJSON_GetObjectItem(out2, "error")->valueint, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - assert_non_null(cJSON_GetObjectItem(out2, "message")); - assert_string_equal(cJSON_GetObjectItem(out2, "message")->valuestring, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - assert_non_null(cJSON_GetObjectItem(out2, "agent")); - assert_int_equal(cJSON_GetObjectItem(out2, "agent")->valueint, 10); - assert_null(cJSON_GetArrayItem(output, 2)); -} - -void test_wm_agent_upgrade_task_module_callback_error_callback_error(void **state) -{ - cJSON *output = cJSON_CreateArray(); - - cJSON *input = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(input, "origin", origin); - cJSON_AddStringToObject(input, "command", "upgrade"); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(12)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(10)); - cJSON_AddItemToObject(parameters, "agents", agents); - cJSON_AddItemToObject(input, "parameters", parameters); - - cJSON *task_response = cJSON_CreateObject(); - cJSON *data = cJSON_CreateArray(); - - cJSON_AddNumberToObject(task_response, "error", 1); - cJSON_AddItemToObject(task_response, "data", data); - cJSON_AddStringToObject(task_response, "message", "Error"); - - cJSON *error1 = cJSON_CreateObject(); - cJSON *error2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(error1, "error", WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - cJSON_AddStringToObject(error1, "message", upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - cJSON_AddNumberToObject(error1, "agent", 12); - - cJSON_AddNumberToObject(error2, "error", WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - cJSON_AddStringToObject(error2, "message", upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - cJSON_AddNumberToObject(error2, "agent", 10); - - expect_memory(__wrap_wm_agent_upgrade_send_tasks_information, message_object, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_send_tasks_information, task_response); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 12); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, 12); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error1); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 10); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, 10); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error2); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8123): There has been an error executing the request in the tasks manager."); - - int result = wm_agent_upgrade_task_module_callback(output, input, NULL, wm_agent_upgrade_remove_entry); - - state[0] = (void *)input; - state[1] = (void *)output; - - assert_int_equal(result, OS_INVALID); - assert_int_equal(cJSON_GetArraySize(output), 2); - cJSON *out1 = cJSON_GetArrayItem(output, 0); - assert_non_null(cJSON_GetObjectItem(out1, "error")); - assert_int_equal(cJSON_GetObjectItem(out1, "error")->valueint, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - assert_non_null(cJSON_GetObjectItem(out1, "message")); - assert_string_equal(cJSON_GetObjectItem(out1, "message")->valuestring, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - assert_non_null(cJSON_GetObjectItem(out1, "agent")); - assert_int_equal(cJSON_GetObjectItem(out1, "agent")->valueint, 12); - cJSON *out2 = cJSON_GetArrayItem(output, 1); - assert_non_null(cJSON_GetObjectItem(out2, "error")); - assert_int_equal(cJSON_GetObjectItem(out2, "error")->valueint, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - assert_non_null(cJSON_GetObjectItem(out2, "message")); - assert_string_equal(cJSON_GetObjectItem(out2, "message")->valuestring, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - assert_non_null(cJSON_GetObjectItem(out2, "agent")); - assert_int_equal(cJSON_GetObjectItem(out2, "agent")->valueint, 10); - assert_null(cJSON_GetArrayItem(output, 2)); -} - -void test_wm_agent_upgrade_task_module_callback_success_error_callback_error(void **state) -{ - cJSON *output = cJSON_CreateArray(); - - cJSON *input = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(input, "origin", origin); - cJSON_AddStringToObject(input, "command", "upgrade"); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(12)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(10)); - cJSON_AddItemToObject(parameters, "agents", agents); - cJSON_AddItemToObject(input, "parameters", parameters); - - cJSON *task_response = cJSON_CreateObject(); - cJSON *data = cJSON_CreateArray(); - cJSON *task1 = cJSON_CreateObject(); - cJSON *task2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(task1, "error", 0); - cJSON_AddStringToObject(task1, "message", "Success"); - cJSON_AddNumberToObject(task1, "agent", 12); - cJSON_AddNumberToObject(task1, "task_id", 115); - cJSON_AddItemToArray(data, task1); - - cJSON_AddNumberToObject(task2, "error", 0); - cJSON_AddStringToObject(task2, "message", "Success"); - cJSON_AddNumberToObject(task2, "agent", 10); - cJSON_AddNumberToObject(task2, "task_id", 116); - cJSON_AddItemToArray(data, task2); - - cJSON_AddNumberToObject(task_response, "error", 0); - cJSON_AddItemToObject(task_response, "data", data); - cJSON_AddStringToObject(task_response, "message", "Success"); - - cJSON *error1 = cJSON_CreateObject(); - cJSON *error2 = cJSON_CreateObject(); - - cJSON_AddNumberToObject(error1, "error", WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - cJSON_AddStringToObject(error1, "message", upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - cJSON_AddNumberToObject(error1, "agent", 12); - - cJSON_AddNumberToObject(error2, "error", WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - cJSON_AddStringToObject(error2, "message", upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - cJSON_AddNumberToObject(error2, "agent", 10); - - expect_memory(__wrap_wm_agent_upgrade_send_tasks_information, message_object, input, sizeof(input)); - will_return(__wrap_wm_agent_upgrade_send_tasks_information, task_response); - - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 12); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 115); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, "Success"); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 1); - - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 10); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 116); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, "Error"); - will_return(__wrap_wm_agent_upgrade_validate_task_ids_message, 0); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 12); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, 12); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error1); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 10); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 1); - will_return(__wrap_wm_agent_upgrade_remove_entry, 0); - - expect_value(__wrap_wm_agent_upgrade_parse_data_response, error_id, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - expect_string(__wrap_wm_agent_upgrade_parse_data_response, message, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - expect_value(__wrap_wm_agent_upgrade_parse_data_response, agent_int, 10); - will_return(__wrap_wm_agent_upgrade_parse_data_response, error2); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8123): There has been an error executing the request in the tasks manager."); - - int result = wm_agent_upgrade_task_module_callback(output, input, wm_agent_upgrade_upgrade_success_callback, wm_agent_upgrade_remove_entry); - - state[0] = (void *)input; - state[1] = (void *)output; - - assert_int_equal(result, OS_INVALID); - assert_int_equal(cJSON_GetArraySize(output), 2); - cJSON *out1 = cJSON_GetArrayItem(output, 0); - assert_non_null(cJSON_GetObjectItem(out1, "error")); - assert_int_equal(cJSON_GetObjectItem(out1, "error")->valueint, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - assert_non_null(cJSON_GetObjectItem(out1, "message")); - assert_string_equal(cJSON_GetObjectItem(out1, "message")->valuestring, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - assert_non_null(cJSON_GetObjectItem(out1, "agent")); - assert_int_equal(cJSON_GetObjectItem(out1, "agent")->valueint, 12); - cJSON *out2 = cJSON_GetArrayItem(output, 1); - assert_non_null(cJSON_GetObjectItem(out2, "error")); - assert_int_equal(cJSON_GetObjectItem(out2, "error")->valueint, WM_UPGRADE_TASK_MANAGER_COMMUNICATION); - assert_non_null(cJSON_GetObjectItem(out2, "message")); - assert_string_equal(cJSON_GetObjectItem(out2, "message")->valuestring, upgrade_error_codes[WM_UPGRADE_TASK_MANAGER_COMMUNICATION]); - assert_non_null(cJSON_GetObjectItem(out2, "agent")); - assert_int_equal(cJSON_GetObjectItem(out2, "agent")->valueint, 10); - assert_null(cJSON_GetArrayItem(output, 2)); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_upgrade_success_callback - cmocka_unit_test_teardown(test_wm_agent_upgrade_upgrade_success_callback_ok, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_upgrade_success_callback_no_task_id, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_upgrade_success_callback_validate_error, teardown_jsons), - // wm_agent_upgrade_get_status_success_callback - cmocka_unit_test_teardown(test_wm_agent_upgrade_get_status_success_callback_ok, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_get_status_success_callback_status_pending, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_get_status_success_callback_status_in_progress, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_get_status_success_callback_validate_error, teardown_jsons), - // wm_agent_upgrade_update_status_success_callback - cmocka_unit_test_teardown(test_wm_agent_upgrade_update_status_success_callback_ok, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_update_status_success_callback_delete_error, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_update_status_success_validate_error, teardown_jsons), - // wm_agent_upgrade_task_module_callback - cmocka_unit_test_teardown(test_wm_agent_upgrade_task_module_callback_no_callbacks_ok, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_task_module_callback_success_callback_ok, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_task_module_callback_no_callbacks_error, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_task_module_callback_error_callback_error, teardown_jsons), - cmocka_unit_test_teardown(test_wm_agent_upgrade_task_module_callback_success_error_callback_error, teardown_jsons) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_upgrades.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_upgrades.c deleted file mode 100644 index 71b526735ef..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_upgrades.c +++ /dev/null @@ -1,3868 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/posix/pthread_wrappers.h" -#include "../../wrappers/posix/unistd_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/queue_linked_op_wrappers.h" -#include "../../wrappers/wazuh/shared/version_op_wrappers.h" -#include "../../wrappers/wazuh/os_crypto/sha1_op_wrappers.h" -#include "../../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_upgrades.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_tasks.h" -#include "../../headers/shared.h" - -extern w_linked_queue_t *upgrade_queue; - -extern sem_t upgrade_semaphore; - -typedef struct _test_upgrade_args { - wm_manager_configs *config; - wm_agent_task *agent_task; -} test_upgrade_args; - -void* wm_agent_upgrade_start_upgrade(void *arg); -int wm_agent_upgrade_send_wpk_to_agent(const wm_agent_task *agent_task, const wm_manager_configs* manager_configs); -int wm_agent_upgrade_send_lock_restart(int agent_id); -int wm_agent_upgrade_send_open(int agent_id, int wpk_message_format, const char *wpk_file); -int wm_agent_upgrade_send_write(int agent_id, int wpk_message_format, const char *wpk_file, const char *file_path, int chunk_size); -int wm_agent_upgrade_send_close(int agent_id, int wpk_message_format, const char *wpk_file); -int wm_agent_upgrade_send_sha1(int agent_id, int wpk_message_format, const char *wpk_file, const char *file_sha1); -int wm_agent_upgrade_send_upgrade(int agent_id, int wpk_message_format, const char *wpk_file, const char *installer); - -// Setup / teardown - -static int teardown_string(void **state) { - char *string = *state; - os_free(string); - return 0; -} - -static int setup_config(void **state) { - wm_manager_configs *config = NULL; - os_calloc(1, sizeof(wm_manager_configs), config); - *state = config; - upgrade_queue = linked_queue_init(); - return 0; -} - -static int teardown_config(void **state) { - wm_manager_configs *config = *state; - os_free(config); - linked_queue_free(upgrade_queue); - return 0; -} - -static int setup_upgrade_args(void **state) { - test_upgrade_args *args = NULL; - wm_manager_configs *config = NULL; - wm_agent_task *agent_task = NULL; - os_calloc(1, sizeof(test_upgrade_args), args); - os_calloc(1, sizeof(wm_manager_configs), config); - agent_task = wm_agent_upgrade_init_agent_task(); - agent_task->agent_info = wm_agent_upgrade_init_agent_info(); - agent_task->task_info = wm_agent_upgrade_init_task_info(); - args->agent_task = agent_task; - args->config = config; - state[0] = (void *)args; - state[1] = (void *)config; - upgrade_queue = linked_queue_init(); - sem_init(&upgrade_semaphore, 0, 5); - return 0; -} - -static int teardown_upgrade_args(void **state) { - wm_manager_configs *config = state[1]; - os_free(config); - linked_queue_free(upgrade_queue); - sem_destroy(&upgrade_semaphore); - return 0; -} - -static int setup_nodes(void **state) { - setup_hash_table(NULL); - OSHashNode *node = NULL; - OSHashNode *node_next = NULL; - wm_agent_task *agent_task = NULL; - wm_agent_task *agent_task_next = NULL; - os_calloc(1, sizeof(OSHashNode), node); - os_calloc(1, sizeof(OSHashNode), node_next); - agent_task = wm_agent_upgrade_init_agent_task(); - agent_task_next = wm_agent_upgrade_init_agent_task(); - node->data = agent_task; - node_next->data = agent_task_next; - node->next = node_next; - *state = (void *)node; - upgrade_queue = linked_queue_init(); - return 0; -} - -static int teardown_nodes(void **state) { - teardown_hash_table(); - OSHashNode *node = (OSHashNode *)*state; - OSHashNode *node_next = node->next; - wm_agent_task *agent_task = node->data; - wm_agent_task *agent_task_next = node_next->data; - wm_agent_upgrade_free_agent_task(agent_task_next); - wm_agent_upgrade_free_agent_task(agent_task); - os_free(node_next->key); - os_free(node_next); - os_free(node->key); - os_free(node); - while(upgrade_queue->first) { - w_linked_queue_node_t *tmp = upgrade_queue->first; - upgrade_queue->first = upgrade_queue->first->next; - os_free(tmp); - } - linked_queue_free(upgrade_queue); - return 0; -} - -static int setup_config_agent_task(void **state) { - wm_manager_configs *config = NULL; - wm_agent_task *agent_task = NULL; - os_calloc(1, sizeof(wm_manager_configs), config); - agent_task = wm_agent_upgrade_init_agent_task(); - agent_task->agent_info = wm_agent_upgrade_init_agent_info(); - agent_task->task_info = wm_agent_upgrade_init_task_info(); - state[0] = (void *)config; - state[1] = (void *)agent_task; - return 0; -} - -static int teardown_config_agent_task(void **state) { - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - os_free(config); - wm_agent_upgrade_free_agent_task(agent_task); - return 0; -} - -static int setup_group(void **state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - -// Wrappers - -int __wrap_CreateThread(void * (*function_pointer)(void *), void *data) { - check_expected_ptr(function_pointer); - - test_upgrade_args *args = (test_upgrade_args *)data; - wm_agent_task *agent_task = args->agent_task; - wm_manager_configs *config = args->config; - - check_expected(agent_task); - check_expected(config); - - wm_agent_upgrade_free_agent_task(agent_task); - os_free(args); - - return 1; -} - -// Tests - -void test_wm_agent_upgrade_send_command_to_agent_ok(void **state) -{ - int socket = 555; - char *command = "Command to agent: restart agent now."; - char *response = "Command received OK."; - size_t response_size = strlen(response) + 1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: 'Command to agent: restart agent now.'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(command)); - expect_string(__wrap_OS_SendSecureTCP, msg, command); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, response_size); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'Command received OK.'"); - - char *res = wm_agent_upgrade_send_command_to_agent(command, strlen(command)); - - *state = res; - - assert_non_null(res); - assert_string_equal(res, response); -} - -void test_wm_agent_upgrade_send_command_to_agent_recv_error(void **state) -{ - int socket = 555; - char *command = "Command to agent: restart agent now."; - char *response = "Error."; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: 'Command to agent: restart agent now.'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(command)); - expect_string(__wrap_OS_SendSecureTCP, msg, command); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8111): Error in recv(): 'Success'"); - - char *res = wm_agent_upgrade_send_command_to_agent(command, 0); - - *state = res; - - assert_non_null(res); -} - -void test_wm_agent_upgrade_send_command_to_agent_sockterr_error(void **state) -{ - int socket = 555; - char *command = "Command to agent: restart agent now."; - char *response = "Command received OK."; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: 'Command to agent: restart agent now.'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(command)); - expect_string(__wrap_OS_SendSecureTCP, msg, command); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, response); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8112): Response size is bigger than expected."); - - char *res = wm_agent_upgrade_send_command_to_agent(command, 0); - - *state = res; - - assert_non_null(res); - assert_string_equal(res, response); -} - -void test_wm_agent_upgrade_send_command_to_agent_connect_error(void **state) -{ - char *command = "Command to agent: restart agent now."; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8114): Cannot connect to 'queue/sockets/remote'. Could not reach agent."); - - char *res = wm_agent_upgrade_send_command_to_agent(command, strlen(command)); - - *state = res; - - assert_null(res); -} - -void test_wm_agent_upgrade_send_lock_restart_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent = 28; - char *cmd = "028 com lock_restart -1"; - char *agent_res = "ok "; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '028 com lock_restart -1'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - int res = wm_agent_upgrade_send_lock_restart(agent); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_lock_restart_err(void **state) -{ - (void) state; - - int socket = 555; - int agent = 28; - char *cmd = "028 com lock_restart -1"; - char *agent_res = "err Could not restart agent"; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '028 com lock_restart -1'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not restart agent'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_lock_restart(agent); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_open_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent = 39; - char *wpk_file = "test.wpk"; - char *cmd = "039 com open wb test.wpk"; - char *agent_res = "ok "; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - int res = wm_agent_upgrade_send_open(agent, format, wpk_file); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_open_ok_new(void **state) -{ - (void) state; - - int socket = 555; - int agent = 39; - char *wpk_file = "test.wpk"; - char *cmd = "039 upgrade {\"command\":\"open\",\"parameters\":{\"mode\":\"wb\",\"file\":\"test.wpk\"}}"; - char *agent_res = "{\"error\":0,\"message\":\"ok\",\"data\": []}"; - int format = 1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 upgrade {\"command\":\"open\",\"parameters\":{\"mode\":\"wb\",\"file\":\"test.wpk\"}}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: '{\"error\":0,\"message\":\"ok\",\"data\": []}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, 0); - - int res = wm_agent_upgrade_send_open(agent, format, wpk_file); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_open_retry_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent = 39; - char *wpk_file = "test.wpk"; - char *cmd = "039 com open wb test.wpk"; - char *agent_res1 = "err Could not open file in agent"; - char *agent_res2 = "ok "; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res1) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res1); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res2); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res2) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res2); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - int res = wm_agent_upgrade_send_open(agent, format, wpk_file); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_open_retry_err(void **state) -{ - (void) state; - - int socket = 555; - int agent = 39; - char *wpk_file = "test.wpk"; - char *cmd = "039 com open wb test.wpk"; - char *agent_res = "err Could not open file in agent"; - int format = -1; - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 10); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 10); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 10); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 10); - - expect_value_count(__wrap_OS_SendSecureTCP, sock, socket, 10); - expect_value_count(__wrap_OS_SendSecureTCP, size, strlen(cmd), 10); - expect_string_count(__wrap_OS_SendSecureTCP, msg, cmd, 10); - will_return_count(__wrap_OS_SendSecureTCP, 0, 10); - - expect_value_count(__wrap_OS_RecvSecureTCP, sock, socket, 10); - expect_value_count(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR, 10); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 20); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not open file in agent'"); - - expect_string_count(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res, 10); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID, 10); - - int res = wm_agent_upgrade_send_open(agent, format, wpk_file); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_write_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent = 39; - char *wpk_file = "test.wpk"; - char *file_path = "/var/upgrade/wazuh_agent.wpk"; - int chunk_size = 5; - char *chunk = "test\n"; - char *cmd = "039 com write 5 test.wpk test\n"; - char *agent_res = "ok "; - int format = -1; - - expect_string(__wrap_wfopen, path, file_path); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, chunk_size); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com write 5 test.wpk test\n'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, chunk_size); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com write 5 test.wpk test\n'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, 0); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - int res = wm_agent_upgrade_send_write(agent, format, wpk_file, file_path, chunk_size); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_write_ok_new(void **state) -{ - (void) state; - - int socket = 555; - int agent = 39; - char *wpk_file = "test.wpk"; - char *file_path = "/var/upgrade/wazuh_agent.wpk"; - int chunk_size = 5; - char *chunk = "test\n"; - char *cmd = "039 upgrade {\"command\":\"write\",\"parameters\":{\"buffer\":\"dGVzdAo=\",\"length\":5,\"file\":\"test.wpk\"}}"; - char *agent_res = "{\"error\":0,\"message\":\"ok\",\"data\": []}"; - int format = 1; - - expect_string(__wrap_wfopen, path, file_path); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, chunk_size); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 upgrade {\"command\":\"write\",\"parameters\":{\"buffer\":\"dGVzdAo=\",\"length\":5,\"file\":\"test.wpk\"}}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: '{\"error\":0,\"message\":\"ok\",\"data\": []}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, 0); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, chunk_size); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 upgrade {\"command\":\"write\",\"parameters\":{\"buffer\":\"dGVzdAo=\",\"length\":5,\"file\":\"test.wpk\"}}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: '{\"error\":0,\"message\":\"ok\",\"data\": []}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, 0); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, 0); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - int res = wm_agent_upgrade_send_write(agent, format, wpk_file, file_path, chunk_size); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_write_err(void **state) -{ - (void) state; - - int socket = 555; - int agent = 39; - char *wpk_file = "test.wpk"; - char *file_path = "/var/upgrade/wazuh_agent.wpk"; - int chunk_size = 5; - char *chunk = "test\n"; - char *cmd = "039 com write 5 test.wpk test\n"; - char *agent_res1 = "ok "; - char *agent_res2 = "err Could not write file in agent"; - int format = -1; - - expect_string(__wrap_wfopen, path, file_path); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, chunk_size); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com write 5 test.wpk test\n'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res1) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res1); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - will_return(__wrap_fread, chunk); - will_return(__wrap_fread, chunk_size); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '039 com write 5 test.wpk test\n'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res2); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res2) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not write file in agent'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res2); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - int res = wm_agent_upgrade_send_write(agent, format, wpk_file, file_path, chunk_size); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_write_open_err(void **state) -{ - (void) state; - - int agent = 39; - char *wpk_file = "test.wpk"; - char *file_path = "/var/upgrade/wazuh_agent.wpk"; - int chunk_size = 5; - int format = -1; - - expect_string(__wrap_wfopen, path, file_path); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 0); - - int res = wm_agent_upgrade_send_write(agent, format, wpk_file, file_path, chunk_size); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_close_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent = 33; - char *wpk_file = "test.wpk"; - char *cmd = "033 com close test.wpk"; - char *agent_res = "ok "; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '033 com close test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - int res = wm_agent_upgrade_send_close(agent, format, wpk_file); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_close_ok_new(void **state) -{ - (void) state; - - int socket = 555; - int agent = 33; - char *wpk_file = "test.wpk"; - char *cmd = "033 upgrade {\"command\":\"close\",\"parameters\":{\"file\":\"test.wpk\"}}"; - char *agent_res = "{\"error\":0,\"message\":\"ok\",\"data\": []}"; - int format = 1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '033 upgrade {\"command\":\"close\",\"parameters\":{\"file\":\"test.wpk\"}}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: '{\"error\":0,\"message\":\"ok\",\"data\": []}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, 0); - - int res = wm_agent_upgrade_send_close(agent, format, wpk_file); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_close_err(void **state) -{ - (void) state; - - int socket = 555; - int agent = 33; - char *wpk_file = "test.wpk"; - char *cmd = "033 com close test.wpk"; - char *agent_res = "err Could not close file in agent"; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '033 com close test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not close file in agent'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_close(agent, format, wpk_file); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_sha1_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent = 33; - char *wpk_file = "test.wpk"; - char *file_sha1 = "d321af65983fa412e3a12c312ada12ab321a253a"; - char *cmd = "033 com sha1 test.wpk"; - char *agent_res = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '033 com sha1 test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a12c312ada12ab321a253a'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - int res = wm_agent_upgrade_send_sha1(agent, format, wpk_file, file_sha1); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_sha1_ok_new(void **state) -{ - (void) state; - - int socket = 555; - int agent = 33; - char *wpk_file = "test.wpk"; - char *file_sha1 = "d321af65983fa412e3a12c312ada12ab321a253a"; - char *cmd = "033 upgrade {\"command\":\"sha1\",\"parameters\":{\"file\":\"test.wpk\"}}"; - char *agent_res = "{\"error\":0,\"message\":\"d321af65983fa412e3a12c312ada12ab321a253a\",\"data\": []}"; - int format = 1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '033 upgrade {\"command\":\"sha1\",\"parameters\":{\"file\":\"test.wpk\"}}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: '{\"error\":0,\"message\":\"d321af65983fa412e3a12c312ada12ab321a253a\",\"data\": []}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, file_sha1); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, 0); - - int res = wm_agent_upgrade_send_sha1(agent, format, wpk_file, file_sha1); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_sha1_err(void **state) -{ - (void) state; - - int socket = 555; - int agent = 33; - char *wpk_file = "test.wpk"; - char *file_sha1 = "d321af65983fa412e3a12c312ada12ab321a253a"; - char *cmd = "033 com sha1 test.wpk"; - char *agent_res = "err Could not calculate sha1 in agent"; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '033 com sha1 test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not calculate sha1 in agent'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_sha1(agent, format, wpk_file, file_sha1); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_sha1_invalid_sha1(void **state) -{ - (void) state; - - int socket = 555; - int agent = 33; - char *wpk_file = "test.wpk"; - char *file_sha1 = "d321af65983fa412e3a12c312ada12ab321a253a"; - char *cmd = "033 com sha1 test.wpk"; - char *agent_res = "ok d321af65983fa412e3a21c312ada12ab321a253a"; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '033 com sha1 test.wpk'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a21c312ada12ab321a253a'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8118): The SHA1 of the file doesn't match in the agent."); - - int res = wm_agent_upgrade_send_sha1(agent, format, wpk_file, file_sha1); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_upgrade_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent = 55; - char *wpk_file = "test.wpk"; - char *installer = "install.sh"; - char *cmd = "055 com upgrade test.wpk install.sh"; - char *agent_res = "ok 0"; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '055 com upgrade test.wpk install.sh'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - int res = wm_agent_upgrade_send_upgrade(agent, format, wpk_file, installer); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_upgrade_ok_new(void **state) -{ - (void) state; - - int socket = 555; - int agent = 55; - char *wpk_file = "test.wpk"; - char *installer = "install.sh"; - char *cmd = "055 upgrade {\"command\":\"upgrade\",\"parameters\":{\"file\":\"test.wpk\",\"installer\":\"install.sh\"}}"; - char *agent_res = "{\"error\":0,\"message\":\"0\",\"data\": []}"; - int format = 1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '055 upgrade {\"command\":\"upgrade\",\"parameters\":{\"file\":\"test.wpk\",\"installer\":\"install.sh\"}}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: '{\"error\":0,\"message\":\"0\",\"data\": []}'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, "0"); - will_return(__wrap_wm_agent_upgrade_parse_agent_upgrade_command_response, 0); - - int res = wm_agent_upgrade_send_upgrade(agent, format, wpk_file, installer); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_upgrade_err(void **state) -{ - (void) state; - - int socket = 555; - int agent = 55; - char *wpk_file = "test.wpk"; - char *installer = "install.sh"; - char *cmd = "055 com upgrade test.wpk install.sh"; - char *agent_res = "err Could not run script in agent"; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '055 com upgrade test.wpk install.sh'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err Could not run script in agent'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_upgrade(agent, format, wpk_file, installer); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_upgrade_script_err(void **state) -{ - (void) state; - - int socket = 555; - int agent = 55; - char *wpk_file = "test.wpk"; - char *installer = "install.sh"; - char *cmd = "055 com upgrade test.wpk install.sh"; - char *agent_res = "ok 2"; - int format = -1; - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '055 com upgrade test.wpk install.sh'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(cmd)); - expect_string(__wrap_OS_SendSecureTCP, msg, cmd); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res) + 1); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 2'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8121): Script execution failed in the agent."); - - int res = wm_agent_upgrade_send_upgrade(agent, format, wpk_file, installer); - - assert_int_equal(res, OS_INVALID); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_linux_ok(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *close_file = "111 com close test.wpk"; - char *calculate_sha1 = "111 com sha1 test.wpk"; - char *run_upgrade = "111 com upgrade test.wpk upgrade.sh"; - char *agent_res_ok = "ok "; - char *agent_res_ok_0 = "ok 0"; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_0); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_0) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a12c312ada12ab321a253a'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com upgrade test.wpk upgrade.sh'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 6); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_windows_ok(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *close_file = "111 com close test.wpk"; - char *calculate_sha1 = "111 com sha1 test.wpk"; - char *run_upgrade = "111 com upgrade test.wpk upgrade.bat"; - char *agent_res_ok = "ok "; - char *agent_res_ok_0 = "ok 0"; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("windows", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_0); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_0) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a12c312ada12ab321a253a'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com upgrade test.wpk upgrade.bat'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 6); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_custom_custom_installer_ok(void **state) -{ - (void) state; - - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *close_file = "111 com close test.wpk"; - char *calculate_sha1 = "111 com sha1 test.wpk"; - char *run_upgrade = "111 com upgrade test.wpk test.sh"; - char *agent_res_ok = "ok "; - char *agent_res_ok_0 = "ok 0"; - char *agent_res_ok_sha1 = "ok 2c312ada12ab321a253ad321af65983fa412e3a1"; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - - config->chunk_size = 5; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE_CUSTOM; - upgrade_custom_task = wm_agent_upgrade_init_upgrade_custom_task(); - os_strdup("/tmp/test.wpk", upgrade_custom_task->custom_file_path); - os_strdup("test.sh", upgrade_custom_task->custom_installer); - agent_task->task_info->task = upgrade_custom_task; - - // wm_agent_upgrade_validate_wpk_custom - will_return(__wrap_wm_agent_upgrade_validate_wpk_custom, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string(__wrap_OS_SHA1_File, fname, "/tmp/test.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, "2c312ada12ab321a253ad321af65983fa412e3a1"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "/tmp/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_0); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_0) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 2c312ada12ab321a253ad321af65983fa412e3a1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com upgrade test.wpk test.sh'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 6); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_custom_default_installer_ok(void **state) -{ - (void) state; - - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *close_file = "111 com close test.wpk"; - char *calculate_sha1 = "111 com sha1 test.wpk"; - char *run_upgrade = "111 com upgrade test.wpk upgrade.sh"; - char *agent_res_ok = "ok "; - char *agent_res_ok_0 = "ok 0"; - char *agent_res_ok_sha1 = "ok 2c312ada12ab321a253ad321af65983fa412e3a1"; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - - config->chunk_size = 5; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE_CUSTOM; - upgrade_custom_task = wm_agent_upgrade_init_upgrade_custom_task(); - os_strdup("/tmp/test.wpk", upgrade_custom_task->custom_file_path); - agent_task->task_info->task = upgrade_custom_task; - - // wm_agent_upgrade_validate_wpk_custom - will_return(__wrap_wm_agent_upgrade_validate_wpk_custom, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string(__wrap_OS_SHA1_File, fname, "/tmp/test.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, "2c312ada12ab321a253ad321af65983fa412e3a1"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "/tmp/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_0); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_0) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 2c312ada12ab321a253ad321af65983fa412e3a1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com upgrade test.wpk upgrade.sh'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 6); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, 0); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_run_upgrade_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *close_file = "111 com close test.wpk"; - char *calculate_sha1 = "111 com sha1 test.wpk"; - char *run_upgrade = "111 com upgrade test.wpk upgrade.sh"; - char *agent_res_ok = "ok "; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - char *agent_res_err = "err "; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a12c312ada12ab321a253a'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com upgrade test.wpk upgrade.sh'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_err); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 5); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_SEND_UPGRADE_ERROR); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_send_sha1_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *close_file = "111 com close test.wpk"; - char *calculate_sha1 = "111 com sha1 test.wpk"; - char *agent_res_ok = "ok "; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a21c312ada12ab321a253a"; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 5); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 5); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 5); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 5); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8118): The SHA1 of the file doesn't match in the agent."); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 10); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a21c312ada12ab321a253a'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 5); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_SEND_SHA1_ERROR); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_close_file_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *close_file = "111 com close test.wpk"; - char *agent_res_ok = "ok "; - char *agent_res_err = "err "; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 4); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 4); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 4); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 4); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 8); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_err); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 3); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_SEND_CLOSE_ERROR); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_write_file_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *write_file = "111 com write 5 test.wpk test\n"; - char *agent_res_ok = "ok "; - char *agent_res_err = "err "; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 3); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 3); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 3); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 3); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 6); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_err); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 2); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_SEND_WRITE_ERROR); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_open_file_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *open_file = "111 com open wb test.wpk"; - char *agent_res_ok = "ok "; - char *agent_res_err = "err "; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 11); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 11); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 11); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 11); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value_count(__wrap_OS_SendSecureTCP, sock, socket, 10); - expect_value_count(__wrap_OS_SendSecureTCP, size, strlen(open_file), 10); - expect_string_count(__wrap_OS_SendSecureTCP, msg, open_file, 10); - will_return_count(__wrap_OS_SendSecureTCP, 0, 10); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 22); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string_count(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_err, 10); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, 0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID, 10); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_SEND_OPEN_ERROR); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_upgrade_lock_restart_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - char *lock_restart = "111 com lock_restart -1"; - char *agent_res_err = "err "; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '111'"); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 2); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '111 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_err); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_SEND_LOCK_RESTART_ERROR); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_validate_wpk_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - // wm_agent_upgrade_validate_wpk - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_WPK_SHA1_DOES_NOT_MATCH); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_WPK_SHA1_DOES_NOT_MATCH); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_validate_wpk_version_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - // wm_agent_upgrade_validate_wpk_version - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_WPK_VERSION_DOES_NOT_EXIST); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_WPK_VERSION_DOES_NOT_EXIST); -} - -void test_wm_agent_upgrade_send_wpk_to_agent_validate_wpk_custom_err(void **state) -{ - (void) state; - - wm_manager_configs *config = state[0]; - wm_agent_task *agent_task = state[1]; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - - config->chunk_size = 5; - - agent_task->agent_info->agent_id = 111; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE_CUSTOM; - upgrade_custom_task = wm_agent_upgrade_init_upgrade_custom_task(); - os_strdup("/tmp/test.wpk", upgrade_custom_task->custom_file_path); - os_strdup("test.sh", upgrade_custom_task->custom_installer); - agent_task->task_info->task = upgrade_custom_task; - - // wm_agent_upgrade_validate_wpk_custom - will_return(__wrap_wm_agent_upgrade_validate_wpk_custom, WM_UPGRADE_WPK_FILE_DOES_NOT_EXIST); - - int res = wm_agent_upgrade_send_wpk_to_agent(agent_task, config); - - assert_int_equal(res, WM_UPGRADE_WPK_FILE_DOES_NOT_EXIST); -} - -void test_wm_agent_upgrade_start_upgrade_upgrade_ok(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - int agent_id = 25; - char *status = "In progress"; - char *lock_restart = "025 com lock_restart -1"; - char *open_file = "025 com open wb test.wpk"; - char *write_file = "025 com write 5 test.wpk test\n"; - char *close_file = "025 com close test.wpk"; - char *calculate_sha1 = "025 com sha1 test.wpk"; - char *run_upgrade = "025 com upgrade test.wpk upgrade.sh"; - char *agent_res_ok = "ok "; - char *agent_res_ok_0 = "ok 0"; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - - test_upgrade_args *args = state[0]; - wm_manager_configs *config = args->config; - wm_agent_task *agent_task = args->agent_task; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = agent_id; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - cJSON *task_request_status = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(task_request_status, "origin", origin); - cJSON_AddStringToObject(task_request_status, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(agent_id)); - cJSON_AddItemToObject(parameters, "agents", agents); - cJSON_AddStringToObject(parameters, "status", status); - cJSON_AddItemToObject(task_request_status, "parameters", parameters); - - cJSON *task_response_status = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response_status, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response_status, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response_status, "agent", agent_id); - cJSON_AddStringToObject(task_response_status, "status", status); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, task_request_status); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, status); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, task_request_status, sizeof(task_request_status)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response_status); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_validate_task_status_message - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, task_response_status, sizeof(task_response_status)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent_id); - - // wm_agent_upgrade_send_wpk_to_agent - - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '025'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_0); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_0) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a12c312ada12ab321a253a'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com upgrade test.wpk upgrade.sh'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 6); - - wm_agent_upgrade_start_upgrade(args); - - int value = 0; - sem_getvalue(&upgrade_semaphore, &value); - - assert_int_equal(value, 6); -} - -void test_wm_agent_upgrade_start_upgrade_upgrade_legacy_ok(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - int agent_id = 25; - char *status1 = "In progress"; - char *status2 = "Legacy"; - char *lock_restart = "025 com lock_restart -1"; - char *open_file = "025 com open wb test.wpk"; - char *write_file = "025 com write 5 test.wpk test\n"; - char *close_file = "025 com close test.wpk"; - char *calculate_sha1 = "025 com sha1 test.wpk"; - char *run_upgrade = "025 com upgrade test.wpk upgrade.sh"; - char *agent_res_ok = "ok "; - char *agent_res_ok_0 = "ok 0"; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - - test_upgrade_args *args = state[0]; - wm_manager_configs *config = args->config; - wm_agent_task *agent_task = args->agent_task; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = agent_id; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - os_strdup("v3.13.1", upgrade_task->custom_version); - agent_task->task_info->task = upgrade_task; - - cJSON *task_request_status1 = cJSON_CreateObject(); - cJSON *origin1 = cJSON_CreateObject(); - cJSON *parameters1 = cJSON_CreateObject(); - cJSON *agents1 = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin1, "module", "upgrade_module"); - cJSON_AddItemToObject(task_request_status1, "origin", origin1); - cJSON_AddStringToObject(task_request_status1, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents1, cJSON_CreateNumber(agent_id)); - cJSON_AddItemToObject(parameters1, "agents", agents1); - cJSON_AddStringToObject(parameters1, "status", status1); - cJSON_AddItemToObject(task_request_status1, "parameters", parameters1); - - cJSON *task_response_status1 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response_status1, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response_status1, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response_status1, "agent", agent_id); - cJSON_AddStringToObject(task_response_status1, "status", status1); - - cJSON *task_request_status2 = cJSON_CreateObject(); - cJSON *origin2 = cJSON_CreateObject(); - cJSON *parameters2 = cJSON_CreateObject(); - cJSON *agents2 = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin2, "module", "upgrade_module"); - cJSON_AddItemToObject(task_request_status2, "origin", origin2); - cJSON_AddStringToObject(task_request_status2, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents2, cJSON_CreateNumber(agent_id)); - cJSON_AddItemToObject(parameters2, "agents", agents2); - cJSON_AddStringToObject(parameters2, "status", status2); - cJSON_AddItemToObject(task_request_status2, "parameters", parameters2); - - cJSON *task_response_status2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response_status2, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response_status2, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response_status2, "agent", agent_id); - cJSON_AddStringToObject(task_response_status2, "status", status2); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, task_request_status1); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, status1); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, task_request_status1, sizeof(task_request_status1)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response_status1); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_validate_task_status_message - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, task_response_status1, sizeof(task_response_status1)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent_id); - - // wm_agent_upgrade_send_wpk_to_agent - - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '025'"); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "var/upgrade/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_0); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_0) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a12c312ada12ab321a253a'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com upgrade test.wpk upgrade.sh'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 6); - - // compare_wazuh_versions - - expect_string(__wrap_compare_wazuh_versions, version1, "v3.13.1"); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, task_request_status2); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, status2); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, task_request_status2, sizeof(task_request_status2)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response_status2); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_validate_task_status_message - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, task_response_status2, sizeof(task_response_status2)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent_id); - - wm_agent_upgrade_start_upgrade(args); - - int value = 0; - sem_getvalue(&upgrade_semaphore, &value); - - assert_int_equal(value, 6); -} - -void test_wm_agent_upgrade_start_upgrade_upgrade_custom_ok(void **state) -{ - (void) state; - - int socket = 555; - int agent_id = 25; - char *status = "In progress"; - - char *lock_restart = "025 com lock_restart -1"; - char *open_file = "025 com open wb test.wpk"; - char *write_file = "025 com write 5 test.wpk test\n"; - char *close_file = "025 com close test.wpk"; - char *calculate_sha1 = "025 com sha1 test.wpk"; - char *run_upgrade = "025 com upgrade test.wpk upgrade.sh"; - char *agent_res_ok = "ok "; - char *agent_res_ok_0 = "ok 0"; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - - test_upgrade_args *args = state[0]; - wm_manager_configs *config = args->config; - wm_agent_task *agent_task = args->agent_task; - wm_upgrade_custom_task *upgrade_custom_task = NULL; - - config->chunk_size = 5; - - agent_task->agent_info->agent_id = agent_id; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE_CUSTOM; - upgrade_custom_task = wm_agent_upgrade_init_upgrade_custom_task(); - os_strdup("/tmp/test.wpk", upgrade_custom_task->custom_file_path); - agent_task->task_info->task = upgrade_custom_task; - - cJSON *task_request_status = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - cJSON_AddItemToObject(task_request_status, "origin", origin); - cJSON_AddStringToObject(task_request_status, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(agent_id)); - cJSON_AddItemToObject(parameters, "agents", agents); - cJSON_AddStringToObject(parameters, "status", status); - cJSON_AddItemToObject(task_request_status, "parameters", parameters); - - cJSON *task_response_status = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response_status, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response_status, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response_status, "agent", agent_id); - cJSON_AddStringToObject(task_response_status, "status", status); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, task_request_status); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, status); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, task_request_status, sizeof(task_request_status)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response_status); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_validate_task_status_message - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, task_response_status, sizeof(task_response_status)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent_id); - - // wm_agent_upgrade_send_wpk_to_agent - - will_return(__wrap_wm_agent_upgrade_validate_wpk_custom, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '025'"); - - expect_string(__wrap_OS_SHA1_File, fname, "/tmp/test.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, "d321af65983fa412e3a12c312ada12ab321a253a"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_string_count(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM, 6); - expect_value_count(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR, 6); - will_return_count(__wrap_OS_ConnectUnixDomain, socket, 6); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - // Open file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(open_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, open_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Write file - - expect_string(__wrap_wfopen, path, "/tmp/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, config->chunk_size); - - will_return(__wrap_fread, "test\n"); - will_return(__wrap_fread, 0); - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(write_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, write_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - // Close file - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(close_file)); - expect_string(__wrap_OS_SendSecureTCP, msg, close_file); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok) + 1); - - // Calculate file sha1 - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(calculate_sha1)); - expect_string(__wrap_OS_SendSecureTCP, msg, calculate_sha1); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_sha1); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_sha1) + 1); - - // Run upgrade script - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(run_upgrade)); - expect_string(__wrap_OS_SendSecureTCP, msg, run_upgrade); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_ok_0); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_ok_0) + 1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 12); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com open wb test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com write 5 test.wpk test\n'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com close test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok '"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com sha1 test.wpk'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok d321af65983fa412e3a12c312ada12ab321a253a'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com upgrade test.wpk upgrade.sh'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'ok 0'"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_sha1); - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_ok_0); - will_return_count(__wrap_wm_agent_upgrade_parse_agent_response, 0, 6); - - wm_agent_upgrade_start_upgrade(args); - - int value = 0; - sem_getvalue(&upgrade_semaphore, &value); - - assert_int_equal(value, 6); -} - -void test_wm_agent_upgrade_start_upgrade_upgrade_err(void **state) -{ - (void) state; - - char repository[OS_BUFFER_SIZE] = ""; - int socket = 555; - int agent_id = 25; - char *status1 = "In progress"; - char *status2 = "Failed"; - char *error = "Send lock restart error"; - char *lock_restart = "025 com lock_restart -1"; - char *open_file = "025 com open wb test.wpk"; - char *write_file = "025 com write 5 test.wpk test\n"; - char *close_file = "025 com close test.wpk"; - char *calculate_sha1 = "025 com sha1 test.wpk"; - char *run_upgrade = "025 com upgrade test.wpk upgrade.sh"; - char *agent_res_err = "err "; - char *agent_res_ok_sha1 = "ok d321af65983fa412e3a12c312ada12ab321a253a"; - - test_upgrade_args *args = state[0]; - wm_manager_configs *config = args->config; - wm_agent_task *agent_task = args->agent_task; - wm_upgrade_task *upgrade_task = NULL; - - config->chunk_size = 5; - snprintf(repository, OS_BUFFER_SIZE-1, WM_UPGRADE_WPK_REPO_URL, 4); - config->wpk_repository = repository; - - agent_task->agent_info->agent_id = agent_id; - os_strdup("ubuntu", agent_task->agent_info->platform); - os_strdup("v3.13.0", agent_task->agent_info->wazuh_version); - agent_task->task_info->command = WM_UPGRADE_UPGRADE; - upgrade_task = wm_agent_upgrade_init_upgrade_task(); - os_strdup("test.wpk", upgrade_task->wpk_file); - os_strdup("d321af65983fa412e3a12c312ada12ab321a253a", upgrade_task->wpk_sha1); - agent_task->task_info->task = upgrade_task; - - cJSON *task_request_status1 = cJSON_CreateObject(); - cJSON *origin1 = cJSON_CreateObject(); - cJSON *parameters1 = cJSON_CreateObject(); - cJSON *agents1 = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin1, "module", "upgrade_module"); - cJSON_AddItemToObject(task_request_status1, "origin", origin1); - cJSON_AddStringToObject(task_request_status1, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents1, cJSON_CreateNumber(agent_id)); - cJSON_AddItemToObject(parameters1, "agents", agents1); - cJSON_AddStringToObject(parameters1, "status", status1); - cJSON_AddItemToObject(task_request_status1, "parameters", parameters1); - - cJSON *task_response_status1 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response_status1, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response_status1, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response_status1, "agent", agent_id); - cJSON_AddStringToObject(task_response_status1, "status", status1); - - cJSON *task_request_status2 = cJSON_CreateObject(); - cJSON *origin2 = cJSON_CreateObject(); - cJSON *parameters2 = cJSON_CreateObject(); - cJSON *agents2 = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin2, "module", "upgrade_module"); - cJSON_AddItemToObject(task_request_status2, "origin", origin2); - cJSON_AddStringToObject(task_request_status2, "command", "upgrade_update_status"); - cJSON_AddItemToArray(agents2, cJSON_CreateNumber(agent_id)); - cJSON_AddItemToObject(parameters2, "agents", agents2); - cJSON_AddStringToObject(parameters2, "status", status2); - cJSON_AddItemToObject(task_request_status2, "parameters", parameters2); - - cJSON *task_response_status2 = cJSON_CreateObject(); - - cJSON_AddStringToObject(task_response_status2, "error", WM_UPGRADE_SUCCESS); - cJSON_AddStringToObject(task_response_status2, "message", upgrade_error_codes[WM_UPGRADE_SUCCESS]); - cJSON_AddNumberToObject(task_response_status2, "agent", agent_id); - cJSON_AddStringToObject(task_response_status2, "status", status2); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, task_request_status1); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, status1); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, task_request_status1, sizeof(task_request_status1)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response_status1); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_validate_task_status_message - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, task_response_status1, sizeof(task_response_status1)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent_id); - - // wm_agent_upgrade_send_wpk_to_agent - - expect_string(__wrap_wm_agent_upgrade_validate_wpk_version, wpk_repository_config, repository); - will_return(__wrap_wm_agent_upgrade_validate_wpk_version, WM_UPGRADE_SUCCESS); - - will_return(__wrap_wm_agent_upgrade_validate_wpk, WM_UPGRADE_SUCCESS); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8162): Sending WPK to agent: '025'"); - - expect_string(__wrap_OS_ConnectUnixDomain, path, REMOTE_LOCAL_SOCK); - expect_value(__wrap_OS_ConnectUnixDomain, type, SOCK_STREAM); - expect_value(__wrap_OS_ConnectUnixDomain, max_msg_size, OS_MAXSTR); - will_return(__wrap_OS_ConnectUnixDomain, socket); - - // Lock restart - - expect_value(__wrap_OS_SendSecureTCP, sock, socket); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(lock_restart)); - expect_string(__wrap_OS_SendSecureTCP, msg, lock_restart); - will_return(__wrap_OS_SendSecureTCP, 0); - - expect_value(__wrap_OS_RecvSecureTCP, sock, socket); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, agent_res_err); - will_return(__wrap_OS_RecvSecureTCP, strlen(agent_res_err) + 1); - - // Format - - expect_string(__wrap_compare_wazuh_versions, version1, agent_task->agent_info->wazuh_version); - expect_string(__wrap_compare_wazuh_versions, version2, WM_UPGRADE_NEW_UPGRADE_MECHANISM); - expect_value(__wrap_compare_wazuh_versions, compare_patch, 1); - will_return(__wrap_compare_wazuh_versions, -1); - - expect_string_count(__wrap__mtdebug2, tag, "wazuh-modulesd:agent-upgrade", 2); - expect_string(__wrap__mtdebug2, formatted_msg, "(8165): Sending message to agent: '025 com lock_restart -1'"); - expect_string(__wrap__mtdebug2, formatted_msg, "(8166): Receiving message from agent: 'err '"); - - expect_string(__wrap_wm_agent_upgrade_parse_agent_response, agent_response, agent_res_err); - will_return(__wrap_wm_agent_upgrade_parse_agent_response, OS_INVALID); - - // wm_agent_upgrade_parse_task_module_request - - expect_value(__wrap_wm_agent_upgrade_parse_task_module_request, command, WM_UPGRADE_AGENT_UPDATE_STATUS); - will_return(__wrap_wm_agent_upgrade_parse_task_module_request, task_request_status2); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, status, status2); - expect_string(__wrap_wm_agent_upgrade_parse_task_module_request, error, error); - - // wm_agent_upgrade_task_module_callback - - expect_memory(__wrap_wm_agent_upgrade_task_module_callback, task_module_request, task_request_status2, sizeof(task_request_status2)); - will_return(__wrap_wm_agent_upgrade_task_module_callback, task_response_status2); - will_return(__wrap_wm_agent_upgrade_task_module_callback, 0); - - // wm_agent_upgrade_validate_task_status_message - - expect_memory(__wrap_wm_agent_upgrade_validate_task_status_message, input_json, task_response_status2, sizeof(task_response_status2)); - will_return(__wrap_wm_agent_upgrade_validate_task_status_message, agent_id); - - wm_agent_upgrade_start_upgrade(args); - - int value = 0; - sem_getvalue(&upgrade_semaphore, &value); - - assert_int_equal(value, 6); -} - -void test_wm_agent_upgrade_dispatch_upgrades(void **state) { - wm_manager_configs *config = *state; - - config->max_threads = 8; - - wm_agent_task *agent_task_next = NULL; - wm_upgrade_task *upgrade_task_next = NULL; - - wm_agent_task *agent_task = wm_agent_upgrade_init_agent_task(); - - config->chunk_size = 5; - - linked_queue_push(upgrade_queue, agent_task); - - will_return(__wrap_linked_queue_pop_ex, 1); - expect_memory(__wrap_linked_queue_pop_ex, queue, upgrade_queue, sizeof(upgrade_queue)); - - expect_memory(__wrap_CreateThread, function_pointer, wm_agent_upgrade_start_upgrade, sizeof(wm_agent_upgrade_start_upgrade)); - expect_memory(__wrap_CreateThread, agent_task, agent_task, sizeof(agent_task)); - expect_memory(__wrap_CreateThread, config, config, sizeof(config)); - - wm_agent_upgrade_dispatch_upgrades(config); - - int value = 0; - sem_getvalue(&upgrade_semaphore, &value); - - assert_int_equal(value, 7); -} - -void test_wm_agent_upgrade_prepare_upgrades_ok(void **state) { - OSHashNode *node = *state; - wm_agent_task *agent_task = node->data; - wm_upgrade_task *upgrade_task = NULL; - - os_strdup("025", node->key); - - will_return(__wrap_wm_agent_upgrade_get_first_node, 1); - will_return(__wrap_wm_agent_upgrade_get_first_node, node); - - will_return(__wrap_wm_agent_upgrade_get_next_node, 1); - will_return(__wrap_wm_agent_upgrade_get_next_node, NULL); - - expect_memory(__wrap_linked_queue_push_ex, queue, upgrade_queue, sizeof(upgrade_queue)); - expect_memory(__wrap_linked_queue_push_ex, data, agent_task, sizeof(agent_task)); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 25); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 0); - will_return(__wrap_wm_agent_upgrade_remove_entry, 1); - - wm_agent_upgrade_prepare_upgrades(); -} - -void test_wm_agent_upgrade_prepare_upgrades_multiple(void **state) { - OSHashNode *node = *state; - wm_agent_task *agent_task = node->data; - wm_upgrade_task *upgrade_task = NULL; - - OSHashNode *node_next = node->next; - wm_agent_task *agent_task_next = node_next->data; - wm_upgrade_task *upgrade_task_next = NULL; - - os_strdup("025", node->key); - - os_strdup("035", node_next->key); - - will_return(__wrap_wm_agent_upgrade_get_first_node, 1); - will_return(__wrap_wm_agent_upgrade_get_first_node, node); - - will_return(__wrap_wm_agent_upgrade_get_next_node, 1); - will_return(__wrap_wm_agent_upgrade_get_next_node, node_next); - - expect_memory(__wrap_linked_queue_push_ex, queue, upgrade_queue, sizeof(upgrade_queue)); - expect_memory(__wrap_linked_queue_push_ex, data, agent_task, sizeof(agent_task)); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 25); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 0); - will_return(__wrap_wm_agent_upgrade_remove_entry, 1); - - will_return(__wrap_wm_agent_upgrade_get_next_node, 1); - will_return(__wrap_wm_agent_upgrade_get_next_node, NULL); - - expect_memory(__wrap_linked_queue_push_ex, queue, upgrade_queue, sizeof(upgrade_queue)); - expect_memory(__wrap_linked_queue_push_ex, data, agent_task_next, sizeof(agent_task_next)); - - expect_value(__wrap_wm_agent_upgrade_remove_entry, agent_id, 35); - expect_value(__wrap_wm_agent_upgrade_remove_entry, free, 0); - will_return(__wrap_wm_agent_upgrade_remove_entry, 1); - - wm_agent_upgrade_prepare_upgrades(); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_send_command_to_agent - cmocka_unit_test_teardown(test_wm_agent_upgrade_send_command_to_agent_ok, teardown_string), - cmocka_unit_test_teardown(test_wm_agent_upgrade_send_command_to_agent_recv_error, teardown_string), - cmocka_unit_test_teardown(test_wm_agent_upgrade_send_command_to_agent_sockterr_error, teardown_string), - cmocka_unit_test_teardown(test_wm_agent_upgrade_send_command_to_agent_connect_error, teardown_string), - // wm_agent_upgrade_send_lock_restart - cmocka_unit_test(test_wm_agent_upgrade_send_lock_restart_ok), - cmocka_unit_test(test_wm_agent_upgrade_send_lock_restart_err), - // wm_agent_upgrade_send_open - cmocka_unit_test(test_wm_agent_upgrade_send_open_ok), - cmocka_unit_test(test_wm_agent_upgrade_send_open_ok_new), - cmocka_unit_test(test_wm_agent_upgrade_send_open_retry_ok), - cmocka_unit_test(test_wm_agent_upgrade_send_open_retry_err), - // wm_agent_upgrade_send_write - cmocka_unit_test(test_wm_agent_upgrade_send_write_ok), - cmocka_unit_test(test_wm_agent_upgrade_send_write_ok_new), - cmocka_unit_test(test_wm_agent_upgrade_send_write_err), - cmocka_unit_test(test_wm_agent_upgrade_send_write_open_err), - // wm_agent_upgrade_send_close - cmocka_unit_test(test_wm_agent_upgrade_send_close_ok), - cmocka_unit_test(test_wm_agent_upgrade_send_close_ok_new), - cmocka_unit_test(test_wm_agent_upgrade_send_close_err), - // wm_agent_upgrade_send_sha1 - cmocka_unit_test(test_wm_agent_upgrade_send_sha1_ok), - cmocka_unit_test(test_wm_agent_upgrade_send_sha1_ok_new), - cmocka_unit_test(test_wm_agent_upgrade_send_sha1_err), - cmocka_unit_test(test_wm_agent_upgrade_send_sha1_invalid_sha1), - // wm_agent_upgrade_send_upgrade - cmocka_unit_test(test_wm_agent_upgrade_send_upgrade_ok), - cmocka_unit_test(test_wm_agent_upgrade_send_upgrade_ok_new), - cmocka_unit_test(test_wm_agent_upgrade_send_upgrade_err), - cmocka_unit_test(test_wm_agent_upgrade_send_upgrade_script_err), - // wm_agent_upgrade_send_wpk_to_agent - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_linux_ok, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_windows_ok, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_custom_custom_installer_ok, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_custom_default_installer_ok, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_run_upgrade_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_send_sha1_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_close_file_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_write_file_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_open_file_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_upgrade_lock_restart_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_validate_wpk_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_validate_wpk_version_err, setup_config_agent_task, teardown_config_agent_task), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_send_wpk_to_agent_validate_wpk_custom_err, setup_config_agent_task, teardown_config_agent_task), - // wm_agent_upgrade_start_upgrade - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_start_upgrade_upgrade_ok, setup_upgrade_args, teardown_upgrade_args), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_start_upgrade_upgrade_legacy_ok, setup_upgrade_args, teardown_upgrade_args), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_start_upgrade_upgrade_custom_ok, setup_upgrade_args, teardown_upgrade_args), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_start_upgrade_upgrade_err, setup_upgrade_args, teardown_upgrade_args), - // wm_agent_upgrade_dispatch_upgrades - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_dispatch_upgrades, setup_config, teardown_config), - // wm_agent_upgrade_prepare_upgrades - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_prepare_upgrades_ok, setup_nodes, teardown_nodes), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_prepare_upgrades_multiple, setup_nodes, teardown_nodes), - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_validate.c b/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_validate.c deleted file mode 100644 index 98a2610a89a..00000000000 --- a/src/unit_tests/wazuh_modules/agent_upgrade/test_wm_agent_upgrade_validate.c +++ /dev/null @@ -1,1833 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/shared/url_wrappers.h" -#include "../../wrappers/wazuh/os_crypto/sha1_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_agent_upgrade_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_validate.h" -#include "../../wazuh_modules/agent_upgrade/manager/wm_agent_upgrade_tasks.h" -#include "../../headers/shared.h" - -// Setup / teardown - -static int setup_validate_wpk_version(void **state) { - wm_agent_info *agent = NULL; - wm_upgrade_task *task = NULL; - agent = wm_agent_upgrade_init_agent_info(); - task = wm_agent_upgrade_init_upgrade_task(); - state[0] = (void *)agent; - state[1] = (void *)task; - return 0; -} - -static int teardown_validate_wpk_version(void **state) { - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - wm_agent_upgrade_free_agent_info(agent); - wm_agent_upgrade_free_upgrade_task(task); - return 0; -} - -static int setup_validate_wpk(void **state) { - wm_upgrade_task *task = NULL; - task = wm_agent_upgrade_init_upgrade_task(); - *state = (void *)task; - return 0; -} - -static int teardown_validate_wpk(void **state) { - wm_upgrade_task *task = *state; - wm_agent_upgrade_free_upgrade_task(task); - return 0; -} - -static int setup_validate_wpk_custom(void **state) { - wm_upgrade_custom_task *task = NULL; - task = wm_agent_upgrade_init_upgrade_custom_task(); - *state = (void *)task; - return 0; -} - -static int teardown_validate_wpk_custom(void **state) { - wm_upgrade_custom_task *task = *state; - wm_agent_upgrade_free_upgrade_custom_task(task); - return 0; -} - -static int teardown_validate_message(void **state) { - cJSON *response = state[0]; - char *data = state[1]; - cJSON_Delete(response); - os_free(data); - return 0; -} - -static int setup_group(void **state) { - test_mode = 1; - return 0; -} - -static int teardown_group(void **state) { - test_mode = 0; - return 0; -} - -// Tests - -void test_wm_agent_upgrade_validate_id_ok(void **state) -{ - (void) state; - int agent_id = 5; - - int ret = wm_agent_upgrade_validate_id(agent_id); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_id_manager(void **state) -{ - (void) state; - int agent_id = 0; - - int ret = wm_agent_upgrade_validate_id(agent_id); - - assert_int_equal(ret, WM_UPGRADE_INVALID_ACTION_FOR_MANAGER); -} - -void test_wm_agent_upgrade_validate_status_ok(void **state) -{ - (void) state; - const char *connection_status = AGENT_CS_ACTIVE; - - int ret = wm_agent_upgrade_validate_status(connection_status); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_status_null(void **state) -{ - (void) state; - const char *connection_status = NULL; - - int ret = wm_agent_upgrade_validate_status(connection_status); - - assert_int_equal(ret, WM_UPGRADE_AGENT_IS_NOT_ACTIVE); -} - -void test_wm_agent_upgrade_validate_status_disconnected(void **state) -{ - (void) state; - const char *connection_status = "disconnected"; - - int ret = wm_agent_upgrade_validate_status(connection_status); - - assert_int_equal(ret, WM_UPGRADE_AGENT_IS_NOT_ACTIVE); -} - -void test_wm_agent_upgrade_validate_system_windows_ok(void **state) -{ - (void) state; - char *platform = "windows"; - char *os_major = "10"; - char *os_minor = NULL; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_non_null(package_type); - assert_string_equal(package_type, "msi"); - os_free(package_type); -} - -void test_wm_agent_upgrade_validate_system_rhel_ok(void **state) -{ - (void) state; - char *platform = "rhel"; - char *os_major = "7"; - char *os_minor = NULL; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_non_null(package_type); - assert_string_equal(package_type, "rpm"); - os_free(package_type); -} - -void test_wm_agent_upgrade_validate_system_ubuntu_ok(void **state) -{ - (void) state; - char *platform = "ubuntu"; - char *os_major = "20"; - char *os_minor = "04"; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_non_null(package_type); - assert_string_equal(package_type, "deb"); - os_free(package_type); -} - -void test_wm_agent_upgrade_validate_system_darwin_x64_ok(void **state) -{ - (void) state; - char *platform = "darwin"; - char *os_major = "10"; - char *os_minor = "15"; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_non_null(package_type); - assert_string_equal(package_type, "pkg"); - os_free(package_type); -} - -void test_wm_agent_upgrade_validate_system_darwin_arm_ok(void **state) -{ - (void) state; - char *platform = "darwin"; - char *os_major = "10"; - char *os_minor = "15"; - char *arch = "arm64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_non_null(package_type); - assert_string_equal(package_type, "pkg"); - os_free(package_type); -} - -void test_wm_agent_upgrade_validate_system_invalid_platform_solaris(void **state) -{ - (void) state; - char *platform = "sunos"; - char *os_major = "11"; - char *os_minor = "4"; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SYSTEM_NOT_SUPPORTED); - assert_null(package_type); -} - -void test_wm_agent_upgrade_validate_system_invalid_platform_suse(void **state) -{ - (void) state; - char *platform = "sles"; - char *os_major = "11"; - char *os_minor = NULL; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SYSTEM_NOT_SUPPORTED); - assert_null(package_type); -} - -void test_wm_agent_upgrade_validate_system_invalid_platform_rhel(void **state) -{ - (void) state; - char *platform = "rhel"; - char *os_major = "5"; - char *os_minor = "7"; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SYSTEM_NOT_SUPPORTED); - assert_null(package_type); -} - -void test_wm_agent_upgrade_validate_system_invalid_platform_centos(void **state) -{ - (void) state; - char *platform = "centos"; - char *os_major = "5"; - char *os_minor = NULL; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SYSTEM_NOT_SUPPORTED); - assert_null(package_type); -} - -void test_wm_agent_upgrade_validate_system_invalid_arch(void **state) -{ - (void) state; - char *platform = "ubuntu"; - char *os_major = "18"; - char *os_minor = "04"; - char *arch = NULL; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_GLOBAL_DB_FAILURE); - assert_null(package_type); -} - -void test_wm_agent_upgrade_validate_system_rolling_opensuse(void **state) -{ - (void) state; - char *platform = "opensuse-tumbleweed"; - char *os_major = NULL; - char *os_minor = NULL; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_non_null(package_type); - assert_string_equal(package_type, "rpm"); - os_free(package_type); -} - -void test_wm_agent_upgrade_validate_system_rolling_archlinux(void **state) -{ - (void) state; - char *platform = "arch"; - char *os_major = NULL; - char *os_minor = NULL; - char *arch = "x64"; - char *package_type = NULL; - - int ret = wm_agent_upgrade_validate_system(platform, os_major, os_minor, arch, &package_type); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_null(package_type); // Not recognized -} - -void test_wm_agent_upgrade_validate_wpk_version_windows_https_ok(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("windows", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("x64", agent->architecture); - os_strdup("msi", agent->package_type); - - task->use_http = false; - os_strdup("v4.0.0", task->wpk_version); - - os_strdup("v3.13.1 4a313b1312c23a213f2e3209fe0909dd\nv4.0.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/windows/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/windows/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.0.0_windows.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_windows_http_ok(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("windows", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("x64", agent->architecture); - os_strdup("msi", agent->package_type); - - task->use_http = true; - os_strdup("v3.13.1", task->wpk_version); - - os_strdup("v3.13.1 4a313b1312c23a213f2e3209fe0909dd\nv4.0.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "http://packages.wazuh.com/wpk/windows/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "http://packages.wazuh.com/wpk/windows/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v3.13.1_windows.wpk"); - assert_string_equal(task->wpk_sha1, "4a313b1312c23a213f2e3209fe0909dd"); -} - - -void test_wm_agent_upgrade_validate_wpk_version_windows_invalid_version(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *repo = "packages.wazuh.com/4.x/wpk"; - char *versions = NULL; - - os_strdup("windows", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("x64", agent->architecture); - os_strdup("msi", agent->package_type); - - task->use_http = true; - os_strdup("v4.2.0", task->wpk_version); - - os_strdup("v3.13.1 4a313b1312c23a213f2e3209fe0909dd\nv4.0.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "http://packages.wazuh.com/4.x/wpk/windows/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, repo); - - assert_int_equal(ret, WM_UPGRADE_WPK_VERSION_DOES_NOT_EXIST); - assert_string_equal(task->wpk_repository, repo); - assert_null(task->wpk_file); - assert_null(task->wpk_sha1); -} - -void test_wm_agent_upgrade_validate_wpk_version_windows_invalid_repo(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *repo = "error.wazuh.com/wpk/"; - char *versions = NULL; - - os_strdup("windows", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("x64", agent->architecture); - os_strdup("msi", agent->package_type); - - task->use_http = true; - os_strdup("v4.2.0", task->wpk_version); - - expect_string(__wrap_wurl_http_get, url, "http://error.wazuh.com/wpk/windows/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, repo); - - assert_int_equal(ret, WM_UPGRADE_URL_NOT_FOUND); - assert_string_equal(task->wpk_repository, repo); - assert_null(task->wpk_file); - assert_null(task->wpk_sha1); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_https_ok(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = false; - os_strdup("v4.0.0", task->wpk_version); - - os_strdup("v3.13.1 4a313b1312c23a213f2e3209fe0909dd\nv4.0.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/x64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/x64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.0.0_linux_x64.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_http_ok(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = true; - os_strdup("v3.13.1", task->wpk_version); - - os_strdup("v3.13.1 4a313b1312c23a213f2e3209fe0909dd\nv4.0.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "http://packages.wazuh.com/wpk/linux/x64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "http://packages.wazuh.com/wpk/linux/x64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v3.13.1_linux_x64.wpk"); - assert_string_equal(task->wpk_sha1, "4a313b1312c23a213f2e3209fe0909dd"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_invalid_str_version(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = true; - os_strdup("v.4.1", task->wpk_version); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_WPK_VERSION_DOES_NOT_EXIST); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_invalid_version(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *repo = "packages.wazuh.com/4.x/wpk"; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = true; - os_strdup("v4.2.0", task->wpk_version); - - os_strdup("error\nerror\nerror", versions); - - expect_string(__wrap_wurl_http_get, url, "http://packages.wazuh.com/4.x/wpk/linux/x64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, repo); - - assert_int_equal(ret, WM_UPGRADE_WPK_VERSION_DOES_NOT_EXIST); - assert_string_equal(task->wpk_repository, repo); - assert_null(task->wpk_file); - assert_null(task->wpk_sha1); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_invalid_repo(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *repo = "error.wazuh.com/wpk/"; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = true; - os_strdup("v4.2.0", task->wpk_version); - - expect_string(__wrap_wurl_http_get, url, "http://error.wazuh.com/wpk/linux/x64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, repo); - - assert_int_equal(ret, WM_UPGRADE_URL_NOT_FOUND); - assert_string_equal(task->wpk_repository, repo); - assert_null(task->wpk_file); - assert_null(task->wpk_sha1); -} - -void test_wm_agent_upgrade_validate_wpk_version_ubuntu_old_version(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("16", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = false; - os_strdup("v3.3.0", task->wpk_version); - - os_strdup("v3.3.0 ad87687f6876e876876bb86ad54e57aa", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/wpk/ubuntu/16.04/x64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/wpk/ubuntu/16.04/x64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v3.3.0_ubuntu_16.04_x64.wpk"); - assert_string_equal(task->wpk_sha1, "ad87687f6876e876876bb86ad54e57aa"); -} - -void test_wm_agent_upgrade_validate_wpk_version_rhel_old_version(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("rhel", agent->platform); - os_strdup("6", agent->major_version); - os_strdup("x86", agent->architecture); - os_strdup("rpm", agent->package_type); - - task->use_http = false; - os_strdup("v3.3.0", task->wpk_version); - - os_strdup("v3.3.0 ad87687f6876e876876bb86ad54e57aa", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/wpk/rhel/6/x86/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/wpk/rhel/6/x86/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v3.3.0_rhel_6_x86.wpk"); - assert_string_equal(task->wpk_sha1, "ad87687f6876e876876bb86ad54e57aa"); -} - -void test_wm_agent_upgrade_validate_wpk_version_no_version(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *repo = "packages.wazuh.com/4.x/wpk"; - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, repo); - - assert_int_equal(ret, WM_UPGRADE_WPK_VERSION_DOES_NOT_EXIST); - assert_null(task->wpk_repository); - assert_null(task->wpk_file); - assert_null(task->wpk_sha1); -} - -void test_wm_agent_upgrade_validate_wpk_version_macos_https_ok(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("darwin", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("15", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("pkg", agent->package_type); - - task->use_http = false; - os_strdup("v4.0.0", task->wpk_version); - - os_strdup("v3.13.1 4a313b1312c23a213f2e3209fe0909dd\nv4.0.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/macos/x64/pkg/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/macos/x64/pkg/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.0.0_macos_x64.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_macos_http_ok(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("darwin", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("15", agent->minor_version); - os_strdup("x64", agent->architecture); - os_strdup("pkg", agent->package_type); - - task->use_http = true; - os_strdup("v3.13.1", task->wpk_version); - - os_strdup("v3.13.1 4a313b1312c23a213f2e3209fe0909dd\nv4.0.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "http://packages.wazuh.com/wpk/macos/x64/pkg/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "http://packages.wazuh.com/wpk/macos/x64/pkg/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v3.13.1_macos_x64.wpk"); - assert_string_equal(task->wpk_sha1, "4a313b1312c23a213f2e3209fe0909dd"); -} - -void test_wm_agent_upgrade_validate_wpk_version_macos_x86_64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("darwin", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("15", agent->minor_version); - os_strdup("x86_64", agent->architecture); - os_strdup("pkg", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/macos/pkg/intel64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/macos/pkg/intel64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_macos_intel64.pkg.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_macos_aarch64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("darwin", agent->platform); - os_strdup("10", agent->major_version); - os_strdup("15", agent->minor_version); - os_strdup("aarch64", agent->architecture); - os_strdup("pkg", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/macos/pkg/arm64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/macos/pkg/arm64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_macos_arm64.pkg.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_x86_64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("centos", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("x86_64", agent->architecture); - os_strdup("rpm", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_x86_64.rpm.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_aarch64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("centos", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("aarch64", agent->architecture); - os_strdup("rpm", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/rpm/aarch64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/rpm/aarch64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_aarch64.rpm.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_rpm(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("centos", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("x86_64", agent->architecture); - os_strdup("rpm", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("rpm", task->package_type); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_x86_64.rpm.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_deb(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("centos", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("x86_64", agent->architecture); - os_strdup("rpm", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("deb", task->package_type); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtwarn, formatted_msg, "(8169): Agent '0' with platform 'centos' won't be upgraded using package 'deb' without the force option. Ignoring..."); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_x86_64.rpm.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_deb_force(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("centos", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("x86_64", agent->architecture); - os_strdup("rpm", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("deb", task->package_type); - task->force_upgrade = true; - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8170): Agent '0' with platform 'centos' will be upgraded using package 'deb'"); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_amd64.deb.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_x86_64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x86_64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_amd64.deb.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_aarch64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("aarch64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/deb/arm64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/deb/arm64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_arm64.deb.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_deb(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x86_64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("deb", task->package_type); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_amd64.deb.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_rpm(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x86_64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("rpm", task->package_type); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtwarn, formatted_msg, "(8169): Agent '0' with platform 'ubuntu' won't be upgraded using package 'rpm' without the force option. Ignoring..."); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/deb/amd64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_amd64.deb.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_rpm_force(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("ubuntu", agent->platform); - os_strdup("18", agent->major_version); - os_strdup("04", agent->minor_version); - os_strdup("x86_64", agent->architecture); - os_strdup("deb", agent->package_type); - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("rpm", task->package_type); - task->force_upgrade = true; - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8170): Agent '0' with platform 'ubuntu' will be upgraded using package 'rpm'"); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/rpm/x86_64/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_x86_64.rpm.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_x86_64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - - os_strdup("unsupported", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("x86_64", agent->architecture); - agent->package_type = NULL; - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtwarn, formatted_msg, "(8171): Agent '0' with unsupported platform 'unsupported' won't be upgraded without a default package."); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SYSTEM_NOT_SUPPORTED); - assert_string_equal(task->wpk_repository, "packages.wazuh.com/4.x/wpk/"); - assert_null(task->wpk_file); - assert_null(task->wpk_sha1); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_aarch64(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - - os_strdup("unsupported", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("aarch64", agent->architecture); - agent->package_type = NULL; - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtwarn, formatted_msg, "(8171): Agent '0' with unsupported platform 'unsupported' won't be upgraded without a default package."); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SYSTEM_NOT_SUPPORTED); - assert_string_equal(task->wpk_repository, "packages.wazuh.com/4.x/wpk/"); - assert_null(task->wpk_file); - assert_null(task->wpk_sha1); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_rpm(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("unsupported", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("i386", agent->architecture); - agent->package_type = NULL; - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("rpm", task->package_type); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8172): Agent '0' with unsupported platform 'unsupported' will be upgraded with package 'rpm'"); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/rpm/i386/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/rpm/i386/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_i386.rpm.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_deb(void **state) -{ - wm_agent_info *agent = state[0]; - wm_upgrade_task *task = state[1]; - char *versions = NULL; - - os_strdup("unsupported", agent->platform); - os_strdup("8", agent->major_version); - os_strdup("i386", agent->architecture); - agent->package_type = NULL; - - task->use_http = false; - os_strdup("v4.9.0", task->wpk_version); - os_strdup("deb", task->package_type); - - os_strdup("v4.9.0 231ef123a32d312b4123c21313ee6780", versions); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8172): Agent '0' with unsupported platform 'unsupported' will be upgraded with package 'deb'"); - - expect_string(__wrap_wurl_http_get, url, "https://packages.wazuh.com/4.x/wpk/linux/deb/i386/versions"); - expect_value(__wrap_wurl_http_get, timeout, WM_UPGRADE_DEFAULT_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_get, versions); - - int ret = wm_agent_upgrade_validate_wpk_version(agent, task, NULL); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_repository, "https://packages.wazuh.com/4.x/wpk/linux/deb/i386/"); - assert_string_equal(task->wpk_file, "wazuh_agent_v4.9.0_linux_i386.deb.wpk"); - assert_string_equal(task->wpk_sha1, "231ef123a32d312b4123c21313ee6780"); -} - -void test_wm_agent_upgrade_validate_version_upgrade_ok(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v3.9.1"; - char *platform = "ubuntu"; - - task->force_upgrade = false; - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE, task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_version, "v3.13.0"); -} - -void test_wm_agent_upgrade_validate_version_upgrade_custom_ok(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v3.9.1"; - char *platform = "ubuntu"; - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE_CUSTOM, task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_version_upgrade_non_minimal(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v2.1.1"; - char *platform = "ubuntu"; - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE, task); - - assert_int_equal(ret, WM_UPGRADE_NOT_MINIMAL_VERSION_SUPPORTED); -} - -void test_wm_agent_upgrade_validate_version_upgrade_custom_non_minimal(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v2.1.1"; - char *platform = "ubuntu"; - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE_CUSTOM, task); - - assert_int_equal(ret, WM_UPGRADE_NOT_MINIMAL_VERSION_SUPPORTED); -} - -void test_wm_agent_upgrade_validate_version_upgrade_older_version(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v3.13.1"; - char *platform = "ubuntu"; - - task->force_upgrade = false; - os_strdup("v3.12.0", task->custom_version); - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE, task); - - assert_int_equal(ret, WM_UPGRADE_NEW_VERSION_LEES_OR_EQUAL_THAT_CURRENT); - assert_string_equal(task->wpk_version, "v3.12.0"); -} - -void test_wm_agent_upgrade_validate_version_upgrade_greater_version(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v3.9.1"; - char *platform = "ubuntu"; - - task->force_upgrade = false; - os_strdup("v3.13.1", task->custom_version); - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE, task); - - assert_int_equal(ret, WM_UPGRADE_NEW_VERSION_GREATER_MASTER); - assert_string_equal(task->wpk_version, "v3.13.1"); -} - -void test_wm_agent_upgrade_validate_version_upgrade_force(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v3.9.1"; - char *platform = "ubuntu"; - - task->force_upgrade = true; - os_strdup("v3.13.1", task->custom_version); - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE, task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_version, "v3.13.1"); -} - -void test_wm_agent_upgrade_validate_version_version_null(void **state) -{ - wm_upgrade_task *task = state[1]; - char *platform = "ubuntu"; - - int ret = wm_agent_upgrade_validate_version(NULL, platform, WM_UPGRADE_UPGRADE_CUSTOM, task); - - assert_int_equal(ret, WM_UPGRADE_GLOBAL_DB_FAILURE); -} - -void test_wm_agent_upgrade_validate_version_upgrade_ok_macos(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v4.3.0"; - char *platform = "darwin"; - - task->force_upgrade = true; - os_strdup("v4.3.0", task->custom_version); - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE, task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); - assert_string_equal(task->wpk_version, "v4.3.0"); -} - -void test_wm_agent_upgrade_validate_version_upgrade_non_minimal_macos(void **state) -{ - wm_upgrade_task *task = state[1]; - char *wazuh_version = "v4.2.0"; - char *platform = "darwin"; - - int ret = wm_agent_upgrade_validate_version(wazuh_version, platform, WM_UPGRADE_UPGRADE, task); - - assert_int_equal(ret, WM_UPGRADE_NOT_MINIMAL_VERSION_SUPPORTED); -} - -void test_wm_agent_upgrade_validate_wpk_exist(void **state) -{ - wm_upgrade_task *task = *state; - char *sha1 = "74691287f21a312ab2a12e31a23f21a33d242d52"; - - os_strdup("https://packages.wazuh.com/4.x/wpk/windows/", task->wpk_repository); - os_strdup("wazuh_agent_v4.0.0_windows.wpk", task->wpk_file); - os_strdup(sha1, task->wpk_sha1); - - expect_string(__wrap_wfopen, path, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - expect_string(__wrap_OS_SHA1_File, fname, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, sha1); - will_return(__wrap_OS_SHA1_File, 0); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - int ret = wm_agent_upgrade_validate_wpk(task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_wpk_exist_diff_sha1(void **state) -{ - wm_upgrade_task *task = *state; - char *sha1 = "74691287f21a312ab2a12e31a23f21a33d242d52"; - - os_strdup("https://packages.wazuh.com/4.x/wpk/windows/", task->wpk_repository); - os_strdup("wazuh_agent_v4.0.0_windows.wpk", task->wpk_file); - os_strdup(sha1, task->wpk_sha1); - - expect_string(__wrap_wfopen, path, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - expect_string(__wrap_OS_SHA1_File, fname, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File, 0); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8161): Downloading WPK file from: 'https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk'"); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 0); - - expect_string(__wrap_OS_SHA1_File, fname, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, sha1); - will_return(__wrap_OS_SHA1_File, 0); - - int ret = wm_agent_upgrade_validate_wpk(task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_wpk_download_retry(void **state) -{ - wm_upgrade_task *task = *state; - char *sha1 = "74691287f21a312ab2a12e31a23f21a33d242d52"; - - os_strdup("https://packages.wazuh.com/4.x/wpk/windows/", task->wpk_repository); - os_strdup("wazuh_agent_v4.0.0_windows.wpk", task->wpk_file); - os_strdup(sha1, task->wpk_sha1); - - expect_string(__wrap_wfopen, path, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8161): Downloading WPK file from: 'https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk'"); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 1); - - expect_value(__wrap_sleep, seconds, 1); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 0); - - expect_string(__wrap_OS_SHA1_File, fname, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, sha1); - will_return(__wrap_OS_SHA1_File, 0); - - int ret = wm_agent_upgrade_validate_wpk(task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_wpk_download_diff_sha1(void **state) -{ - wm_upgrade_task *task = *state; - char *sha1 = "74691287f21a312ab2a12e31a23f21a33d242d52"; - - os_strdup("https://packages.wazuh.com/4.x/wpk/windows/", task->wpk_repository); - os_strdup("wazuh_agent_v4.0.0_windows.wpk", task->wpk_file); - os_strdup(sha1, task->wpk_sha1); - - expect_string(__wrap_wfopen, path, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8161): Downloading WPK file from: 'https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk'"); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 0); - - expect_string(__wrap_OS_SHA1_File, fname, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_OS_SHA1_File, mode, OS_BINARY); - will_return(__wrap_OS_SHA1_File, "32bb98743e298dee0a654a654765c765d765ae80"); - will_return(__wrap_OS_SHA1_File, 0); - - int ret = wm_agent_upgrade_validate_wpk(task); - - assert_int_equal(ret, WM_UPGRADE_WPK_SHA1_DOES_NOT_MATCH); -} - -void test_wm_agent_upgrade_validate_wpk_download_retry_max(void **state) -{ - wm_upgrade_task *task = *state; - char *sha1 = "74691287f21a312ab2a12e31a23f21a33d242d52"; - - os_strdup("https://packages.wazuh.com/4.x/wpk/windows/", task->wpk_repository); - os_strdup("wazuh_agent_v4.0.0_windows.wpk", task->wpk_file); - os_strdup(sha1, task->wpk_sha1); - - expect_string(__wrap_wfopen, path, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8161): Downloading WPK file from: 'https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk'"); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 1); - - expect_value(__wrap_sleep, seconds, 1); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 1); - - expect_value(__wrap_sleep, seconds, 2); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 1); - - expect_value(__wrap_sleep, seconds, 3); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 1); - - expect_value(__wrap_sleep, seconds, 4); - - expect_string(__wrap_wurl_request, url, "https://packages.wazuh.com/4.x/wpk/windows/wazuh_agent_v4.0.0_windows.wpk"); - expect_string(__wrap_wurl_request, dest, "var/upgrade/wazuh_agent_v4.0.0_windows.wpk"); - expect_value(__wrap_wurl_request, timeout, WM_UPGRADE_WPK_DOWNLOAD_TIMEOUT); - will_return(__wrap_wurl_request, 1); - - int ret = wm_agent_upgrade_validate_wpk(task); - - assert_int_equal(ret, WM_UPGRADE_WPK_FILE_DOES_NOT_EXIST); -} - -void test_wm_agent_upgrade_validate_wpk_task_error(void **state) -{ - wm_upgrade_task *task = *state; - - int ret = wm_agent_upgrade_validate_wpk(task); - - assert_int_equal(ret, WM_UPGRADE_WPK_FILE_DOES_NOT_EXIST); -} - -void test_wm_agent_upgrade_validate_wpk_custom_exist(void **state) -{ - wm_upgrade_custom_task *task = *state; - - os_strdup("/tmp/test.wpk", task->custom_file_path); - - expect_string(__wrap_wfopen, path, "/tmp/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 1); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - int ret = wm_agent_upgrade_validate_wpk_custom(task); - - assert_int_equal(ret, WM_UPGRADE_SUCCESS); -} - -void test_wm_agent_upgrade_validate_wpk_custom_not_exist(void **state) -{ - wm_upgrade_custom_task *task = *state; - - os_strdup("/tmp/test.wpk", task->custom_file_path); - - expect_string(__wrap_wfopen, path, "/tmp/test.wpk"); - expect_string(__wrap_wfopen, mode, "rb"); - will_return(__wrap_wfopen, 0); - - int ret = wm_agent_upgrade_validate_wpk_custom(task); - - assert_int_equal(ret, WM_UPGRADE_WPK_FILE_DOES_NOT_EXIST); -} - -void test_wm_agent_upgrade_validate_wpk_custom_task_error(void **state) -{ - wm_upgrade_custom_task *task = *state; - - int ret = wm_agent_upgrade_validate_wpk_custom(task); - - assert_int_equal(ret, WM_UPGRADE_WPK_FILE_DOES_NOT_EXIST); -} - -void test_wm_agent_upgrade_validate_task_status_message_ok(void **state) -{ - cJSON *response = cJSON_CreateObject(); - char *status = NULL; - int agent_id = 0; - - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddStringToObject(response, "message", "Success"); - cJSON_AddNumberToObject(response, "agent", 5); - cJSON_AddStringToObject(response, "status", "Done"); - - int ret = wm_agent_upgrade_validate_task_status_message(response, &status, &agent_id); - - state[0] = (void *)response; - state[1] = (void *)status; - - assert_int_equal(ret, true); - assert_string_equal(status, "Done"); - assert_int_equal(agent_id, 5); -} - -void test_wm_agent_upgrade_validate_task_status_message_not_agent_status_ok(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddStringToObject(response, "message", "Success"); - cJSON_AddNumberToObject(response, "agent", 5); - cJSON_AddStringToObject(response, "status", "Done"); - - int ret = wm_agent_upgrade_validate_task_status_message(response, NULL, NULL); - - state[0] = (void *)response; - - assert_int_equal(ret, true); -} - -void test_wm_agent_upgrade_validate_task_status_message_error_code(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - cJSON_AddNumberToObject(response, "error", 1); - cJSON_AddStringToObject(response, "message", "Error"); - cJSON_AddNumberToObject(response, "agent", 5); - cJSON_AddStringToObject(response, "status", "Done"); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8119): There has been an error updating task state. Error code: '1', message: 'Error'"); - - int ret = wm_agent_upgrade_validate_task_status_message(response, NULL, NULL); - - state[0] = (void *)response; - - assert_int_equal(ret, false); -} - -void test_wm_agent_upgrade_validate_task_status_message_invalid_json(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:agent-upgrade"); - expect_string(__wrap__mterror, formatted_msg, "(8107): Required parameters in message are missing."); - - int ret = wm_agent_upgrade_validate_task_status_message(response, NULL, NULL); - - state[0] = (void *)response; - - assert_int_equal(ret, false); -} - -void test_wm_agent_upgrade_validate_task_status_message_null_json(void **state) -{ - int ret = wm_agent_upgrade_validate_task_status_message(NULL, NULL, NULL); - - assert_int_equal(ret, false); -} - -void test_wm_agent_upgrade_validate_task_ids_message_ok(void **state) -{ - cJSON *response = cJSON_CreateObject(); - int agent_id = 0; - int task_id = 0; - char *data = NULL; - - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddStringToObject(response, "message", "Success"); - cJSON_AddNumberToObject(response, "agent", 7); - cJSON_AddNumberToObject(response, "task_id", 15); - - int ret = wm_agent_upgrade_validate_task_ids_message(response, &agent_id, &task_id, &data); - - state[0] = (void *)response; - state[1] = (void *)data; - - assert_int_equal(ret, true); - assert_int_equal(agent_id, 7); - assert_int_equal(task_id, 15); - assert_string_equal(data, "Success"); -} - -void test_wm_agent_upgrade_validate_task_ids_message_not_agent_error(void **state) -{ - cJSON *response = cJSON_CreateObject(); - int task_id = 0; - char *data = NULL; - - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddStringToObject(response, "message", "Success"); - cJSON_AddNumberToObject(response, "agent", 7); - cJSON_AddNumberToObject(response, "task_id", 15); - - int ret = wm_agent_upgrade_validate_task_ids_message(response, NULL, &task_id, &data); - - state[0] = (void *)response; - - assert_int_equal(ret, false); - assert_int_equal(task_id, 0); - assert_null(data); -} - -void test_wm_agent_upgrade_validate_task_ids_message_not_data_error(void **state) -{ - cJSON *response = cJSON_CreateObject(); - int agent_id = 0; - int task_id = 0; - - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddStringToObject(response, "message", "Success"); - cJSON_AddNumberToObject(response, "agent", 7); - cJSON_AddNumberToObject(response, "task_id", 15); - - int ret = wm_agent_upgrade_validate_task_ids_message(response, &agent_id, &task_id, NULL); - - state[0] = (void *)response; - - assert_int_equal(ret, false); - assert_int_equal(agent_id, 7); - assert_int_equal(task_id, 0); -} - -void test_wm_agent_upgrade_validate_task_ids_message_not_task_ok(void **state) -{ - cJSON *response = cJSON_CreateObject(); - int agent_id = 0; - char *data = NULL; - - cJSON_AddNumberToObject(response, "error", 0); - cJSON_AddStringToObject(response, "message", "Success"); - cJSON_AddNumberToObject(response, "agent", 7); - cJSON_AddNumberToObject(response, "task_id", 15); - - int ret = wm_agent_upgrade_validate_task_ids_message(response, &agent_id, NULL, &data); - - state[0] = (void *)response; - state[1] = (void *)data; - - assert_int_equal(ret, true); - assert_int_equal(agent_id, 7); - assert_string_equal(data, "Success"); -} - -void test_wm_agent_upgrade_validate_task_ids_message_invalid_json(void **state) -{ - cJSON *response = cJSON_CreateObject(); - int agent_id = 0; - int task_id = 0; - char *data = NULL; - - int ret = wm_agent_upgrade_validate_task_ids_message(response, &agent_id, &task_id, &data); - - state[0] = (void *)response; - - assert_int_equal(ret, false); - assert_int_equal(agent_id, 0); - assert_int_equal(task_id, 0); - assert_null(data); -} - -void test_wm_agent_upgrade_validate_task_ids_message_null_json(void **state) -{ - int ret = wm_agent_upgrade_validate_task_ids_message(NULL, NULL, NULL, NULL); - - assert_int_equal(ret, false); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_agent_upgrade_validate_id - cmocka_unit_test(test_wm_agent_upgrade_validate_id_ok), - cmocka_unit_test(test_wm_agent_upgrade_validate_id_manager), - // wm_agent_upgrade_validate_status - cmocka_unit_test(test_wm_agent_upgrade_validate_status_ok), - cmocka_unit_test(test_wm_agent_upgrade_validate_status_null), - cmocka_unit_test(test_wm_agent_upgrade_validate_status_disconnected), - // wm_agent_upgrade_validate_system - cmocka_unit_test(test_wm_agent_upgrade_validate_system_windows_ok), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_rhel_ok), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_ubuntu_ok), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_darwin_x64_ok), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_darwin_arm_ok), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_invalid_platform_solaris), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_invalid_platform_suse), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_invalid_platform_rhel), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_invalid_platform_centos), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_invalid_arch), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_rolling_opensuse), - cmocka_unit_test(test_wm_agent_upgrade_validate_system_rolling_archlinux), - // wm_agent_upgrade_validate_wpk_version - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_windows_https_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_windows_http_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_windows_invalid_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_windows_invalid_repo, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_https_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_http_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_invalid_str_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_invalid_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_invalid_repo, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_ubuntu_old_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_macos_https_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_macos_http_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_macos_x86_64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_macos_aarch64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_rhel_old_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_no_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_x86_64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_aarch64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_rpm, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_deb, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_rpm_deb_force, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_x86_64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_aarch64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_deb, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_rpm, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_deb_rpm_force, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_x86_64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_aarch64, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_rpm, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_version_linux_package_unsupported_deb, setup_validate_wpk_version, teardown_validate_wpk_version), - // wm_agent_upgrade_validate_version - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_custom_ok, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_non_minimal, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_custom_non_minimal, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_older_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_greater_version, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_force, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_version_null, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_ok_macos, setup_validate_wpk_version, teardown_validate_wpk_version), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_version_upgrade_non_minimal_macos, setup_validate_wpk_version, teardown_validate_wpk_version), - // wm_agent_upgrade_validate_wpk - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_exist, setup_validate_wpk, teardown_validate_wpk), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_exist_diff_sha1, setup_validate_wpk, teardown_validate_wpk), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_download_retry, setup_validate_wpk, teardown_validate_wpk), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_download_diff_sha1, setup_validate_wpk, teardown_validate_wpk), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_download_retry_max, setup_validate_wpk, teardown_validate_wpk), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_task_error, setup_validate_wpk, teardown_validate_wpk), - // wm_agent_upgrade_validate_wpk_custom - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_custom_exist, setup_validate_wpk_custom, teardown_validate_wpk_custom), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_custom_not_exist, setup_validate_wpk_custom, teardown_validate_wpk_custom), - cmocka_unit_test_setup_teardown(test_wm_agent_upgrade_validate_wpk_custom_task_error, setup_validate_wpk_custom, teardown_validate_wpk_custom), - // wm_agent_upgrade_validate_task_status_message - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_status_message_ok, teardown_validate_message), - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_status_message_not_agent_status_ok, teardown_validate_message), - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_status_message_error_code, teardown_validate_message), - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_status_message_invalid_json, teardown_validate_message), - cmocka_unit_test(test_wm_agent_upgrade_validate_task_status_message_null_json), - // wm_agent_upgrade_validate_task_ids_message - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_ids_message_ok, teardown_validate_message), - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_ids_message_not_agent_error, teardown_validate_message), - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_ids_message_not_data_error, teardown_validate_message), - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_ids_message_not_task_ok, teardown_validate_message), - cmocka_unit_test_teardown(test_wm_agent_upgrade_validate_task_ids_message_invalid_json, teardown_validate_message), - cmocka_unit_test(test_wm_agent_upgrade_validate_task_ids_message_null_json) - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/aws/CMakeLists.txt b/src/unit_tests/wazuh_modules/aws/CMakeLists.txt deleted file mode 100644 index 9df6d818097..00000000000 --- a/src/unit_tests/wazuh_modules/aws/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_aws") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror \ - -Wl,--wrap=_mtwarn,--wrap=_mtinfo,--wrap=_mterror,--wrap=wm_aws_run_s3,--wrap=StartMQ,--wrap=FOREVER \ - -Wl,--wrap=atexit -Wl,--wrap=wm_state_io") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB aws ../../../wazuh_modules/*.o) -list(REMOVE_ITEM aws ../../../wazuh_modules/main.o) - -add_library(AWS_O STATIC ${aws}) - -set_source_files_properties( - ${aws} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - AWS_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(AWS_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - AWS_O - -lcmocka - -ldl - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/aws/test_wm_aws.c b/src/unit_tests/wazuh_modules/aws/test_wm_aws.c deleted file mode 100644 index 88dea8bf721..00000000000 --- a/src/unit_tests/wazuh_modules/aws/test_wm_aws.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for aws Module - * */ - -#include -#include -#include -#include -#include -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../../../wazuh_modules/wm_aws.h" -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wmodules_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" - -#define TEST_MAX_DATES 5 - -static wmodule *aws_module; -static OS_XML *lxml; -extern int test_mode; - -extern void wm_aws_run_s3(wm_aws_bucket *bucket); - -void wm_aws_run_s3(wm_aws_bucket *exec_bucket) { - // Will wrap this function to check running times in order to check scheduling - return; -} -/****************************************************************/ - -static void wmodule_cleanup(wmodule *module) { - free( ((wm_aws*) module->data)->buckets->bucket); - free( ((wm_aws*) module->data)->buckets->aws_profile); - free( ((wm_aws*) module->data)->buckets->trail_prefix); - free( ((wm_aws*) module->data)->buckets->type); - free( ((wm_aws*) module->data)->buckets); - free(module->data); - free(module->tag); - free(module); -} - -/*** SETUPS/TEARDOWNS ******/ -static int setup_module() { - int ret; - aws_module = calloc(1, sizeof(wmodule)); - const char *string = - "no\n" - "10m\n" - "no\n" - "yes\n" - "\n" - " wazuh-aws-wodle\n" - " config\n" - " default\n" - "" - ; - lxml = malloc(sizeof(OS_XML)); - XML_NODE nodes = string_to_xml_node(string, lxml); - ret = wm_aws_read(lxml, nodes, aws_module); - OS_ClearNode(nodes); - test_mode = 1; - return ret; -} - -static int teardown_module() { - test_mode = 0; - wmodule_cleanup(aws_module); - OS_ClearXML(lxml); - return 0; -} - -static int setup_test_executions(void **state) { - wm_max_eps = 1; - return 0; -} - -static int teardown_test_executions(void **state) { - wm_aws* module_data = (wm_aws *) *state; - sched_scan_free(&(module_data->scan_config)); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wm_aws *module_data = (wm_aws*)test->module->data; - sched_scan_free(&(module_data->scan_config)); - wmodule_cleanup(test->module); - os_free(test); - return 0; -} - -/** Tests **/ -void test_interval_execution(void **state) { - wm_aws* module_data = (wm_aws *)aws_module->data; - int i = 0; - - *state = module_data; - module_data->scan_config.next_scheduled_scan_time = 0; - module_data->scan_config.scan_day = 0; - module_data->scan_config.scan_wday = -1; - module_data->scan_config.interval = 600; // 10min - module_data->scan_config.month_interval = false; - - will_return_count(__wrap_FOREVER, 1, TEST_MAX_DATES); - will_return(__wrap_FOREVER, 0); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 0); - - expect_string(__wrap_wm_state_io, tag, "aws-s3"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_value(__wrap_wm_state_io, state, &module_data->state); - expect_value(__wrap_wm_state_io, size, sizeof(module_data->state)); - will_return(__wrap_wm_state_io, 1); - - for (i = 0; i < TEST_MAX_DATES + 1; i++) { - expect_string(__wrap_wm_state_io, tag, "aws-s3"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_value(__wrap_wm_state_io, state, &module_data->state); - expect_value(__wrap_wm_state_io, size, sizeof(module_data->state)); - will_return(__wrap_wm_state_io, -1); - } - - expect_string_count(__wrap__mterror, tag, "wazuh-modulesd:aws-s3", TEST_MAX_DATES + 1); - expect_string_count(__wrap__mterror, formatted_msg, "Couldn't save running state.", TEST_MAX_DATES + 1); - expect_any_always(__wrap__mtinfo, tag); - expect_any_always(__wrap__mtinfo, formatted_msg); - - aws_module->context->start(module_data); -} - -void test_fake_tag(void **state) { - const char *string = - "no\n" - "\n" - "no\n" - "yes\n" - "\n" - " wazuh-aws-wodle\n" - " config\n" - " default\n" - "\n" - "ASD" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'fake-tag' at module 'aws-s3'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_aws_read(&(test->xml), test->nodes, test->module), -1); - -} - -void test_read_scheduling_monthday_configuration(void **state) { - const char *string = - "no\n" - "\n" - "6\n" - "no\n" - "yes\n" - "\n" - " wazuh-aws-wodle\n" - " config\n" - " default\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_aws_read(&(test->xml), test->nodes, test->module), 0); - wm_aws *module_data = (wm_aws*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 6); - assert_int_equal(module_data->scan_config.interval, 1); - assert_int_equal(module_data->scan_config.month_interval, true); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "15:05"); -} - -void test_read_scheduling_weekday_configuration(void **state) { - const char *string = - "no\n" - "\n" - "Monday\n" - "no\n" - "yes\n" - "\n" - " wazuh-aws-wodle\n" - " config\n" - " default\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_aws_read(&(test->xml), test->nodes, test->module), 0); - wm_aws *module_data = (wm_aws*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 604800); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, 1); - assert_string_equal(module_data->scan_config.scan_time, "13:03"); -} - -void test_read_scheduling_daytime_configuration(void **state) { - const char *string = - "no\n" - "\n" - "no\n" - "yes\n" - "\n" - " wazuh-aws-wodle\n" - " config\n" - " default\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one day. New interval value: 1d"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_aws_read(&(test->xml), test->nodes, test->module), 0); - wm_aws *module_data = (wm_aws*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "01:11"); -} - -void test_read_scheduling_interval_configuration(void **state) { - const char *string = - "no\n" - "10m\n" - "no\n" - "yes\n" - "\n" - " wazuh-aws-wodle\n" - " config\n" - " default\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_aws_read(&(test->xml), test->nodes, test->module), 0); - wm_aws *module_data = (wm_aws*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 600); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); -} - -int main(void) { - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_interval_execution, setup_test_executions, teardown_test_executions) - }; - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_monthday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_weekday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_daytime_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_interval_configuration, setup_test_read, teardown_test_read) - }; - int result; - result = cmocka_run_group_tests(tests_with_startup, setup_module, teardown_module); - result += cmocka_run_group_tests(tests_without_startup, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/azure/CMakeLists.txt b/src/unit_tests/wazuh_modules/azure/CMakeLists.txt deleted file mode 100644 index 7a75df89ae9..00000000000 --- a/src/unit_tests/wazuh_modules/azure/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_azure") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror \ - -Wl,--wrap=_mtwarn,--wrap=_mtinfo,--wrap=_mterror,--wrap=wm_exec,--wrap=StartMQ,--wrap=FOREVER,--wrap=SendMSG \ - -Wl,--wrap=atexit") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB azure ../../../wazuh_modules/*.o) -list(REMOVE_ITEM azure ../../../wazuh_modules/main.o) - -add_library(AZURE_O STATIC ${azure}) - -set_source_files_properties( - ${azure} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - AZURE_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(AZURE_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - AZURE_O - -lcmocka - -ldl - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/azure/test_wm_azure.c b/src/unit_tests/wazuh_modules/azure/test_wm_azure.c deleted file mode 100644 index 0d38bc96ca0..00000000000 --- a/src/unit_tests/wazuh_modules/azure/test_wm_azure.c +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for azure Module - * */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../../../wazuh_modules/wm_azure.h" - -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" - -#define TEST_MAX_DATES 5 - -static wmodule *azure_module; -static OS_XML *lxml; -extern int test_mode; - -static void wmodule_cleanup(wmodule *module){ - wm_azure_t* module_data = (wm_azure_t *)module->data; - if(module_data->api_config){ - free(module_data->api_config->auth_path); - free(module_data->api_config->tenantdomain); - free(module_data->api_config->request->time_offset); - free(module_data->api_config->request->workspace); - free(module_data->api_config->request->query); - free(module_data->api_config->request->tag); - free(module_data->api_config->request); - free(module_data->api_config); - } - free(module_data); - free(module->tag); - free(module); -} - - -/*** SETUPS/TEARDOWNS ******/ -static int setup_module() { - azure_module = calloc(1, sizeof(wmodule)); - const char *string = - "no\n" - "5m\n" - "no\n" - "\n" - " /var/ossec/wodles/azure/credentials.txt\n" - " wazuh.onmicrosoft.com\n" - " \n" - " azure-activity\n" - " AzureActivity | where SubscriptionId == 2d7...61d \n" - " d6b...efa\n" - " 36h\n" - " \n" - "\n" - ; - lxml = malloc(sizeof(OS_XML)); - XML_NODE nodes = string_to_xml_node(string, lxml); - int ret = wm_azure_read(lxml, nodes, azure_module); - OS_ClearNode(nodes); - test_mode = 1; - return ret; -} - -static int teardown_module(){ - test_mode = 0; - wmodule_cleanup(azure_module); - OS_ClearXML(lxml); - return 0; -} - -static int setup_test_executions(void **state) { - return 0; -} - -static int teardown_test_executions(void **state){ - wm_azure_t* module_data = (wm_azure_t *) *state; - sched_scan_free(&(module_data->scan_config)); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wm_azure_t *module_data = (wm_azure_t*)test->module->data; - sched_scan_free(&(module_data->scan_config)); - wmodule_cleanup(test->module); - os_free(test); - return 0; -} -/************************************/ - -void test_interval_execution(void **state) { - wm_azure_t* module_data = (wm_azure_t *)azure_module->data; - *state = module_data; - module_data->scan_config.next_scheduled_scan_time = 0; - module_data->scan_config.scan_day = 0; - module_data->scan_config.scan_wday = -1; - module_data->scan_config.interval = 1200; // 20min - module_data->scan_config.month_interval = false; - - expect_any_count(__wrap_SendMSG, message, (TEST_MAX_DATES + 1) * 2); - expect_string_count(__wrap_SendMSG, locmsg, xml_rootcheck, (TEST_MAX_DATES + 1) * 2); - expect_value_count(__wrap_SendMSG, loc, ROOTCHECK_MQ, (TEST_MAX_DATES + 1) * 2); - will_return_count(__wrap_SendMSG, 1, (TEST_MAX_DATES + 1) * 2); - - expect_any_always(__wrap_wm_exec, command); - expect_any_always(__wrap_wm_exec, secs); - expect_any_always(__wrap_wm_exec, add_path); - - will_return_always(__wrap_wm_exec, 0); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 0); - - will_return_count(__wrap_FOREVER, 1, TEST_MAX_DATES); - will_return(__wrap_FOREVER, 0); - expect_any_always(__wrap__mtinfo, tag); - expect_any_always(__wrap__mtinfo, formatted_msg); - - azure_module->context->start(module_data); -} - -void test_fake_tag(void **state) { - const char *string = - "no\n" - "1\n" - "\n" - "no\n" - "\n" - " /var/ossec/wodles/azure/credentials.txt\n" - " wazuh.onmicrosoft.com\n" - " \n" - " azure-activity\n" - " AzureActivity | where SubscriptionId == 2d7...61d \n" - " d6b...efa\n" - " 36h\n" - " \n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'fake_tag' at module 'azure-logs'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_azure_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_scheduling_monthday_configuration(void **state) { - const char *string = - "no\n" - "\n" - "4\n" - "no\n" - "\n" - " /var/ossec/wodles/azure/credentials.txt\n" - " wazuh.onmicrosoft.com\n" - " \n" - " azure-activity\n" - " AzureActivity | where SubscriptionId == 2d7...61d \n" - " d6b...efa\n" - " 36h\n" - " \n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_azure_read(&(test->xml), test->nodes, test->module),0); - wm_azure_t *module_data = (wm_azure_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 4); - assert_int_equal(module_data->scan_config.interval, 1); - assert_int_equal(module_data->scan_config.month_interval, true); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "00:01"); -} - -void test_read_scheduling_weekday_configuration(void **state) { - const char *string = - "no\n" - "\n" - "Friday\n" - "no\n" - "\n" - " /var/ossec/wodles/azure/credentials.txt\n" - " wazuh.onmicrosoft.com\n" - " \n" - " azure-activity\n" - " AzureActivity | where SubscriptionId == 2d7...61d \n" - " d6b...efa\n" - " 36h\n" - " \n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_azure_read(&(test->xml), test->nodes, test->module),0); - wm_azure_t *module_data = (wm_azure_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 604800); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, 5); - assert_string_equal(module_data->scan_config.scan_time, "00:01"); -} - -void test_read_scheduling_daytime_configuration(void **state) { - const char *string = - "no\n" - "\n" - "no\n" - "\n" - " /var/ossec/wodles/azure/credentials.txt\n" - " wazuh.onmicrosoft.com\n" - " \n" - " azure-activity\n" - " AzureActivity | where SubscriptionId == 2d7...61d \n" - " d6b...efa\n" - " 36h\n" - " \n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_azure_read(&(test->xml), test->nodes, test->module),0); - wm_azure_t *module_data = (wm_azure_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "00:10"); -} - -void test_read_scheduling_interval_configuration(void **state) { - const char *string = - "no\n" - "3h\n" - "no\n" - "\n" - " /var/ossec/wodles/azure/credentials.txt\n" - " wazuh.onmicrosoft.com\n" - " \n" - " azure-activity\n" - " AzureActivity | where SubscriptionId == 2d7...61d \n" - " d6b...efa\n" - " 36h\n" - " \n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_azure_read(&(test->xml), test->nodes, test->module),0); - wm_azure_t *module_data = (wm_azure_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 3600*3); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); -} - -int main(void) { - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_interval_execution, setup_test_executions, teardown_test_executions) - }; - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_monthday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_weekday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_daytime_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_interval_configuration, setup_test_read, teardown_test_read) - }; - int result; - result = cmocka_run_group_tests(tests_with_startup, setup_module, teardown_module); - result += cmocka_run_group_tests(tests_without_startup, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/ciscat/CMakeLists.txt b/src/unit_tests/wazuh_modules/ciscat/CMakeLists.txt deleted file mode 100644 index d7b494b5721..00000000000 --- a/src/unit_tests/wazuh_modules/ciscat/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_ciscat") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror \ - -Wl,--wrap=_mtwarn,--wrap=_mtinfo,--wrap=_mterror,--wrap=os_random,--wrap=StartMQ,--wrap=FOREVER,--wrap=IsDir \ - -Wl,--wrap=atexit,--wrap=wfopen") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB ciscat ../../../wazuh_modules/*.o) -list(REMOVE_ITEM ciscat ../../../wazuh_modules/main.o) - -add_library(CISCAT_O STATIC ${ciscat}) - -set_source_files_properties( - ${ciscat} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - CISCAT_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(CISCAT_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - CISCAT_O - -ldl - -lcmocka - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/ciscat/test_wm_ciscat.c b/src/unit_tests/wazuh_modules/ciscat/test_wm_ciscat.c deleted file mode 100644 index 6640c66d51c..00000000000 --- a/src/unit_tests/wazuh_modules/ciscat/test_wm_ciscat.c +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for ciscat Module - * */ - -#define ENABLE_CISCAT -#include -#include -#include -#include -#include -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../../../wazuh_modules/wm_ciscat.h" -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../../wrappers/wazuh/shared/randombytes_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" - -#define TEST_MAX_DATES 5 - -static wmodule *ciscat_module; -static OS_XML *lxml; -extern int test_mode; - -static void wmodule_cleanup(wmodule *module){ - wm_ciscat* module_data = (wm_ciscat *) module->data; - wm_ciscat_eval *eval = module_data->evals; - while(eval != 0) { - wm_ciscat_eval *aux = eval; - eval = eval->next; - os_free(aux->profile); - os_free(aux->path); - os_free(aux); - } - os_free(module_data->ciscat_binary); - os_free(module_data->ciscat_path); - os_free(module_data->java_path); - os_free(module_data); - os_free(module->tag); - os_free(module); -} - -/*** SETUPS/TEARDOWNS ******/ -static int setup_module() { - ciscat_module = calloc(1, sizeof(wmodule)); - const char *string = - "no\n" - "1800\n" - "3m\n" - "no\n" - "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin\n" - "/var/ossec/wodles/ciscat\n" - "\n" - " xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server\n" - "\n" - ; - lxml = malloc(sizeof(OS_XML)); - XML_NODE nodes = string_to_xml_node(string, lxml); - int ret = wm_ciscat_read(lxml, nodes, ciscat_module); - OS_ClearNode(nodes); - test_mode = 1; - return ret; -} - -static int teardown_module(){ - test_mode = 0; - wmodule_cleanup(ciscat_module); - OS_ClearXML(lxml); - return 0; -} - -static int setup_test_executions() { - return 0; -} - -static int teardown_test_executions(void **state){ - wm_ciscat* module_data = (wm_ciscat *) *state; - sched_scan_free(&(module_data->scan_config)); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wm_ciscat *module_data = (wm_ciscat*)test->module->data; - if (module_data) { - os_free(module_data->ciscat_binary); - sched_scan_free(&(module_data->scan_config)); - } - wmodule_cleanup(test->module); - os_free(test); - return 0; -} -/************************************/ - -void test_interval_execution(void **state) { - wm_ciscat* module_data = (wm_ciscat *)ciscat_module->data; - *state = module_data; - FILE *fp = NULL; - module_data->scan_config.next_scheduled_scan_time = 0; - module_data->scan_config.scan_day = 0; - module_data->scan_config.scan_wday = -1; - module_data->scan_config.interval = 120; // 2min - module_data->scan_config.month_interval = false; - - expect_wfopen("var/wodles/cis-cat", "rb", fp); - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 0); - expect_string(__wrap_IsDir, file, "/var/ossec/wodles/ciscat"); - will_return(__wrap_IsDir, 0); - will_return_count(__wrap_FOREVER, 1, TEST_MAX_DATES); - will_return(__wrap_FOREVER, 0); - will_return_always(__wrap_os_random, 12345); - expect_string_count(__wrap__mterror, tag, "wazuh-modulesd:ciscat", TEST_MAX_DATES + 1); - expect_string_count(__wrap__mterror, formatted_msg, "Benchmark file '/var/ossec/wodles/ciscat/benchmarks/CIS_Ubuntu_Linux_16.04_LTS_Benchmark_v1.0.0-xccdf.xml' not found.", TEST_MAX_DATES + 1); - expect_any_always(__wrap__mtinfo, tag); - expect_any_always(__wrap__mtinfo, formatted_msg); - - ciscat_module->context->start(module_data); -} - -void test_fake_tag(void **state) { - const char *string = - "no\n" - "1800\n" - "\n" - "no\n" - "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin\n" - "wodles/ciscat\n" - "laklsdaklsa" - "\n" - " xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'invalid-tag' at module 'cis-cat'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_ciscat_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_scheduling_monthday_configuration(void **state) { - const char *string = - "no\n" - "1800\n" - "\n" - "5\n" - "no\n" - "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin\n" - "wodles/ciscat\n" - "\n" - " xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_ciscat_read(&(test->xml), test->nodes, test->module),0); - wm_ciscat* module_data = (wm_ciscat *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 5); - assert_int_equal(module_data->scan_config.interval, 1); - assert_int_equal(module_data->scan_config.month_interval, true); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "14:59"); -} - -void test_read_scheduling_weekday_configuration(void** state) { - const char *string = - "no\n" - "1800\n" - "\n" - "Wednesday\n" - "no\n" - "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin\n" - "wodles/ciscat\n" - "\n" - " xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_ciscat_read(&(test->xml), test->nodes, test->module),0); - wm_ciscat* module_data = (wm_ciscat *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 604800); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, 3); - assert_string_equal(module_data->scan_config.scan_time, "23:59"); -} - -void test_read_scheduling_daytime_configuration(void **state) { - const char *string = - "no\n" - "1800\n" - "\n" - "no\n" - "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin\n" - "wodles/ciscat\n" - "\n" - " xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_ciscat_read(&(test->xml), test->nodes, test->module),0); - wm_ciscat* module_data = (wm_ciscat *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "11:45"); -} - -void test_read_scheduling_interval_configuration(void **state) { - const char *string = - "no\n" - "1800\n" - "1h\n" - "no\n" - "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin\n" - "wodles/ciscat\n" - "\n" - " xccdf_org.cisecurity.benchmarks_profile_Level_2_-_Server\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_ciscat_read(&(test->xml), test->nodes, test->module),0); - wm_ciscat* module_data = (wm_ciscat *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 3600); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); -} - -int main(void) { - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_interval_execution, setup_test_executions, teardown_test_executions) - }; - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_monthday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_weekday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_daytime_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_interval_configuration, setup_test_read, teardown_test_read) - }; - int result = (cmocka_run_group_tests(tests_with_startup, setup_module, teardown_module) || - cmocka_run_group_tests(tests_without_startup, NULL, NULL)); - return result; -} diff --git a/src/unit_tests/wazuh_modules/command/CMakeLists.txt b/src/unit_tests/wazuh_modules/command/CMakeLists.txt deleted file mode 100644 index 4d02926e68d..00000000000 --- a/src/unit_tests/wazuh_modules/command/CMakeLists.txt +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_command") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror \ - -Wl,--wrap=_mtwarn,--wrap=_mtinfo,--wrap=_mterror,--wrap=wm_exec,--wrap=StartMQ,--wrap=FOREVER") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB command ../../../wazuh_modules/*.o) -list(REMOVE_ITEM command ../../../wazuh_modules/main.o) - -add_library(COMMAND_O STATIC ${command}) - -set_source_files_properties( - ${command} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - COMMAND_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(COMMAND_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - COMMAND_O - -ldl - -lcmocka - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/command/test_wm_command.c b/src/unit_tests/wazuh_modules/command/test_wm_command.c deleted file mode 100644 index c29e71b127a..00000000000 --- a/src/unit_tests/wazuh_modules/command/test_wm_command.c +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for command Module - * */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../../../wazuh_modules/wm_command.h" - -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" - -#define TEST_MAX_DATES 5 - -static wmodule *command_module; -static OS_XML *lxml; -extern int test_mode; - -/****************************************************************/ -static void wmodule_cleanup(wmodule *module){ - wm_command_t* module_data = (wm_command_t *)module->data; - free(module_data->sha256_hash); - free(module_data->sha1_hash); - free(module_data->full_command); - free(module_data->command); - free(module_data->tag); - free(module_data); - free(module->tag); - free(module); -} - -/*** SETUPS/TEARDOWNS ******/ -static int setup_module() { - command_module = calloc(1, sizeof(wmodule)); - const char *string = - "no\n" - "test\n" - "/bin/bash /root/script.sh\n" - "1d\n" - "no\n" - "no\n" - "0\n" - "da39a3ee5e6b4b0d3255bfef95601890afd80709\n" - "292a188e498caea5c5fbfb0beca413c980e7a5edf40d47cf70e1dbc33e4f395e\n" - "10m\n" - "yes" - ; - lxml = malloc(sizeof(OS_XML)); - XML_NODE nodes = string_to_xml_node(string, lxml); - - int ret = wm_command_read(nodes, command_module, 0); - OS_ClearNode(nodes); - test_mode = 1; - return ret; -} - -static int teardown_module(){ - test_mode = 0; - wmodule_cleanup(command_module); - OS_ClearXML(lxml); - return 0; -} - -static int setup_test_executions(void **state){ - wm_max_eps = 1; - return 0; -} - -static int teardown_test_executions(void **state){ - wm_command_t* module_data = (wm_command_t *) *state; - sched_scan_free(&(module_data->scan_config)); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wm_command_t *module_data = (wm_command_t*)test->module->data; - sched_scan_free(&(module_data->scan_config)); - wmodule_cleanup(test->module); - os_free(test); - return 0; -} - -/** Tests **/ -void test_interval_execution(void **state) { - wm_command_t* module_data = (wm_command_t *)command_module->data; - *state = module_data; - module_data->scan_config.next_scheduled_scan_time = 0; - module_data->scan_config.scan_day = 0; - module_data->scan_config.scan_wday = -1; - module_data->scan_config.interval = 60; // 1min - module_data->scan_config.month_interval = false; - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 0); - - expect_any_always(__wrap_wm_exec, command); - expect_any_always(__wrap_wm_exec, secs); - expect_any_always(__wrap_wm_exec, add_path); - - will_return_always(__wrap_wm_exec, 0); - - will_return_count(__wrap_FOREVER, 1, TEST_MAX_DATES); - will_return(__wrap_FOREVER, 0); - expect_any_always(__wrap__mtinfo, tag); - expect_any_always(__wrap__mtinfo, formatted_msg); - expect_any_always(__wrap__mtwarn, tag); - expect_any_always(__wrap__mtwarn, formatted_msg); - - command_module->context->start(module_data); -} - -void test_fake_tag(void **state) { - const char *string = - "True\n" - "no\n" - "test\n" - "/bin/bash /root/script.sh\n" - "1800\n" - "\n" - "no\n" - "no\n" - "0\n" - "da39a3ee5e6b4b0d3255bfef95601890afd80709\n" - "292a188e498caea5c5fbfb0beca413c980e7a5edf40d47cf70e1dbc33e4f395e\n" - "10m\n" - "yes"; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'fake' at module 'command'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_command_read(test->nodes, test->module, 0),-1); -} - -void test_read_scheduling_monthday_configuration(void **state) { - const char *string = - "no\n" - "test\n" - "\n" - "1\n" - "/bin/bash /root/script.sh\n" - "1800\n" - "no\n" - "no\n" - "0\n" - "da39a3ee5e6b4b0d3255bfef95601890afd80709\n" - "292a188e498caea5c5fbfb0beca413c980e7a5edf40d47cf70e1dbc33e4f395e\n" - "yes" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_command_read(test->nodes, test->module, 0),0); - wm_command_t *module_data = (wm_command_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 1); - assert_int_equal(module_data->scan_config.interval, 1); - assert_int_equal(module_data->scan_config.month_interval, true); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "12:05"); -} - -void test_read_scheduling_weekday_configuration(void **state) { - const char *string = - "no\n" - "test\n" - "\n" - "Tuesday\n" - "/bin/bash /root/script.sh\n" - "1800\n" - "no\n" - "no\n" - "0\n" - "da39a3ee5e6b4b0d3255bfef95601890afd80709\n" - "292a188e498caea5c5fbfb0beca413c980e7a5edf40d47cf70e1dbc33e4f395e\n" - "yes" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_command_read(test->nodes, test->module, 0),0); - wm_command_t *module_data = (wm_command_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 604800); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, 2); - assert_string_equal(module_data->scan_config.scan_time, "10:59"); -} - -void test_read_scheduling_daytime_configuration(void **state) { - const char *string = - "no\n" - "test\n" - "\n" - "/bin/bash /root/script.sh\n" - "1800\n" - "no\n" - "no\n" - "0\n" - "da39a3ee5e6b4b0d3255bfef95601890afd80709\n" - "292a188e498caea5c5fbfb0beca413c980e7a5edf40d47cf70e1dbc33e4f395e\n" - "yes" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one day. New interval value: 1d"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_command_read(test->nodes, test->module, 0),0); - wm_command_t *module_data = (wm_command_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "10:53"); -} - -void test_read_scheduling_interval_configuration(void **state) { - const char *string = - "no\n" - "test\n" - "10s\n" - "/bin/bash /root/script.sh\n" - "1800\n" - "no\n" - "no\n" - "0\n" - "da39a3ee5e6b4b0d3255bfef95601890afd80709\n" - "292a188e498caea5c5fbfb0beca413c980e7a5edf40d47cf70e1dbc33e4f395e\n" - "yes" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_command_read(test->nodes, test->module, 0),0); - wm_command_t *module_data = (wm_command_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 10); // 10 seconds - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); -} - -int main(void) { - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_interval_execution, setup_test_executions, teardown_test_executions) - }; - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_monthday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_weekday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_daytime_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_interval_configuration, setup_test_read, teardown_test_read) - }; - int result; - result = cmocka_run_group_tests(tests_with_startup, setup_module, teardown_module); - result += cmocka_run_group_tests(tests_without_startup, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/control/CMakeLists.txt b/src/unit_tests/wazuh_modules/control/CMakeLists.txt deleted file mode 100644 index 02b2fae2ff5..00000000000 --- a/src/unit_tests/wazuh_modules/control/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Tests list and flags -list(APPEND tests_names "test_wm_control") -list(APPEND tests_flags "-Wl,--wrap,sysinfo_networks -Wl,--wrap,sysinfo_free_result ${DEBUG_OP_WRAPPERS}") -list(APPEND use_shared_libs 1) - - -# Generate wazuh modules library -file(GLOB control ../../../wazuh_modules/*.o) -list(REMOVE_ITEM control ../../../wazuh_modules/main.o) - -add_library(CONTROL_O STATIC ${control}) - -set_source_files_properties( - ${control} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - CONTROL_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(CONTROL_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - CONTROL_O - -lcmocka - -ldl - -fprofile-arcs - -ftest-coverage - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - endif() - - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/control/test_wm_control.c b/src/unit_tests/wazuh_modules/control/test_wm_control.c deleted file mode 100644 index 9363a9d7423..00000000000 --- a/src/unit_tests/wazuh_modules/control/test_wm_control.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include "../../wrappers/wazuh/data_provider/sysInfo_wrappers.h" -#include "../../../data_provider/include/sysInfo.h" -#include "../../../wazuh_modules/wm_control.h" - -extern sysinfo_networks_func sysinfo_network_ptr; -extern sysinfo_free_result_func sysinfo_free_result_ptr; - -static void test_wm_control_getPrimaryIP_no_sysinfo_network(void ** state) { - sysinfo_network_ptr = NULL; - - char * ip = getPrimaryIP(); - - assert_null(ip); -} - -static void test_wm_control_getPrimaryIP_no_sysinfo_free(void ** state) { - sysinfo_network_ptr = (int (*)(cJSON **)) 1; - sysinfo_free_result_ptr = NULL; - - char * ip = getPrimaryIP(); - - assert_null(ip); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_return_error(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = NULL; - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 1234); - expect_string(__wrap__mterror, tag, "wazuh-modulesd:control"); - expect_string(__wrap__mterror, formatted_msg, "Unable to get system network information. Error code: 1234."); - - char * ip = getPrimaryIP(); - - assert_null(ip); -} -static void test_wm_control_getPrimaryIP_sysinfo_network_no_object(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = NULL; - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - - char * ip = getPrimaryIP(); - - assert_null(ip); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_no_iface(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_no_iface_array(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":{}}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_empty_array(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_no_gateway(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[{\"name\":\"eth0\"}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_invalid_gateway_type(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[{\"name\":\"eth0\",\"gateway\":1234}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_empty_gateway(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[{\"name\":\"eth0\",\"gateway\":\" \"}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv6_gateway_ipv6_address(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[{\"name\":\"eth0\",\"gateway\":\"fe80::\",\"IPv6\":[{\"address\":" - "\"fe80::a00:27ff:fee0:d046\"}]}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_string_equal(ip, "FE80:0000:0000:0000:0A00:27FF:FEE0:D046"); - - os_free(ip); - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv6_gateway_ipv4_address(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse( - "{\"iface\":[{\"name\":\"eth0\",\"gateway\":\"fe80::\",\"IPv4\":[{\"address\":\"192.168.1.10\"}]}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_string_equal(ip, "192.168.1.10"); - - os_free(ip); - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv4_gateway_ipv6_address(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[{\"name\":\"eth0\",\"gateway\":\"192.168.1.1\",\"IPv6\":[{\"address\":" - "\"fe80::a00:27ff:fee0:d046\"}]}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_string_equal(ip, "FE80:0000:0000:0000:0A00:27FF:FEE0:D046"); - - os_free(ip); - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv4_gateway_ipv4_address(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse( - "{\"iface\":[{\"name\":\"eth0\",\"gateway\":\"192.168.1.1\",\"IPv4\":[{\"address\":\"192.168.1.10\"}]}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_string_equal(ip, "192.168.1.10"); - - os_free(ip); - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_valid_gateway_no_address_array(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[{\"name\":\"eth0\",\"gateway\":\"192.168.1.1\"}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_valid_gateway_address_invalid_type(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = - cJSON_Parse("{\"iface\":[{\"name\":\"eth0\",\"gateway\":\"192.168.1.1\",\"IPv4\":[{\"address\":1234}]}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_null(ip); - - cJSON_Delete(networks); -} - -static void test_wm_control_getPrimaryIP_sysinfo_network_iface_valid_gateway_multiple_address_array(void ** state) { - sysinfo_network_ptr = __wrap_sysinfo_networks; - sysinfo_free_result_ptr = __wrap_sysinfo_free_result; - cJSON * networks = cJSON_Parse("{\"iface\":[{\"name\":\"eth0\",\"gateway\":\"192.168.1.1\",\"IPv4\":[{\"address\":" - "\"192.168.1.10\"},{\"address\":\"192.168.1.11\"}]}]}"); - - will_return(__wrap_sysinfo_networks, networks); - will_return(__wrap_sysinfo_networks, 0); - will_return(__wrap_sysinfo_free_result, networks); - - char * ip = getPrimaryIP(); - - assert_string_equal(ip, "192.168.1.10"); - - os_free(ip); - cJSON_Delete(networks); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_wm_control_getPrimaryIP_no_sysinfo_network), - cmocka_unit_test(test_wm_control_getPrimaryIP_no_sysinfo_free), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_return_error), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_no_object), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_no_iface), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_no_iface_array), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_empty_array), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_no_gateway), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_invalid_gateway_type), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_empty_gateway), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv6_gateway_ipv6_address), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv6_gateway_ipv4_address), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv4_gateway_ipv6_address), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_ipv4_gateway_ipv4_address), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_valid_gateway_no_address_array), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_valid_gateway_address_invalid_type), - cmocka_unit_test(test_wm_control_getPrimaryIP_sysinfo_network_iface_valid_gateway_multiple_address_array)}; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/database/CMakeLists.txt b/src/unit_tests/wazuh_modules/database/CMakeLists.txt deleted file mode 100644 index a0f9b700760..00000000000 --- a/src/unit_tests/wazuh_modules/database/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -list(APPEND wmdb_tests_names "test_wm_database") -list(APPEND wmdb_tests_flags "-Wl,--wrap,wdb_set_agent_groups -Wl,--wrap,opendir -Wl,--wrap,readdir -Wl,--wrap,strerror -Wl,--wrap,unlink \ - -Wl,--wrap,closedir -Wl,--wrap,rmdir_ex -Wl,--wrap,getpid -Wl,--wrap,w_is_single_node -Wl,--wrap,_mterror \ - -Wl,--wrap,wdb_get_all_agents_rbtree -Wl,--wrap,rbtree_get -Wl,--wrap,wdb_get_agent_group -Wl,--wrap,OS_CIDRtoStr \ - -Wl,--wrap,wdb_insert_agent -Wl,--wrap,rbtree_keys -Wl,--wrap,OS_IsAllowedID -Wl,--wrap,wdb_get_agent_name \ - -Wl,--wrap,wdb_remove_agent -Wl,--wrap,fopen -Wl,--wrap,wfopen \ - -Wl,--wrap,wdb_get_agent_name -Wl,--wrap,wdbc_query_ex -Wl,--wrap,popen ${DEBUG_OP_WRAPPERS} ${STDIO_OP_WRAPPERS}") - -# Add extra compiling flags -add_compile_options(-Wall) - -# Compilig tests -list(LENGTH wmdb_tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET wmdb_tests_names ${counter} test_name) - list(GET wmdb_tests_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/database/test_wm_database.c b/src/unit_tests/wazuh_modules/database/test_wm_database.c deleted file mode 100644 index 6a7526aaaef..00000000000 --- a/src/unit_tests/wazuh_modules/database/test_wm_database.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * March, 2022. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include "../../../wazuh_modules/wmodules_def.h" -#include "../../../wazuh_modules/wm_database.h" - -#include "../../wrappers/common.h" -#include "../../wrappers/wazuh/os_crypto/keys_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../../wrappers/wazuh/shared/rbtree_op_wrappers.h" -#include "../../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_db/wdb_global_helpers_wrappers.h" -#include "../../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/libc/string_wrappers.h" -#include "../../wrappers/posix/dirent_wrappers.h" -#include "../../wrappers/posix/unistd_wrappers.h" - -/* setup/teardown */ - -extern int test_mode; -extern int is_worker; - -int setup_wmdb(void **state) { - test_mode = 1; - return OS_SUCCESS; -} - -int teardown_wmdb(void **state) { - test_mode = 0; - return OS_SUCCESS; -} - -int setup_keys_to_db(void **state) { - keystore keys = KEYSTORE_INITIALIZER; - - keyentry** keyentries; - os_calloc(1, sizeof(keyentry*), keyentries); - keys.keyentries = keyentries; - - keyentry *key = NULL; - os_calloc(1, sizeof(keyentry), key); - keys.keyentries[0] = key; - - key->id = strdup("001"); - key->name = strdup("agent1"); - key->ip = (os_ip *)1; - key->raw_key = strdup("1234567890abcdef"); - - os_calloc(1, sizeof(keystore), *state); - memcpy(*state, &keys, sizeof(keystore)); - - test_mode = 1; - return OS_SUCCESS; -} - -int teardown_keys_to_db(void **state) { - keystore * keys = (keystore *)*state; - - os_free(keys->keyentries[0]->id); - os_free(keys->keyentries[0]->name); - os_free(keys->keyentries[0]->raw_key); - os_free(keys->keyentries[0]); - os_free(keys->keyentries); - os_free(keys); - - test_mode = 0; - return OS_SUCCESS; -} - -/* helpers */ - -/** - * @brief Generates a CSV string with the name of 'ngroups'. The string must - * be deallocated by the caller. - * - * @param ngroups The number of group names to be included in the CSV string - * @return char* The groups CSV string. - */ -char *generate_groups_csv_string(unsigned int ngroups) { - char *groups = NULL; - os_calloc(OS_BUFFER_SIZE, sizeof(char), groups); - - int i = 0, position = 0; - for (i = 0; i < ngroups-1; ++i) { - snprintf(groups+position, OS_BUFFER_SIZE - position, "group%d,", i); - position = strlen(groups); - } - snprintf(groups+position, OS_BUFFER_SIZE - position, "group%d\n", i); - - return groups; -} - -/* Tests wm_sync_group_file */ - -void test_wm_sync_group_file_error_agent_id(void **state) { - int ret = OS_INVALID; - const char *group_file = "invalid_name"; - const char *group_file_path = "invalid_path"; - - // Invalid agent ID obtained from 'group_file' - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Couldn't extract agent ID from file 'invalid_path'."); - - ret = wm_sync_group_file(group_file, group_file_path); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wm_sync_group_file_error_opening_file(void **state) { - int ret = OS_INVALID; - const char *group_file = "001"; - const char *group_file_path = "invalid_path"; - - // Error opening agent groups file specified by 'group_file_path' - expect_string(__wrap_wfopen, path, group_file_path); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Groups file 'invalid_path' could not be opened for syncronization."); - - ret = wm_sync_group_file(group_file, group_file_path); - - assert_int_equal(ret, OS_INVALID); -} - -void test_wm_sync_group_file_success_empty_file(void **state) { - int ret = OS_INVALID; - const char *group_file = "001"; - const char *group_file_path = GROUPS_DIR "/001"; - FILE *fp_group_file = (FILE *)1; - const char *groups_in_file = NULL; - - // Agent groups file opened succesfully - expect_string(__wrap_wfopen, path, group_file_path); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, fp_group_file); - // No data when reading the file - will_return(__wrap_fgets, groups_in_file); - expect_value(__wrap_fgets, __stream, fp_group_file); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Empty group file 'queue/agent-groups/001'."); - // Closing group file - expect_value(__wrap_fclose, _File, fp_group_file); - will_return(__wrap_fclose, OS_SUCCESS); - - ret = wm_sync_group_file(group_file, group_file_path); - - assert_int_equal(ret, OS_SUCCESS); -} - -void test_wm_sync_group_file_success_more_than_max_groups(void **state) { - int ret = OS_INVALID; - const char *group_file = "001"; - const char *group_file_path = GROUPS_DIR "/001"; - int agent_id = atoi(group_file); - FILE *fp_group_file = (FILE *)1; - - // Generating a CSV groups string with more than 128 groups - char *groups_in_file = generate_groups_csv_string(MAX_GROUPS_PER_MULTIGROUP+1); - - // Agent groups file opened succesfully - expect_string(__wrap_wfopen, path, group_file_path); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, fp_group_file); - // Reading the file - will_return(__wrap_fgets, groups_in_file); - expect_value(__wrap_fgets, __stream, fp_group_file); - // Setting groups - will_return(__wrap_w_is_single_node, 1); - expect_value(__wrap_wdb_set_agent_groups, id, agent_id); - expect_string(__wrap_wdb_set_agent_groups, mode, "override"); - expect_string(__wrap_wdb_set_agent_groups, sync_status, "synced"); - will_return(__wrap_wdb_set_agent_groups, OS_SUCCESS); - // Closing group file - expect_value(__wrap_fclose, _File, fp_group_file); - will_return(__wrap_fclose, OS_SUCCESS); - - ret = wm_sync_group_file(group_file, group_file_path); - - assert_int_equal(ret, OS_SUCCESS); - os_free(groups_in_file); -} - -void test_wm_sync_group_file_success_max_groups(void **state) { - int ret = OS_INVALID; - const char *group_file = "001"; - const char *group_file_path = GROUPS_DIR "/001"; - int agent_id = atoi(group_file); - FILE *fp_group_file = (FILE *)1; - - // Generating a CSV groups string with 128 groups - char *groups_in_file = generate_groups_csv_string(MAX_GROUPS_PER_MULTIGROUP); - - // Agent groups file opened succesfully - expect_string(__wrap_wfopen, path, group_file_path); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, fp_group_file); - // Reading the file - will_return(__wrap_fgets, groups_in_file); - expect_value(__wrap_fgets, __stream, fp_group_file); - // Setting groups - will_return(__wrap_w_is_single_node, 1); - expect_value(__wrap_wdb_set_agent_groups, id, agent_id); - expect_string(__wrap_wdb_set_agent_groups, mode, "override"); - expect_string(__wrap_wdb_set_agent_groups, sync_status, "synced"); - will_return(__wrap_wdb_set_agent_groups, OS_SUCCESS); - // Closing group file - expect_value(__wrap_fclose, _File, fp_group_file); - will_return(__wrap_fclose, OS_SUCCESS); - - ret = wm_sync_group_file(group_file, group_file_path); - - assert_int_equal(ret, OS_SUCCESS); - os_free(groups_in_file); -} - -/* Tests wm_sync_legacy_groups_files */ - -void test_wm_sync_legacy_groups_files_error_opening_groups_dir(void **state) { - // Error opening groups directory - will_return(__wrap_opendir, NULL); - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Couldn't open directory 'queue/agent-groups': ERROR."); - - wm_sync_legacy_groups_files(); -} - -void test_wm_sync_legacy_groups_files_success_files_worker_error_dir(void **state) { - DIR *dir = (DIR *)1; - struct dirent *dir_ent = NULL; - os_calloc(1, sizeof(struct dirent), dir_ent); - strncpy(dir_ent->d_name, "001\0", 11); - - // Opening groups directory and iterating files - will_return(__wrap_opendir, dir); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning directory 'queue/agent-groups'."); - will_return(__wrap_readdir, dir_ent); - is_worker = 1; - - // Logging result, removing agent groups file, and finalizing the dir iteration - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Group file 'queue/agent-groups/001' won't be synced in a worker node, removing."); - expect_string(__wrap_unlink, file, "queue/agent-groups/001"); - will_return(__wrap_unlink, OS_SUCCESS); - will_return(__wrap_readdir, NULL); - - // Error removing the groups directory - expect_string(__wrap_rmdir_ex, name, GROUPS_DIR); - will_return(__wrap_rmdir_ex, OS_INVALID); - will_return(__wrap_strerror, "ERROR"); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unable to remove directory 'queue/agent-groups': 'ERROR' (39)"); - - wm_sync_legacy_groups_files(); - - os_free(dir_ent); -} - -void test_wm_sync_legacy_groups_files_success_files_success_dir(void **state) { - DIR *dir = (DIR *)1; - struct dirent *dir_ent = NULL; - os_calloc(1, sizeof(struct dirent), dir_ent); - strncpy(dir_ent->d_name, "001\0", 11); - - // Opening groups directory and iterating files - will_return(__wrap_opendir, dir); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning directory 'queue/agent-groups'."); - will_return(__wrap_readdir, dir_ent); - is_worker = 0; - - // Preparing data for the call to wm_sync_group_file - const char *group_file = "001"; - const char *group_file_path = GROUPS_DIR "/001"; - int agent_id = atoi(group_file); - FILE *fp_group_file = (FILE *)1; - // Generating a CSV groups string with 128 groups - char *groups_in_file = generate_groups_csv_string(MAX_GROUPS_PER_MULTIGROUP); - // Calling wm_sync_group_file - // Agent groups file opened succesfully - expect_string(__wrap_wfopen, path, group_file_path); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, fp_group_file); - // Reading the file - will_return(__wrap_fgets, groups_in_file); - expect_value(__wrap_fgets, __stream, fp_group_file); - // Setting groups - will_return(__wrap_w_is_single_node, 1); - expect_value(__wrap_wdb_set_agent_groups, id, agent_id); - expect_string(__wrap_wdb_set_agent_groups, mode, "override"); - expect_string(__wrap_wdb_set_agent_groups, sync_status, "synced"); - will_return(__wrap_wdb_set_agent_groups, OS_SUCCESS); - // Closing group file - expect_value(__wrap_fclose, _File, fp_group_file); - will_return(__wrap_fclose, OS_SUCCESS); - - // Logging result, removing agent groups file, and finalizing the dir iteration - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Group file 'queue/agent-groups/001' successfully synced, removing."); - expect_string(__wrap_unlink, file, "queue/agent-groups/001"); - will_return(__wrap_unlink, OS_SUCCESS); - will_return(__wrap_readdir, NULL); - - // Removing the groups directory - expect_string(__wrap_rmdir_ex, name, GROUPS_DIR); - will_return(__wrap_rmdir_ex, OS_SUCCESS); - - wm_sync_legacy_groups_files(); - - os_free(groups_in_file); - os_free(dir_ent); -} - -void test_wm_sync_legacy_groups_files_error_files(void **state) { - DIR *dir = (DIR *)1; - struct dirent *dir_ent = NULL; - os_calloc(1, sizeof(struct dirent), dir_ent); - strncpy(dir_ent->d_name, "001\0", 11); - - // Opening groups directory and iterating files - will_return(__wrap_opendir, dir); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning directory 'queue/agent-groups'."); - will_return(__wrap_readdir, dir_ent); - is_worker = 0; - - // Preparing data for the call to wm_sync_group_file - const char *group_file_path = GROUPS_DIR "/001"; - // Calling wm_sync_group_file - // Error opening agent groups file specified by 'group_file_path' - expect_string(__wrap_wfopen, path, group_file_path); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Groups file 'queue/agent-groups/001' could not be opened for syncronization."); - - // Logging result and finalizing the dir iteration - expect_string(__wrap__merror, formatted_msg, "Failed during the groups file 'queue/agent-groups/001' syncronization."); - will_return(__wrap_readdir, NULL); - - wm_sync_legacy_groups_files(); - - os_free(dir_ent); -} - -/* Tests sync_keys_with_wdb */ - -void test_sync_keys_with_wdb_insert(void **state) { - keystore keys = *((keystore *)*state); - keys.keysize = 1; - - rb_tree *tree = NULL; - os_calloc(1, sizeof(rb_tree), tree); - - char *test_ip = "1.1.1.1"; - - char **ids = NULL; - ids = os_AddStrArray("001", ids); - - expect_value(__wrap_wdb_get_all_agents_rbtree, include_manager, 0); - will_return(__wrap_wdb_get_all_agents_rbtree, tree); - - expect_value(__wrap_rbtree_get, tree, tree); - expect_string(__wrap_rbtree_get, key, keys.keyentries[0]->id); - will_return(__wrap_rbtree_get, NULL); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug2, formatted_msg, "Synchronizing agent 001 'agent1'."); - - expect_any(__wrap_OS_CIDRtoStr, ip); - expect_value(__wrap_OS_CIDRtoStr, size, IPSIZE); - will_return(__wrap_OS_CIDRtoStr, test_ip); - will_return(__wrap_OS_CIDRtoStr, 0); - - expect_value(__wrap_wdb_insert_agent, id, 1); - expect_string(__wrap_wdb_insert_agent, name, keys.keyentries[0]->name); - expect_string(__wrap_wdb_insert_agent, register_ip, test_ip); - expect_string(__wrap_wdb_insert_agent, internal_key, keys.keyentries[0]->raw_key); - expect_value(__wrap_wdb_insert_agent, keep_date, 1); - will_return(__wrap_wdb_insert_agent, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Couldn't insert agent '001' in the database."); - - will_return(__wrap_rbtree_keys, ids); - - expect_string(__wrap_OS_IsAllowedID, id, keys.keyentries[0]->id); - will_return(__wrap_OS_IsAllowedID, 0); - - sync_keys_with_wdb(&keys); -} - -void test_sync_keys_with_wdb_delete(void **state) { - keystore keys = *((keystore *)*state); - keys.keysize = 1; - - rb_tree *tree = NULL; - os_calloc(1, sizeof(rb_tree), tree); - - char **ids = NULL; - ids = os_AddStrArray("001", ids); - - char *test_name = strdup("TESTNAME"); - - expect_value(__wrap_wdb_get_all_agents_rbtree, include_manager, 0); - will_return(__wrap_wdb_get_all_agents_rbtree, tree); - - expect_value(__wrap_rbtree_get, tree, tree); - expect_string(__wrap_rbtree_get, key, keys.keyentries[0]->id); - will_return(__wrap_rbtree_get, 1); - - will_return(__wrap_rbtree_keys, ids); - - expect_string(__wrap_OS_IsAllowedID, id, keys.keyentries[0]->id); - will_return(__wrap_OS_IsAllowedID, -1); - - expect_value(__wrap_wdb_get_agent_name, id, 1); - will_return(__wrap_wdb_get_agent_name, test_name); - - expect_value(__wrap_wdb_remove_agent, id, 1); - will_return(__wrap_wdb_remove_agent, -1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Couldn't remove agent '001' from the database."); - - sync_keys_with_wdb(&keys); -} - -void test_sync_keys_with_wdb_insert_delete(void **state) { - keystore keys = *((keystore *)*state); - keys.keysize = 1; - - rb_tree *tree = NULL; - os_calloc(1, sizeof(rb_tree), tree); - - char *test_ip = "1.1.1.1"; - char *test_name = strdup("TESTNAME"); - - char **ids = NULL; - ids = os_AddStrArray("001", ids); - - expect_value(__wrap_wdb_get_all_agents_rbtree, include_manager, 0); - will_return(__wrap_wdb_get_all_agents_rbtree, tree); - - expect_value(__wrap_rbtree_get, tree, tree); - expect_string(__wrap_rbtree_get, key, keys.keyentries[0]->id); - will_return(__wrap_rbtree_get, NULL); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug2, formatted_msg, "Synchronizing agent 001 'agent1'."); - - expect_any(__wrap_OS_CIDRtoStr, ip); - expect_value(__wrap_OS_CIDRtoStr, size, IPSIZE); - will_return(__wrap_OS_CIDRtoStr, test_ip); - will_return(__wrap_OS_CIDRtoStr, 0); - - expect_value(__wrap_wdb_insert_agent, id, 1); - expect_string(__wrap_wdb_insert_agent, name, keys.keyentries[0]->name); - expect_string(__wrap_wdb_insert_agent, register_ip, test_ip); - expect_string(__wrap_wdb_insert_agent, internal_key, keys.keyentries[0]->raw_key); - expect_value(__wrap_wdb_insert_agent, keep_date, 1); - will_return(__wrap_wdb_insert_agent, 0); - - will_return(__wrap_rbtree_keys, ids); - - expect_string(__wrap_OS_IsAllowedID, id, keys.keyentries[0]->id); - will_return(__wrap_OS_IsAllowedID, -1); - - expect_value(__wrap_wdb_get_agent_name, id, 1); - will_return(__wrap_wdb_get_agent_name, test_name); - - expect_value(__wrap_wdb_remove_agent, id, 1); - will_return(__wrap_wdb_remove_agent, 0); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "wazuhdb remove 1"); - expect_value(__wrap_wdbc_query_ex, len, OS_SIZE_1024); - will_return(__wrap_wdbc_query_ex, "ok"); - will_return(__wrap_wdbc_query_ex, -1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mtdebug1, formatted_msg, "Could not remove the wazuh-db DB of the agent 1."); - - expect_string(__wrap_rmdir_ex, name, "queue/diff/TESTNAME"); - will_return(__wrap_rmdir_ex, 0); - - expect_string(__wrap_unlink, file, "queue/rids/001"); - will_return(__wrap_unlink, 0); - - expect_string(__wrap_wfopen, path, "queue/agents-timestamp"); - expect_string(__wrap_wfopen, mode, "r"); - will_return(__wrap_wfopen, NULL); - - sync_keys_with_wdb(&keys); -} - -void test_sync_keys_with_wdb_null(void **state) { - keystore keys = *((keystore *)*state); - keys.keysize = 1; - - expect_value(__wrap_wdb_get_all_agents_rbtree, include_manager, 0); - will_return(__wrap_wdb_get_all_agents_rbtree, NULL); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:database"); - expect_string(__wrap__mterror, formatted_msg, "Couldn't synchronize the keystore with the DB."); - - sync_keys_with_wdb(&keys); -} - -int main() -{ - const struct CMUnitTest tests[] = { - // wm_sync_group_file - cmocka_unit_test_setup_teardown(test_wm_sync_group_file_error_agent_id, setup_wmdb, teardown_wmdb), - cmocka_unit_test_setup_teardown(test_wm_sync_group_file_error_opening_file, setup_wmdb, teardown_wmdb), - cmocka_unit_test_setup_teardown(test_wm_sync_group_file_success_empty_file, setup_wmdb, teardown_wmdb), - cmocka_unit_test_setup_teardown(test_wm_sync_group_file_success_more_than_max_groups, setup_wmdb, teardown_wmdb), - cmocka_unit_test_setup_teardown(test_wm_sync_group_file_success_max_groups, setup_wmdb, teardown_wmdb), - // wm_sync_legacy_groups_files - cmocka_unit_test_setup_teardown(test_wm_sync_legacy_groups_files_error_opening_groups_dir, setup_wmdb, teardown_wmdb), - cmocka_unit_test_setup_teardown(test_wm_sync_legacy_groups_files_success_files_worker_error_dir, setup_wmdb, teardown_wmdb), - cmocka_unit_test_setup_teardown(test_wm_sync_legacy_groups_files_success_files_success_dir, setup_wmdb, teardown_wmdb), - cmocka_unit_test_setup_teardown(test_wm_sync_legacy_groups_files_error_files, setup_wmdb, teardown_wmdb), - // sync_keys_with_wdb - cmocka_unit_test_setup_teardown(test_sync_keys_with_wdb_insert, setup_keys_to_db, teardown_keys_to_db), - cmocka_unit_test_setup_teardown(test_sync_keys_with_wdb_delete, setup_keys_to_db, teardown_keys_to_db), - cmocka_unit_test_setup_teardown(test_sync_keys_with_wdb_insert_delete, setup_keys_to_db, teardown_keys_to_db), - cmocka_unit_test_setup_teardown(test_sync_keys_with_wdb_null, setup_keys_to_db, teardown_keys_to_db), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/docker/CMakeLists.txt b/src/unit_tests/wazuh_modules/docker/CMakeLists.txt deleted file mode 100644 index 62f81d5206e..00000000000 --- a/src/unit_tests/wazuh_modules/docker/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_docker") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror \ - -Wl,--wrap=_mtwarn,--wrap=_mtinfo,--wrap=_mterror,--wrap=FOREVER,--wrap=wpclose,--wrap=fgets \ - -Wl,--wrap=wpopenl,--wrap=fclose,--wrap=fflush,--wrap=fprintf,--wrap=fopen,--wrap=fread,--wrap=fseek \ - -Wl,--wrap=fwrite,--wrap=remove,--wrap=atexit -Wl,--wrap,fgetpos -Wl,--wrap=fgetc -Wl,--wrap=wfopen -Wl,--wrap,popen") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB docker ../../../wazuh_modules/*.o) -list(REMOVE_ITEM docker ../../../wazuh_modules/main.o) - -add_library(DOCKER_O STATIC ${docker}) - -set_source_files_properties( - ${docker} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - DOCKER_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(DOCKER_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - DOCKER_O - -ldl - -lcmocka - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/docker/test_wm_docker.c b/src/unit_tests/wazuh_modules/docker/test_wm_docker.c deleted file mode 100644 index 33dfb837b58..00000000000 --- a/src/unit_tests/wazuh_modules/docker/test_wm_docker.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for docker Module - * */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdio_wrappers.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/exec_op_wrappers.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../../../wazuh_modules/wm_docker.h" -#include "../scheduling/wmodules_scheduling_helpers.h" - -#define TEST_MAX_DATES 5 - -static wmodule *docker_module; -static OS_XML *lxml; -extern int test_mode; - -typedef struct { - wfd_t * wfd; - wm_docker_t* module_data; -} states; - -/******* Helpers **********/ - -static void wmodule_cleanup(wmodule *module){ - free(module->data); - free(module->tag); - free(module); -} - -/*** SETUPS/TEARDOWNS ******/ -static int setup_module() { - docker_module = calloc(1, sizeof(wmodule)); - const char *string = - "10m\n" - "10\n" - "no\n" - "no\n"; - lxml = malloc(sizeof(OS_XML)); - XML_NODE nodes = string_to_xml_node(string, lxml); - int ret = wm_docker_read(nodes, docker_module); - OS_ClearNode(nodes); - test_mode = 1; - wm_children_pool_init(); - return ret; -} - -static int teardown_module(){ - test_mode = 0; - wmodule_cleanup(docker_module); - OS_ClearXML(lxml); - return 0; -} - -static int setup_test_executions(void **state) { - states *states_ptr = calloc(1, sizeof(*states_ptr)); - states_ptr->wfd = calloc(1, sizeof(wfd_t)); - *state = states_ptr; - wm_max_eps = 1; - - return 0; -} - -static int teardown_test_executions(void **state){ - states *states_ptr = *state; - wm_docker_t* module_data = states_ptr->module_data; - sched_scan_free(&(module_data->scan_config)); - - free(states_ptr->wfd); - free(states_ptr); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wm_docker_t *module_data = (wm_docker_t*)test->module->data; - sched_scan_free(&(module_data->scan_config)); - wmodule_cleanup(test->module); - os_free(test); - return 0; -} - -/****************************************************************/ - -/** Tests **/ -void test_interval_execution(void **state) { - states *states_ptr = *state; - wm_docker_t* module_data = (wm_docker_t *)docker_module->data; - wfd_t * wfd = states_ptr->wfd; - - states_ptr->module_data = module_data; - module_data->scan_config.next_scheduled_scan_time = 0; - module_data->scan_config.scan_day = 0; - module_data->scan_config.scan_wday = -1; - module_data->scan_config.interval = 60 * 25; // 25min - module_data->scan_config.month_interval = false; - - will_return_count(__wrap_wpopenl, wfd, TEST_MAX_DATES + 1); - will_return_count(__wrap_wpclose, 0, TEST_MAX_DATES + 1); - expect_any_count(__wrap_fgets, __stream, TEST_MAX_DATES + 1); - will_return_count(__wrap_fgets, 0, TEST_MAX_DATES + 1); - will_return_count(__wrap_FOREVER, 1, TEST_MAX_DATES); - will_return(__wrap_FOREVER, 0); - expect_any_always(__wrap__mtinfo, tag); - expect_any_always(__wrap__mtinfo, formatted_msg); - expect_any_always(__wrap__mtwarn, tag); - expect_any_always(__wrap__mtwarn, formatted_msg); - - docker_module->context->start(module_data); -} - -void test_fake_tag(void **state) { - const char *string = - "\n" - "10m\n" - "10\n" - "no\n" - "no\n" - "extra\n"; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'extra-tag' at module 'docker-listener'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_docker_read(test->nodes, test->module),-1); -} - -void test_read_scheduling_monthday_configuration(void **state) { - const char *string = - "\n" - "10\n" - "10\n" - "no\n" - "no\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_docker_read(test->nodes, test->module),0); - wm_docker_t *module_data = (wm_docker_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 10); - assert_int_equal(module_data->scan_config.interval, 1); - assert_int_equal(module_data->scan_config.month_interval, true); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "19:55"); -} - -void test_read_scheduling_weekday_configuration(void **state) { - const char *string = - "\n" - "Thursday\n" - "10\n" - "no\n" - "no\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_docker_read(test->nodes, test->module),0); - wm_docker_t *module_data = (wm_docker_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 604800); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, 4); - assert_string_equal(module_data->scan_config.scan_time, "18:55"); -} - -void test_read_scheduling_daytime_configuration(void **state) { - const char *string = - "\n" - "10\n" - "no\n" - "no\n" - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one day. New interval value: 1d"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_docker_read(test->nodes, test->module),0); - wm_docker_t *module_data = (wm_docker_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "17:20"); -} - -void test_read_scheduling_interval_configuration(void **state) { - const char *string = - "1d\n" - "10\n" - "no\n" - "no\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_docker_read(test->nodes, test->module),0); - wm_docker_t *module_data = (wm_docker_t*)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); // 1 day - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); -} - -int main(void) { - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_interval_execution, setup_test_executions, teardown_test_executions) - }; - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_monthday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_weekday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_daytime_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_interval_configuration, setup_test_read, teardown_test_read), - }; - int result; - result = cmocka_run_group_tests(tests_with_startup, setup_module, teardown_module); - result += cmocka_run_group_tests(tests_without_startup, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/exec/CMakeLists.txt b/src/unit_tests/wazuh_modules/exec/CMakeLists.txt deleted file mode 100644 index 6e315eaf44c..00000000000 --- a/src/unit_tests/wazuh_modules/exec/CMakeLists.txt +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright (C) 2023, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Generate wazuh modules library -file(GLOB wm_exec ../../../wazuh_modules/wm_exec.o) - -add_library(WM_EXEC_O STATIC ${wm_exec}) - -set_source_files_properties( - ${wm_exec} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - WM_EXEC_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(WM_EXEC_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Tests list and flags -list(APPEND tests_names "test_wm_exec") -list(APPEND WM_EXEC_BASE_FLAGS "-Wl,--wrap,OSList_AddData -Wl,--wrap,OSList_DeleteThisNode \ - -Wl,--wrap,OSList_GetFirstNode -Wl,--wrap,OSList_Destroy ${DEBUG_OP_WRAPPERS}") - -if(${TARGET} STREQUAL "winagent") - list(APPEND tests_flags "${WM_EXEC_BASE_FLAGS} -Wl,--wrap,fim_db_init -Wl,--wrap=syscom_dispatch \ - -Wl,--wrap=fim_db_teardown -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap=is_fim_shutdown") -else() - list(APPEND tests_flags "${WM_EXEC_BASE_FLAGS} -Wl,--wrap,fork -Wl,--wrap,kill -Wl,--wrap,exit -Wl,--wrap,sleep") -endif() - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - WM_EXEC_O - ${TEST_DEPS} - ) - - if(${TARGET} STREQUAL "winagent") - target_link_libraries(${test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/exec/test_wm_exec.c b/src/unit_tests/wazuh_modules/exec/test_wm_exec.c deleted file mode 100644 index b4593be2a08..00000000000 --- a/src/unit_tests/wazuh_modules/exec/test_wm_exec.c +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright (C) 2023, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" - -#include "../../wrappers/wazuh/shared/list_op_wrappers.h" -#include "../../wrappers/posix/signal_wrappers.h" - -#define COMMAND u8"Powershell -c \"@{ winCounter = (Get-Counter '\\mémoire\\mégaoctets disponibles').CounterSamples[0] } | ConvertTo-Json -compress\"" -#define COMMAND2 u8"Powershell -c \"@{ winCounter = (Get-Counter '\\processeur(_total)\\% temps processeur').CounterSamples[0] } | ConvertTo-Json -compress\"" - - -extern OSList * wm_children_list; - -int __wrap_sleep (unsigned int __seconds) { - return mock(); -} - -pid_t __wrap_fork(void) { - return mock_type(pid_t); -} - -void __wrap_exit(__attribute__((unused))int code) { - function_called(); - return; -} - -static int setup_modules(void ** state) { - *state = NULL; - // wm_kill_timeout to default value - wm_kill_timeout = 0; - wm_children_pool_init(); - // Release list for custom usage - OSList_Destroy(wm_children_list); - test_mode = true; - wm_children_list = NULL; - return 0; -} - -static int teardown_modules(void ** state) { - // wm_kill_timeout to default value - wm_kill_timeout = 0; - test_mode = false; - return 0; -} - -static void test_wm_exec_accented_command(void ** state) { -#ifdef WIN32 - size_t size = mbstowcs(NULL, COMMAND, 0); - wchar_t *wcommand = calloc(size, sizeof(wchar_t)); - mbstowcs(wcommand, COMMAND, size); - - expect_any(__wrap__mdebug2, formatted_msg); - expect_string(wrap_CreateProcessW, lpCommandLine, wcommand); - will_return(wrap_CreateProcessW, TRUE); - expect_any(wrap_WaitForSingleObject, hMutex); - expect_any(wrap_WaitForSingleObject, value); - will_return(wrap_WaitForSingleObject, 0); - expect_any(wrap_CloseHandle, hObject); - will_return(wrap_CloseHandle, FALSE); - expect_any(wrap_CloseHandle, hObject); - will_return(wrap_CloseHandle, FALSE); - assert_int_equal(0, wm_exec(COMMAND, NULL, NULL, 0, NULL)); - - free(wcommand); -#else - printf("not implemented yet!\n"); -#endif -} - -static void test_wm_exec_not_accented_command(void ** state) { -#ifdef WIN32 - size_t size = mbstowcs(NULL, COMMAND2, 0); - wchar_t *wcommand = calloc(size, sizeof(wchar_t)); - mbstowcs(wcommand, COMMAND2, size); - - expect_any(__wrap__mdebug2, formatted_msg); - expect_string(wrap_CreateProcessW, lpCommandLine, wcommand); - will_return(wrap_CreateProcessW, TRUE); - expect_any(wrap_WaitForSingleObject, hMutex); - expect_any(wrap_WaitForSingleObject, value); - will_return(wrap_WaitForSingleObject, 0); - expect_any(wrap_CloseHandle, hObject); - will_return(wrap_CloseHandle, FALSE); - expect_any(wrap_CloseHandle, hObject); - will_return(wrap_CloseHandle, FALSE); - assert_int_equal(0, wm_exec(COMMAND2, NULL, NULL, 0, NULL)); - - free(wcommand); -#else - printf("not implemented yet!\n"); -#endif -} - -#ifndef TEST_WINAGENT -static void test_wm_append_sid_null_list(void ** state) { - pid_t sid = 1234; - wm_children_list = NULL; // NULL List - - wm_append_sid(sid); -} - -static void test_wm_append_sid_fail(void ** state) { - pid_t sid = 1234; - wm_children_list = (OSList *)1; // NON-NULL List - - will_return(__wrap_OSList_AddData, false); - will_return(__wrap_OSList_AddData, NULL); - - expect_string(__wrap__merror, formatted_msg, "Child process ID 1234 could not be registered in the children list."); - - wm_append_sid(sid); -} - -static void test_wm_append_sid_success(void ** state) { - pid_t sid = 1234; - OSListNode * node; - wm_children_list = (OSList *)1; // NON-NULL List - - will_return(__wrap_OSList_AddData, true); - will_return(__wrap_OSList_AddData, (void *)1); - - wm_append_sid(sid); -} - -static void test_wm_remove_sid_null_list(void ** state) { - pid_t sid = 1234; - wm_children_list = NULL; // NULL List - - wm_remove_sid(sid); -} - -static void test_wm_remove_sid_not_found(void ** state) { - pid_t sid = 1234; - wm_children_list = (OSList *)1; // NON-NULL List - - will_return(__wrap_OSList_GetFirstNode, NULL); - - expect_string(__wrap__mwarn, formatted_msg, - "Child process ID 1234 could not be removed because it was " - "not found in the children list."); - - wm_remove_sid(sid); -} - -static void test_wm_remove_sid_success(void ** state) { - pid_t sid = 1234; - pid_t * p_sid = NULL; - OSListNode * node = NULL; - wm_children_list = (OSList *)1; // NON-NULL List - - os_calloc(1, sizeof(pid_t), p_sid); - *p_sid = sid; - node = (OSListNode *) calloc(1, sizeof(OSListNode)); - node->data = p_sid; - - will_return(__wrap_OSList_GetFirstNode, node); - expect_function_call(__wrap_OSList_DeleteThisNode); - - wm_remove_sid(sid); - - os_free(node); -} - -static void test_wm_kill_children_fork_failed(void ** state) { - pid_t sid = 1234; - pid_t * p_sid = NULL; - OSListNode * node = NULL; - - wm_children_list = OSList_Create(); - OSList_SetFreeDataPointer(wm_children_list, free); - - os_calloc(1, sizeof(pid_t), p_sid); - *p_sid = sid; - node = (OSListNode *) calloc(1, sizeof(OSListNode)); - node->data = p_sid; - - will_return(__wrap_OSList_GetFirstNode, node); - - pid_t pidError = -1; - will_return(__wrap_fork, pidError); - errno = 13; - - wm_kill_timeout = 1; - - expect_string(__wrap__merror, formatted_msg, "wm_kill_children(): Couldn't fork: (13) Permission denied."); - - test_mode = false; - - wm_kill_children(sid); - - os_free(p_sid); - os_free(node); - - OSList_Destroy(wm_children_list); - wm_children_list = NULL; -} - -static void test_wm_kill_children_timeout_kill_child(void ** state) { - pid_t sid = 1234; - pid_t * p_sid = NULL; - OSListNode * node = NULL; - - wm_children_list = OSList_Create(); - OSList_SetFreeDataPointer(wm_children_list, free); - - wm_kill_timeout = 1; - - os_calloc(1, sizeof(pid_t), p_sid); - *p_sid = sid; - node = (OSListNode *) calloc(1, sizeof(OSListNode)); - node->data = p_sid; - - will_return(__wrap_OSList_GetFirstNode, node); - - pid_t pidOk = 0; - will_return(__wrap_fork, pidOk); - - expect_value(__wrap_kill,pid,sid*(-1)); - expect_value(__wrap_kill,sig,SIGTERM); - will_return(__wrap_kill,0); - - will_return(__wrap_sleep, OS_SUCCESS); - - expect_value(__wrap_kill,pid,sid*(-1)); - expect_value(__wrap_kill,sig,0); - will_return(__wrap_kill,-1); - - errno = 3; - - expect_function_call(__wrap_exit); - - expect_string(__wrap__merror, formatted_msg, "wm_kill_children(): Couldn't wait PID 1234: (3) No such process."); - - expect_function_call(__wrap_exit); - - expect_string(__wrap__mdebug1, formatted_msg, "Killing process group 1234"); - - expect_value(__wrap_kill,pid,sid*(-1)); - expect_value(__wrap_kill,sig,SIGKILL); - will_return(__wrap_kill,0); - - expect_function_call(__wrap_exit); - - test_mode = false; - - wm_kill_children(sid); - - os_free(p_sid); - os_free(node); - - OSList_Destroy(wm_children_list); - wm_children_list = NULL; -} - -static void test_wm_kill_children_parent(void ** state) { - pid_t sid = 1234; - pid_t * p_sid = NULL; - OSListNode * node = NULL; - - wm_children_list = OSList_Create(); - OSList_SetFreeDataPointer(wm_children_list, free); - - os_calloc(1, sizeof(pid_t), p_sid); - *p_sid = sid; - node = (OSListNode *) calloc(1, sizeof(OSListNode)); - node->data = p_sid; - - will_return(__wrap_OSList_GetFirstNode, node); - - expect_value(__wrap_kill,pid,sid*(-1)); - expect_value(__wrap_kill,sig,SIGKILL); - will_return(__wrap_kill,0); - - test_mode = false; - - wm_kill_children(sid); - - os_free(p_sid); - os_free(node); - - OSList_Destroy(wm_children_list); - wm_children_list = NULL; -} - -#else -static void test_wm_append_handle_null_list(void ** state) { - HANDLE hProcess = (HANDLE)0x00112233; - wm_children_list = NULL; // NULL List - - wm_append_handle(hProcess); -} - -static void test_wm_append_handle_fail(void ** state) { - HANDLE hProcess = (HANDLE)0x00112233; - wm_children_list = (OSList *)1; // NON-NULL List - - - will_return(__wrap_OSList_AddData, false); - will_return(__wrap_OSList_AddData, NULL); - - expect_string(__wrap__merror, formatted_msg, - "Child process handle 00112233 could not be registered in the " - "children list."); - - wm_append_handle(hProcess); -} - -static void test_wm_append_handle_success(void ** state) { - HANDLE hProcess = (HANDLE)0x00112233; - OSListNode * node; - wm_children_list = (OSList *)1; // NON-NULL List - - will_return(__wrap_OSList_AddData, true); - will_return(__wrap_OSList_AddData, node); - - wm_append_handle(hProcess); -} - -static void test_wm_remove_handle_null_list(void ** state) { - HANDLE hProccess = (HANDLE)0x00112233; - wm_children_list = NULL; // NULL List - - wm_remove_handle(hProccess); -} - -static void test_wm_remove_handle_not_found(void ** state) { - HANDLE hProcces = (HANDLE)0x00112233; - wm_children_list = (OSList *)1; // NON-NULL List - - will_return(__wrap_OSList_GetFirstNode, NULL); - - expect_string(__wrap__mwarn, formatted_msg, - "Child process handle 00112233 could not be removed because " - "it was not found in the children list."); - - wm_remove_handle(hProcces); -} - -static void test_wm_remove_handle_success(void ** state) { - HANDLE hProcess = (HANDLE)0x00112233; - HANDLE * p_hProcess = NULL; - OSListNode * node = NULL; - wm_children_list = (OSList *)1; // NON-NULL List - - os_calloc(1, sizeof(HANDLE), p_hProcess); - *p_hProcess = hProcess; - node = (OSListNode *) calloc(1, sizeof(OSListNode)); - node->data = p_hProcess; - - will_return(__wrap_OSList_GetFirstNode, node); - expect_function_call(__wrap_OSList_DeleteThisNode); - - wm_remove_handle(hProcess); - - os_free(node); -} - -static void test_wm_kill_children_with_empty_list(void ** state) { - wm_children_list = NULL; // NULL List - - test_mode = false; - - wm_kill_children(); -} - -static void test_wm_kill_children_with_empty_node(void ** state) { - OSListNode * node = NULL; - - wm_children_list = OSList_Create(); - OSList_SetFreeDataPointer(wm_children_list, free); - - node = (OSListNode *) calloc(1, sizeof(OSListNode)); - node->data = NULL; - - will_return(__wrap_OSList_GetFirstNode, node); - - test_mode = false; - - wm_kill_children(); - - os_free(node); - - OSList_Destroy(wm_children_list); - wm_children_list = NULL; -} - -static void test_wm_kill_children_with_success(void ** state) { - HANDLE hProcess = (HANDLE)10; - HANDLE * p_hProcess = NULL; - OSListNode * node = NULL; - - wm_children_list = OSList_Create(); - OSList_SetFreeDataPointer(wm_children_list, free); - - os_calloc(1, sizeof(HANDLE), p_hProcess); - *p_hProcess = hProcess; - node = (OSListNode *) calloc(1, sizeof(OSListNode)); - node->data = p_hProcess; - - will_return(__wrap_OSList_GetFirstNode, node); - - expect_function_call(wrap_TerminateProcess); - will_return(wrap_TerminateProcess, true); - - test_mode = false; - - wm_kill_children(); - - os_free(p_hProcess); - os_free(node); - - OSList_Destroy(wm_children_list); - wm_children_list = NULL; -} - -#endif - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_wm_exec_accented_command), - cmocka_unit_test(test_wm_exec_not_accented_command), -#ifndef TEST_WINAGENT - cmocka_unit_test_setup_teardown(test_wm_append_sid_null_list, NULL, NULL), - cmocka_unit_test_setup_teardown(test_wm_append_sid_fail, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_append_sid_success, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_remove_sid_null_list, NULL, NULL), - cmocka_unit_test_setup_teardown(test_wm_remove_sid_not_found, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_remove_sid_success, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_kill_children_fork_failed, setup_modules, NULL), - cmocka_unit_test_setup_teardown(test_wm_kill_children_timeout_kill_child, setup_modules, NULL), - cmocka_unit_test_setup_teardown(test_wm_kill_children_parent, setup_modules, NULL) -#else - cmocka_unit_test_setup_teardown(test_wm_append_handle_null_list, NULL, NULL), - cmocka_unit_test_setup_teardown(test_wm_append_handle_fail, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_append_handle_success, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_remove_handle_null_list, NULL, NULL), - cmocka_unit_test_setup_teardown(test_wm_remove_handle_not_found, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_remove_handle_success, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_wm_kill_children_with_empty_list, setup_modules, NULL), - cmocka_unit_test_setup_teardown(test_wm_kill_children_with_empty_node, setup_modules, NULL), - cmocka_unit_test_setup_teardown(test_wm_kill_children_with_success, setup_modules, NULL) -#endif - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/gcp/CMakeLists.txt b/src/unit_tests/wazuh_modules/gcp/CMakeLists.txt deleted file mode 100644 index 5bc48d2249d..00000000000 --- a/src/unit_tests/wazuh_modules/gcp/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Tests list and flags -list(APPEND tests_names "test_wm_gcp") -list(APPEND tests_flags "-Wl,--wrap,wm_exec \ - -Wl,--wrap,sched_scan_dump,--wrap,sched_scan_get_time_until_next_scan \ - -Wl,--wrap,cJSON_CreateObject -Wl,--wrap,FOREVER,--wrap,w_get_timestamp \ - -Wl,--wrap,w_sleep_until,--wrap,isDebug ${DEBUG_OP_WRAPPERS}") -list(APPEND use_shared_libs 0) - -list(APPEND tests_names "test_wmodules_gcp") -list(APPEND tests_flags "-Wl,--wrap,sched_scan_read,--wrap,realpath,--wrap,IsFile,--wrap,atexit -Wl,--wrap,wfopen ${DEBUG_OP_WRAPPERS}") -list(APPEND use_shared_libs 0) - -# Generate wazuh modules library -file(GLOB gcp ../../../wazuh_modules/*.o ../../../config/*.o) -list(REMOVE_ITEM gcp ../../../wazuh_modules/main.o) - -add_library(GCP_O STATIC ${gcp}) - -set_source_files_properties( - ${gcp} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - GCP_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(GCP_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - GCP_O - -ldl - -lcmocka - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/gcp/test_wm_gcp.c b/src/unit_tests/wazuh_modules/gcp/test_wm_gcp.c deleted file mode 100644 index a3617001580..00000000000 --- a/src/unit_tests/wazuh_modules/gcp/test_wm_gcp.c +++ /dev/null @@ -1,2557 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/wm_gcp.h" -#include "../../headers/defs.h" -#include "../../wrappers/externals/cJSON/cJSON_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/schedule_scan_wrappers.h" -#include "../../wrappers/wazuh/shared/time_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" - -void wm_gcp_pubsub_run(const wm_gcp_pubsub *data); -cJSON *wm_gcp_pubsub_dump(const wm_gcp_pubsub *data); -void wm_gcp_pubsub_destroy(wm_gcp_pubsub * data); -void* wm_gcp_pubsub_main(wm_gcp_pubsub *data); - -void wm_gcp_bucket_run(wm_gcp_bucket *exec_bucket); -cJSON *wm_gcp_bucket_dump(const wm_gcp_bucket_base *data); -void wm_gcp_bucket_destroy(wm_gcp_bucket_base *data); -void* wm_gcp_bucket_main(wm_gcp_bucket_base *data); - -/* Generic setup/teardown */ -static int group_setup(void ** state) { - test_mode = 1; - return 0; -} - -static int group_teardown(void ** state) { - test_mode = 0; - return 0; -} - -/* Auxiliar structs for pubsub*/ -typedef struct __gcp_pubsub_dump_s { - wm_gcp_pubsub *config; - cJSON *dump; - cJSON *root; - cJSON *wm_wd; -}gcp_pubsub_dump_t; - -/* wraps */ -int __wrap_isDebug() { - return mock(); -} - -/* setup/teardown for pubsub*/ -static int setup_group_pubsub(void **state) { - wm_gcp_pubsub *gcp_config; - os_calloc(1, sizeof(wm_gcp_pubsub), gcp_config); - - if(gcp_config == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_config->project_id); - if(gcp_config->project_id == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_config->subscription_name); - if(gcp_config->subscription_name == NULL) - return -1; - os_calloc(OS_SIZE_1024, sizeof(char), gcp_config->credentials_file); - if(gcp_config->credentials_file == NULL) - return -1; - - *state = gcp_config; - - return 0; -} - -static int teardown_group_pubsub(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - if (gcp_config->project_id) os_free(gcp_config->project_id); - if (gcp_config->subscription_name) os_free(gcp_config->subscription_name); - if (gcp_config->credentials_file) os_free(gcp_config->credentials_file); - - os_free(gcp_config); - - return 0; -} - -static int setup_gcp_pubsub_dump(void **state) { - setup_group_pubsub(state); - - gcp_pubsub_dump_t *dump_data = calloc(1, sizeof(gcp_pubsub_dump_t)); - - if(dump_data == NULL) - return -1; - - if(dump_data->root = __real_cJSON_CreateObject(), dump_data->root == NULL) - return -1; - - if(dump_data->wm_wd = __real_cJSON_CreateObject(), dump_data->wm_wd == NULL) - return -1; - - // Move some pointers around in order to add some info for these tests - dump_data->config = *state; - *state = dump_data; - - return 0; -} - -static int teardown_gcp_pubsub_dump(void **state) { - gcp_pubsub_dump_t *dump_data = *state; - - // Make sure to keep the group information. - *state = dump_data->config; - - teardown_group_pubsub(state); - - // Free/delete everything else - cJSON_Delete(dump_data->dump); - os_free(dump_data); - - return 0; -} - -static int setup_gcp_pubsub_destroy(void **state) { - setup_group_pubsub(state); - - wm_gcp_pubsub **gcp_config; - - if(gcp_config = calloc(2, sizeof(wm_gcp_pubsub*)), gcp_config == NULL) - return -1; - - // Save the globally used gcp_config - gcp_config[1] = *state; - - // And create a new one to be destroyed by tests - if(gcp_config[0] = calloc(1, sizeof(wm_gcp_pubsub)), gcp_config[0] == NULL) - return -1; - - if(gcp_config[0]->project_id = calloc(OS_SIZE_1024, sizeof(char)), gcp_config[0]->project_id == NULL) - return -1; - - if(gcp_config[0]->subscription_name = calloc(OS_SIZE_1024, sizeof(char)), gcp_config[0]->subscription_name == NULL) - return -1; - - if(gcp_config[0]->credentials_file = calloc(OS_SIZE_1024, sizeof(char)), gcp_config[0]->credentials_file == NULL) - return -1; - - *state = gcp_config; - - return 0; -} - -static int teardown_gcp_pubsub_destroy(void **state) { - wm_gcp_pubsub **gcp_config; - - gcp_config = *state; - - // gcp_config[0] was destroyed by the test, restore the original into state - *state = gcp_config[1]; - - teardown_group_pubsub(state); - - os_free(gcp_config); - - return 0; -} - -/* Auxiliar structs for buckets*/ -typedef struct __gcp_bucket_dump_s { - wm_gcp_bucket_base *config; - cJSON *dump; - cJSON *root; - cJSON *wm_wd; - cJSON *cur_bucket; -}gcp_bucket_dump_t; - -/* setup/teardown for buckets*/ -static int setup_group_bucket(void **state) { - wm_gcp_bucket_base *gcp_config; - wm_gcp_bucket *gcp_bucket; - - os_calloc(OS_SIZE_1024, sizeof(wm_gcp_bucket_base), gcp_config); - os_calloc(OS_SIZE_1024, sizeof(wm_gcp_bucket), gcp_bucket); - - if(gcp_config == NULL) - return -1; - - if(gcp_bucket == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->bucket); - if(gcp_bucket->bucket == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->type); - if(gcp_bucket->type == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->credentials_file); - if(gcp_bucket->credentials_file == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->prefix); - if(gcp_bucket->prefix == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->only_logs_after); - if(gcp_bucket->only_logs_after == NULL) - return -1; - - gcp_bucket->remove_from_bucket = 1; - - gcp_config->buckets = gcp_bucket; - *state = gcp_config; - - return 0; -} - -static int teardown_group_bucket(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *gcp_bucket = gcp_config->buckets; - - if (gcp_bucket->bucket) os_free(gcp_bucket->bucket); - if (gcp_bucket->type) os_free(gcp_bucket->type); - if (gcp_bucket->credentials_file) os_free(gcp_bucket->credentials_file); - if (gcp_bucket->prefix) os_free(gcp_bucket->prefix); - if (gcp_bucket->only_logs_after) os_free(gcp_bucket->only_logs_after); - - os_free(gcp_bucket); - os_free(gcp_config); - - return 0; -} - -static int setup_gcp_bucket_dump(void **state) { - setup_group_bucket(state); - - gcp_bucket_dump_t *dump_data; - os_calloc(1, sizeof(gcp_bucket_dump_t), dump_data); - - if(dump_data == NULL) - return -1; - - if(dump_data->root = __real_cJSON_CreateObject(), dump_data->root == NULL) - return -1; - - if(dump_data->wm_wd = __real_cJSON_CreateObject(), dump_data->wm_wd == NULL) - return -1; - - if(dump_data->cur_bucket = __real_cJSON_CreateObject(), dump_data->cur_bucket == NULL) - return -1; - - // Move some pointers around in order to add some info for these tests - dump_data->config = *state; - *state = dump_data; - - return 0; -} - -static int teardown_gcp_bucket_dump(void **state) { - gcp_bucket_dump_t *dump_data = *state; - - // Make sure to keep the group information. - *state = dump_data->config; - - // Free/delete everything else - cJSON_Delete(dump_data->dump); - - teardown_group_bucket(state); - os_free(dump_data); - - return 0; -} - -static int setup_gcp_bucket_destroy(void **state) { - setup_group_bucket(state); - wm_gcp_bucket_base **gcp_config; - wm_gcp_bucket *gcp_bucket; - - os_calloc(OS_SIZE_1024, sizeof(wm_gcp_bucket_base*), gcp_config); - os_calloc(OS_SIZE_1024, sizeof(wm_gcp_bucket), gcp_bucket); - - if(gcp_config == NULL) - return -1; - - if(gcp_bucket == NULL) - return -1; - - // Save the globally used gcp_config - gcp_config[1] = *state; - - // And create a new one to be destroyed by tests - os_calloc(1, sizeof(wm_gcp_bucket_base), gcp_config[0]); - if(gcp_config[0] == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->bucket); - if(gcp_bucket->bucket == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->type); - if(gcp_bucket->type == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->credentials_file); - if(gcp_bucket->credentials_file == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->prefix); - if(gcp_bucket->prefix == NULL) - return -1; - - os_calloc(OS_SIZE_1024, sizeof(char), gcp_bucket->only_logs_after); - if(gcp_bucket->only_logs_after == NULL) - return -1; - - gcp_bucket->remove_from_bucket = 1; - - gcp_config[0]->buckets = gcp_bucket; - *state = gcp_config; - - return 0; -} - -static int teardown_gcp_bucket_destroy(void **state) { - wm_gcp_bucket_base **gcp_config; - - gcp_config = *state; - - // gcp_config[0] was destroyed by the test, restore the original into state - *state = gcp_config[1]; - - teardown_group_bucket(state); - - os_free(gcp_config); - - return 0; -} - - -/* tests */ -/* wm_gcp_pubsub_run */ -static void test_wm_gcp_pubsub_run_error_running_command(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 1); - - expect_string(__wrap__mterror, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "Internal error. Exiting..."); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_unknown_error(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Unknown error - This is an unknown error."); - will_return(__wrap_wm_exec, 1); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 1"); - - will_return(__wrap_isDebug, 1); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_unknown_error_no_description(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Unknown error - This is an unknown error."); - will_return(__wrap_wm_exec, 1); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 1"); - - will_return(__wrap_isDebug, 1); - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_error_parsing_args(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Error!! integration.py: error: unable to parse"); - will_return(__wrap_wm_exec, 2); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 2"); - - will_return(__wrap_isDebug, 1); - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_error_parsing_args_no_description(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Error!! But won't trigger a specific message"); - will_return(__wrap_wm_exec, 2); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 2"); - - will_return(__wrap_isDebug, 1); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_generic_error(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "ERROR: A specific error message."); - will_return(__wrap_wm_exec, 3); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 3"); - - will_return(__wrap_isDebug, 0); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_generic_error_no_description(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "A specific error message."); - will_return(__wrap_wm_exec, 3); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 3"); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_warning_message_warning(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - WARNING - This is a warning message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "This is a warning message"); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_debug_message_not_debug_discarded(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 2); - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output - This is a message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 2); - - wm_gcp_pubsub_run(gcp_config); -} - - -static void test_wm_gcp_pubsub_run_logging_debug_message_not_debug(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 2); - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - INFO - This is an info message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mtinfo, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "This is an info message"); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_info_message_info(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - INFO - This is an info message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtinfo, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "This is an info message"); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_info_message_debug(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - DEBUG - This is an info message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_info_message_warning(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - WARNING - This is a warning message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtwarn, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "This is a warning message"); - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_warning_message_error(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - ERROR - This is an error message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mterror, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is an error message"); - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_warning_multiline_message_error(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - ERROR - This is a \nmultiline\nerror message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mterror, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is a \nmultiline\nerror message"); - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_warning_multimessage_message_error(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - ERROR - This is a \nmultiline\nerror message\n" - ":gcloud_wodle:Test output - ERROR - This is the second message\n" - ":gcloud_wodle:Test output - CRITICAL - This is a critical message\n"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mterror, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is a \nmultiline\nerror message"); - expect_string(__wrap__mterror, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is the second message"); - expect_string(__wrap__mterror, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is a critical message"); - wm_gcp_pubsub_run(gcp_config); -} - -static void test_wm_gcp_pubsub_run_logging_default_message_debug(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 6"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 6"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output - DEBUG - This is an info message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - wm_gcp_pubsub_run(gcp_config); -} - -/* wm_gcp_pubsub_dump */ -static void test_wm_gcp_pubsub_dump_success_logging_debug(void **state) { - gcp_pubsub_dump_t *gcp_pubsub_dump_data = *state; - - gcp_pubsub_dump_data->config->enabled = 0; - gcp_pubsub_dump_data->config->pull_on_start = 0; - gcp_pubsub_dump_data->config->max_messages = 100; - gcp_pubsub_dump_data->config->num_threads = 2; - - snprintf(gcp_pubsub_dump_data->config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_pubsub_dump_data->config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_pubsub_dump_data->config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - will_return(__wrap_cJSON_CreateObject, gcp_pubsub_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_pubsub_dump_data->wm_wd); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_pubsub_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_pubsub_dump_data->wm_wd); - will_return(__wrap_isDebug, 2); - - gcp_pubsub_dump_data->dump = wm_gcp_pubsub_dump(gcp_pubsub_dump_data->config); - - assert_non_null(gcp_pubsub_dump_data->dump); - assert_ptr_equal(gcp_pubsub_dump_data->dump, gcp_pubsub_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_pubsub_dump_data->dump), 1); - - cJSON *gcp_pubsub = cJSON_GetObjectItem(gcp_pubsub_dump_data->dump, "gcp-pubsub"); - assert_non_null(gcp_pubsub); - assert_int_equal(cJSON_GetArraySize(gcp_pubsub), 8); - - cJSON *enabled = cJSON_GetObjectItem(gcp_pubsub, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "no"); - cJSON *pull_on_start = cJSON_GetObjectItem(gcp_pubsub, "pull_on_start"); - assert_string_equal(cJSON_GetStringValue(pull_on_start), "no"); - cJSON *max_messages = cJSON_GetObjectItem(gcp_pubsub, "max_messages"); - assert_non_null(max_messages); - assert_int_equal(max_messages->valueint, 100); - cJSON *num_threads = cJSON_GetObjectItem(gcp_pubsub, "num_threads"); - assert_non_null(num_threads); - assert_int_equal(num_threads->valueint, 2); - cJSON *project_id = cJSON_GetObjectItem(gcp_pubsub, "project_id"); - assert_string_equal(cJSON_GetStringValue(project_id), "wazuh-gcp-test"); - cJSON *subscription_name = cJSON_GetObjectItem(gcp_pubsub, "subscription_name"); - assert_string_equal(cJSON_GetStringValue(subscription_name), "wazuh-subscription-test"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_pubsub, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - - -static void test_wm_gcp_pubsub_dump_success_logging_info(void **state) { - gcp_pubsub_dump_t *gcp_pubsub_dump_data = *state; - - gcp_pubsub_dump_data->config->enabled = 1; - gcp_pubsub_dump_data->config->pull_on_start = 0; - gcp_pubsub_dump_data->config->max_messages = 100; - gcp_pubsub_dump_data->config->num_threads = 2; - - snprintf(gcp_pubsub_dump_data->config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_pubsub_dump_data->config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_pubsub_dump_data->config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - will_return(__wrap_cJSON_CreateObject, gcp_pubsub_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_pubsub_dump_data->wm_wd); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_pubsub_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_pubsub_dump_data->wm_wd); - will_return(__wrap_isDebug, 1); - - gcp_pubsub_dump_data->dump = wm_gcp_pubsub_dump(gcp_pubsub_dump_data->config); - - assert_non_null(gcp_pubsub_dump_data->dump); - assert_ptr_equal(gcp_pubsub_dump_data->dump, gcp_pubsub_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_pubsub_dump_data->dump), 1); - - cJSON *gcp_pubsub = cJSON_GetObjectItem(gcp_pubsub_dump_data->dump, "gcp-pubsub"); - assert_non_null(gcp_pubsub); - assert_int_equal(cJSON_GetArraySize(gcp_pubsub), 8); - - cJSON *enabled = cJSON_GetObjectItem(gcp_pubsub, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "yes"); - cJSON *pull_on_start = cJSON_GetObjectItem(gcp_pubsub, "pull_on_start"); - assert_string_equal(cJSON_GetStringValue(pull_on_start), "no"); - cJSON *max_messages = cJSON_GetObjectItem(gcp_pubsub, "max_messages"); - assert_non_null(max_messages); - assert_int_equal(max_messages->valueint, 100); - cJSON *num_threads = cJSON_GetObjectItem(gcp_pubsub, "num_threads"); - assert_non_null(num_threads); - assert_int_equal(num_threads->valueint, 2); - cJSON *project_id = cJSON_GetObjectItem(gcp_pubsub, "project_id"); - assert_string_equal(cJSON_GetStringValue(project_id), "wazuh-gcp-test"); - cJSON *subscription_name = cJSON_GetObjectItem(gcp_pubsub, "subscription_name"); - assert_string_equal(cJSON_GetStringValue(subscription_name), "wazuh-subscription-test"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_pubsub, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - -static void test_wm_gcp_pubsub_dump_success_logging_warning(void **state) { - gcp_pubsub_dump_t *gcp_pubsub_dump_data = *state; - - gcp_pubsub_dump_data->config->enabled = 0; - gcp_pubsub_dump_data->config->pull_on_start = 1; - gcp_pubsub_dump_data->config->max_messages = 100; - gcp_pubsub_dump_data->config->num_threads = 2; - - snprintf(gcp_pubsub_dump_data->config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_pubsub_dump_data->config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_pubsub_dump_data->config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - will_return(__wrap_cJSON_CreateObject, gcp_pubsub_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_pubsub_dump_data->wm_wd); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_pubsub_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_pubsub_dump_data->wm_wd); - will_return(__wrap_isDebug, 0); - - gcp_pubsub_dump_data->dump = wm_gcp_pubsub_dump(gcp_pubsub_dump_data->config); - - assert_non_null(gcp_pubsub_dump_data->dump); - assert_ptr_equal(gcp_pubsub_dump_data->dump, gcp_pubsub_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_pubsub_dump_data->dump), 1); - - cJSON *gcp_pubsub = cJSON_GetObjectItem(gcp_pubsub_dump_data->dump, "gcp-pubsub"); - assert_non_null(gcp_pubsub); - assert_int_equal(cJSON_GetArraySize(gcp_pubsub), 8); - - cJSON *enabled = cJSON_GetObjectItem(gcp_pubsub, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "no"); - cJSON *pull_on_start = cJSON_GetObjectItem(gcp_pubsub, "pull_on_start"); - assert_string_equal(cJSON_GetStringValue(pull_on_start), "yes"); - cJSON *max_messages = cJSON_GetObjectItem(gcp_pubsub, "max_messages"); - assert_non_null(max_messages); - assert_int_equal(max_messages->valueint, 100); - cJSON *num_threads = cJSON_GetObjectItem(gcp_pubsub, "num_threads"); - assert_non_null(num_threads); - assert_int_equal(num_threads->valueint, 2); - cJSON *project_id = cJSON_GetObjectItem(gcp_pubsub, "project_id"); - assert_string_equal(cJSON_GetStringValue(project_id), "wazuh-gcp-test"); - cJSON *subscription_name = cJSON_GetObjectItem(gcp_pubsub, "subscription_name"); - assert_string_equal(cJSON_GetStringValue(subscription_name), "wazuh-subscription-test"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_pubsub, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - -static void test_wm_gcp_pubsub_dump_error_allocating_wm_wd(void **state) { - gcp_pubsub_dump_t *gcp_pubsub_dump_data = *state; - - gcp_pubsub_dump_data->config->enabled = 0; - gcp_pubsub_dump_data->config->pull_on_start = 0; - gcp_pubsub_dump_data->config->max_messages = 100; - gcp_pubsub_dump_data->config->num_threads = 2; - - snprintf(gcp_pubsub_dump_data->config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_pubsub_dump_data->config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_pubsub_dump_data->config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - // Since we won't use wm_wd, we can just free it to prevent memory leaks. - os_free(gcp_pubsub_dump_data->wm_wd); - gcp_pubsub_dump_data->wm_wd = NULL; - - will_return(__wrap_cJSON_CreateObject, gcp_pubsub_dump_data->root); - will_return(__wrap_cJSON_CreateObject, NULL); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_pubsub_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, NULL); - will_return(__wrap_isDebug, 0); - - gcp_pubsub_dump_data->dump = wm_gcp_pubsub_dump(gcp_pubsub_dump_data->config); - - assert_non_null(gcp_pubsub_dump_data->dump); - assert_ptr_equal(gcp_pubsub_dump_data->dump, gcp_pubsub_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_pubsub_dump_data->dump), 0); -} - -static void test_wm_gcp_pubsub_dump_error_allocating_root(void **state) { - gcp_pubsub_dump_t *gcp_pubsub_dump_data = *state; - - gcp_pubsub_dump_data->config->enabled = 0; - gcp_pubsub_dump_data->config->pull_on_start = 0; - gcp_pubsub_dump_data->config->max_messages = 100; - - snprintf(gcp_pubsub_dump_data->config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_pubsub_dump_data->config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_pubsub_dump_data->config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - // Since we won't use wm_wd or root, we can just free them to prevent memory leaks. - os_free(gcp_pubsub_dump_data->wm_wd); - gcp_pubsub_dump_data->wm_wd = NULL; - - os_free(gcp_pubsub_dump_data->root); - gcp_pubsub_dump_data->root = NULL; - - will_return(__wrap_cJSON_CreateObject, NULL); - will_return(__wrap_cJSON_CreateObject, NULL); // If we cannot alloc root, wm_wd won't be alloced either. - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_pubsub_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, NULL); - will_return(__wrap_isDebug, 0); - - gcp_pubsub_dump_data->dump = wm_gcp_pubsub_dump(gcp_pubsub_dump_data->config); - - assert_null(gcp_pubsub_dump_data->dump); -} - -/* wm_gcp_pubsub_destroy */ -static void test_wm_gcp_pubsub_destroy(void **state) { - wm_gcp_pubsub **gcp_config = *state; - - // gcp_config[0] is to be destroyed by the test - wm_gcp_pubsub_destroy(gcp_config[0]); - - // No assertions are possible on this test, it's meant to be used along valgrind to check memory leaks. -} - -/* wm_gcp_pubsub_main */ -static void test_wm_gcp_pubsub_main_disabled(void **state) { - wm_gcp_pubsub *gcp_config = *state; - - gcp_config->enabled = 0; - - expect_string(__wrap__mtinfo, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module disabled. Exiting."); - - wm_gcp_pubsub_main(gcp_config); -} - -static void test_wm_gcp_pubsub_main_pull_on_start(void **state) { - wm_gcp_pubsub *gcp_config = *state; - void *ret; - - gcp_config->enabled = 1; - gcp_config->pull_on_start = 1; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - expect_string(__wrap__mtinfo, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module started."); - - expect_value(__wrap_sched_scan_get_time_until_next_scan, config, &gcp_config->scan_config); - expect_string(__wrap_sched_scan_get_time_until_next_scan, MODULE_TAG, WM_GCP_PUBSUB_LOGTAG); - expect_value(__wrap_sched_scan_get_time_until_next_scan, run_on_start, 1); - will_return(__wrap_sched_scan_get_time_until_next_scan, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Starting fetching of logs."); - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Fetching logs finished."); - - will_return(__wrap_FOREVER, 0); - will_return(__wrap_isDebug, 1); - - ret = wm_gcp_pubsub_main(gcp_config); - - assert_null(ret); -} - -static void test_wm_gcp_pubsub_main_sleep_then_run(void **state) { - wm_gcp_pubsub *gcp_config = *state; - void *ret; - - gcp_config->enabled = 1; - gcp_config->pull_on_start = 1; - - snprintf(gcp_config->project_id, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(gcp_config->subscription_name, OS_SIZE_1024, "wazuh-subscription-test"); - snprintf(gcp_config->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - - gcp_config->max_messages = 10; - gcp_config->num_threads = 2; - - int create_time = 123456789; - gcp_config->scan_config.next_scheduled_scan_time = create_time; // sleep 10 seconds - - char *create_time_timestamp = NULL; - os_strdup("20/10/21 15:35:48.111", create_time_timestamp); - - expect_string(__wrap__mtinfo, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module started."); - - expect_value(__wrap_sched_scan_get_time_until_next_scan, config, &gcp_config->scan_config); - expect_string(__wrap_sched_scan_get_time_until_next_scan, MODULE_TAG, WM_GCP_PUBSUB_LOGTAG); - expect_value(__wrap_sched_scan_get_time_until_next_scan, run_on_start, 1); - will_return(__wrap_sched_scan_get_time_until_next_scan, create_time); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Sleeping until: 20/10/21 15:35:48.111"); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Starting fetching of logs."); - - expect_string(__wrap__mtdebug2, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 2); - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type pubsub --project wazuh-gcp-test --subscription_id wazuh-subscription-test " - "--credentials_file /wazuh/credentials/test.json --max_messages 10 --num_threads 2 --log_level 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_PUBSUB_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Fetching logs finished."); - - will_return(__wrap_FOREVER, 0); - will_return(__wrap_isDebug, 2); - - ret = wm_gcp_pubsub_main(gcp_config); - - assert_null(ret); -} - -/* wm_gcp_bucket_run */ -static void test_wm_gcp_bucket_run_success(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_error_running_command(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 1); - - expect_string(__wrap__mterror, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "Internal error. Exiting..."); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_error(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Unknown error - This is an unknown error."); - will_return(__wrap_wm_exec, 1); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 1"); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_error_no_description(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "This description does not match the criteria"); - will_return(__wrap_wm_exec, 1); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 1"); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_error_parsing_args(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Error!! integration.py: error: unable to parse"); - will_return(__wrap_wm_exec, 2); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 2"); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_error_parsing_args_no_description(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Error!! But won't trigger a specific message"); - will_return(__wrap_wm_exec, 2); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 2"); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_generic_error(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "ERROR: A specific error message."); - will_return(__wrap_wm_exec, 3); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 3"); - - will_return(__wrap_isDebug, 0); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_generic_error_no_description(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test " - "--credentials_file /wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "A specific error message."); - will_return(__wrap_wm_exec, 3); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "Command returned exit code 3"); - - will_return(__wrap_isDebug, 0); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_debug_message_debug(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 2); - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - DEBUG - This is a debug message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "This is a debug message"); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_debug_message_not_debug_discarded(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 2); - will_return(__wrap_isDebug, 2); - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - This is a discarded message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 2); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_debug_message_not_debug(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 2); - will_return(__wrap_isDebug, 2); - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 2"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 2"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - INFO - This is an info message\n"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 2); - - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "This is an info message"); - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_info_message_info(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - INFO - This is an info message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "This is an info message"); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_info_message_debug(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output - DEBUG - This is an info message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_info_message_warning(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - WARNING - This is a warning message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "This is a warning message"); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_warning_message_warning(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - WARNING - This is a warning message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtwarn, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtwarn, formatted_msg, "This is a warning message"); - will_return(__wrap_isDebug, 1); - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_warning_message_debug(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - will_return(__wrap_isDebug, 0); - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output - DEBUG - This is a debug message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_warning_message_error(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - ERROR - This is an error message"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mterror, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is an error message"); - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_warning_multiline_message_error(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - ERROR - This is a\nmultiline\n error message\n"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 0); - - expect_string(__wrap__mterror, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is a\nmultiline\n error message"); - wm_gcp_bucket_run(cur_bucket); -} - -static void test_wm_gcp_bucket_run_logging_warning_multimessage_message_error(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, ":gcloud_wodle:Test output - ERROR - This is a\nmultimessage\n error message\n" - ":gcloud_wodle:Test critical - CRITICAL - This is another error message\n" - ":gcloud_wodle:Test info - INFO - This is a test info message\n"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mterror, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is a\nmultimessage\n error message"); - expect_string(__wrap__mterror, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "This is another error message"); - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "This is a test info message"); - wm_gcp_bucket_run(cur_bucket); -} - -/* wm_gcp_bucket_dump */ - -static void test_wm_gcp_bucket_dump_success_logging_debug(void **state) { - gcp_bucket_dump_t *gcp_bucket_dump_data = *state; - wm_gcp_bucket *cur_bucket = gcp_bucket_dump_data->config->buckets; - - gcp_bucket_dump_data->config->enabled = 0; - gcp_bucket_dump_data->config->run_on_start = 0; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->wm_wd); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->cur_bucket); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_bucket_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_bucket_dump_data->wm_wd); - - gcp_bucket_dump_data->dump = wm_gcp_bucket_dump(gcp_bucket_dump_data->config); - - assert_non_null(gcp_bucket_dump_data->dump); - assert_ptr_equal(gcp_bucket_dump_data->dump, gcp_bucket_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_dump_data->dump), 1); - cJSON *gcp_bucket_base = cJSON_GetObjectItem(gcp_bucket_dump_data->dump, "gcp-bucket"); - assert_non_null(gcp_bucket_base); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_base), 4); - cJSON *enabled = cJSON_GetObjectItem(gcp_bucket_base, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "no"); - cJSON *run_on_start = cJSON_GetObjectItem(gcp_bucket_base, "run_on_start"); - assert_string_equal(cJSON_GetStringValue(run_on_start), "no"); - cJSON *gcp_bucket = cJSON_GetObjectItem(gcp_bucket_dump_data->dump->child, "buckets"); - assert_non_null(gcp_bucket); - cJSON *bucket = cJSON_GetObjectItem(gcp_bucket->child, "bucket"); - assert_string_equal(cJSON_GetStringValue(bucket), "wazuh-gcp-test"); - cJSON *type = cJSON_GetObjectItem(gcp_bucket->child, "type"); - assert_string_equal(cJSON_GetStringValue(type), "access_logs"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_bucket->child, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - - -static void test_wm_gcp_bucket_dump_success_logging_info(void **state) { - gcp_bucket_dump_t *gcp_bucket_dump_data = *state; - wm_gcp_bucket *cur_bucket = gcp_bucket_dump_data->config->buckets; - - gcp_bucket_dump_data->config->enabled = 1; - gcp_bucket_dump_data->config->run_on_start = 0; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->wm_wd); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->cur_bucket); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_bucket_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_bucket_dump_data->wm_wd); - - gcp_bucket_dump_data->dump = wm_gcp_bucket_dump(gcp_bucket_dump_data->config); - - assert_non_null(gcp_bucket_dump_data->dump); - assert_ptr_equal(gcp_bucket_dump_data->dump, gcp_bucket_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_dump_data->dump), 1); - - cJSON *gcp_bucket_base = cJSON_GetObjectItem(gcp_bucket_dump_data->dump, "gcp-bucket"); - assert_non_null(gcp_bucket_base); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_base), 4); - - cJSON *enabled = cJSON_GetObjectItem(gcp_bucket_base, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "yes"); - cJSON *run_on_start = cJSON_GetObjectItem(gcp_bucket_base, "run_on_start"); - assert_string_equal(cJSON_GetStringValue(run_on_start), "no"); - - cJSON *gcp_bucket = cJSON_GetObjectItem(gcp_bucket_dump_data->dump->child, "buckets"); - assert_non_null(gcp_bucket); - cJSON *bucket = cJSON_GetObjectItem(gcp_bucket->child, "bucket"); - assert_string_equal(cJSON_GetStringValue(bucket), "wazuh-gcp-test"); - cJSON *type = cJSON_GetObjectItem(gcp_bucket->child, "type"); - assert_string_equal(cJSON_GetStringValue(type), "access_logs"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_bucket->child, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - -static void test_wm_gcp_bucket_dump_success(void **state) { - gcp_bucket_dump_t *gcp_bucket_dump_data = *state; - wm_gcp_bucket *cur_bucket = gcp_bucket_dump_data->config->buckets; - - gcp_bucket_dump_data->config->enabled = 0; - gcp_bucket_dump_data->config->run_on_start = 1; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->wm_wd); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->cur_bucket); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_bucket_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_bucket_dump_data->wm_wd); - - will_return(__wrap_isDebug, 0); - - gcp_bucket_dump_data->dump = wm_gcp_bucket_dump(gcp_bucket_dump_data->config); - - assert_non_null(gcp_bucket_dump_data->dump); - assert_ptr_equal(gcp_bucket_dump_data->dump, gcp_bucket_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_dump_data->dump), 1); - - cJSON *gcp_bucket_base = cJSON_GetObjectItem(gcp_bucket_dump_data->dump, "gcp-bucket"); - assert_non_null(gcp_bucket_base); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_base), 4); - - cJSON *enabled = cJSON_GetObjectItem(gcp_bucket_base, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "no"); - cJSON *run_on_start = cJSON_GetObjectItem(gcp_bucket_base, "run_on_start"); - assert_string_equal(cJSON_GetStringValue(run_on_start), "yes"); - cJSON *gcp_bucket = cJSON_GetObjectItem(gcp_bucket_dump_data->dump->child, "buckets"); - assert_non_null(gcp_bucket); - cJSON *bucket = cJSON_GetObjectItem(gcp_bucket->child, "bucket"); - assert_string_equal(cJSON_GetStringValue(bucket), "wazuh-gcp-test"); - cJSON *type = cJSON_GetObjectItem(gcp_bucket->child, "type"); - assert_string_equal(cJSON_GetStringValue(type), "access_logs"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_bucket->child, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - -static void test_wm_gcp_bucket_dump_success_logging_critical(void **state) { - gcp_bucket_dump_t *gcp_bucket_dump_data = *state; - wm_gcp_bucket *cur_bucket = gcp_bucket_dump_data->config->buckets; - - gcp_bucket_dump_data->config->enabled = 0; - gcp_bucket_dump_data->config->run_on_start = 0; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->wm_wd); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->cur_bucket); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_bucket_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_bucket_dump_data->wm_wd); - - gcp_bucket_dump_data->dump = wm_gcp_bucket_dump(gcp_bucket_dump_data->config); - - assert_non_null(gcp_bucket_dump_data->dump); - assert_ptr_equal(gcp_bucket_dump_data->dump, gcp_bucket_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_dump_data->dump), 1); - - cJSON *gcp_bucket_base = cJSON_GetObjectItem(gcp_bucket_dump_data->dump, "gcp-bucket"); - assert_non_null(gcp_bucket_base); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_base), 4); - - cJSON *enabled = cJSON_GetObjectItem(gcp_bucket_base, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "no"); - cJSON *run_on_start = cJSON_GetObjectItem(gcp_bucket_base, "run_on_start"); - assert_string_equal(cJSON_GetStringValue(run_on_start), "no"); - cJSON *gcp_bucket = cJSON_GetObjectItem(gcp_bucket_dump_data->dump->child, "buckets"); - assert_non_null(gcp_bucket); - cJSON *bucket = cJSON_GetObjectItem(gcp_bucket->child, "bucket"); - assert_string_equal(cJSON_GetStringValue(bucket), "wazuh-gcp-test"); - cJSON *type = cJSON_GetObjectItem(gcp_bucket->child, "type"); - assert_string_equal(cJSON_GetStringValue(type), "access_logs"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_bucket->child, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - -static void test_wm_gcp_bucket_dump_success_logging_default(void **state) { - gcp_bucket_dump_t *gcp_bucket_dump_data = *state; - wm_gcp_bucket *cur_bucket = gcp_bucket_dump_data->config->buckets; - - gcp_bucket_dump_data->config->enabled = 0; - gcp_bucket_dump_data->config->run_on_start = 0; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->wm_wd); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->cur_bucket); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_bucket_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_bucket_dump_data->wm_wd); - - gcp_bucket_dump_data->dump = wm_gcp_bucket_dump(gcp_bucket_dump_data->config); - - assert_non_null(gcp_bucket_dump_data->dump); - assert_ptr_equal(gcp_bucket_dump_data->dump, gcp_bucket_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_dump_data->dump), 1); - - cJSON *gcp_bucket_base = cJSON_GetObjectItem(gcp_bucket_dump_data->dump, "gcp-bucket"); - assert_non_null(gcp_bucket_base); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_base), 4); - - cJSON *enabled = cJSON_GetObjectItem(gcp_bucket_base, "enabled"); - assert_string_equal(cJSON_GetStringValue(enabled), "no"); - cJSON *run_on_start = cJSON_GetObjectItem(gcp_bucket_base, "run_on_start"); - assert_string_equal(cJSON_GetStringValue(run_on_start), "no"); - cJSON *gcp_bucket = cJSON_GetObjectItem(gcp_bucket_dump_data->dump->child, "buckets"); - assert_non_null(gcp_bucket); - cJSON *bucket = cJSON_GetObjectItem(gcp_bucket->child, "bucket"); - assert_string_equal(cJSON_GetStringValue(bucket), "wazuh-gcp-test"); - cJSON *type = cJSON_GetObjectItem(gcp_bucket->child, "type"); - assert_string_equal(cJSON_GetStringValue(type), "access_logs"); - cJSON *credentials_file = cJSON_GetObjectItem(gcp_bucket->child, "credentials_file"); - assert_string_equal(cJSON_GetStringValue(credentials_file), "/wazuh/credentials/test.json"); -} - -static void test_wm_gcp_bucket_dump_error_allocating_wm_wd(void **state) { - gcp_bucket_dump_t *gcp_bucket_dump_data = *state; - wm_gcp_bucket *cur_bucket = gcp_bucket_dump_data->config->buckets; - - gcp_bucket_dump_data->config->enabled = 0; - gcp_bucket_dump_data->config->run_on_start = 0; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->root); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->wm_wd); - will_return(__wrap_cJSON_CreateObject, gcp_bucket_dump_data->cur_bucket); - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_bucket_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, gcp_bucket_dump_data->wm_wd); - - will_return(__wrap_isDebug, 1); - gcp_bucket_dump_data->dump = wm_gcp_bucket_dump(gcp_bucket_dump_data->config); - - assert_non_null(gcp_bucket_dump_data->dump); - assert_ptr_equal(gcp_bucket_dump_data->dump, gcp_bucket_dump_data->root); - assert_int_equal(cJSON_GetArraySize(gcp_bucket_dump_data->dump), 1); -} - -static void test_wm_gcp_bucket_dump_error_allocating_root(void **state) { - gcp_bucket_dump_t *gcp_bucket_dump_data = *state; - wm_gcp_bucket *cur_bucket = gcp_bucket_dump_data->config->buckets; - - gcp_bucket_dump_data->config->enabled = 0; - gcp_bucket_dump_data->config->run_on_start = 0; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - // Since we won't use wm_wd or root, we can just free them to prevent memory leaks. - os_free(gcp_bucket_dump_data->wm_wd); - gcp_bucket_dump_data->wm_wd = NULL; - - os_free(gcp_bucket_dump_data->root); - gcp_bucket_dump_data->root = NULL; - - os_free(gcp_bucket_dump_data->cur_bucket); - gcp_bucket_dump_data->cur_bucket = NULL; - - will_return(__wrap_cJSON_CreateObject, NULL); - will_return(__wrap_cJSON_CreateObject, NULL); - will_return(__wrap_cJSON_CreateObject, NULL); // If we cannot alloc root, wm_wd won't be alloced either. - - expect_value(__wrap_sched_scan_dump, scan_config, &gcp_bucket_dump_data->config->scan_config); - expect_value(__wrap_sched_scan_dump, cjson_object, NULL); - - will_return(__wrap_isDebug, 1); - gcp_bucket_dump_data->dump = wm_gcp_bucket_dump(gcp_bucket_dump_data->config); - - assert_null(gcp_bucket_dump_data->dump); -} - -/* wm_gcp_bucket_destroy */ -static void test_wm_gcp_bucket_destroy(void **state) { - wm_gcp_bucket_base **gcp_config = *state; - - // gcp_config[0] is to be destroyed by the test - wm_gcp_bucket_destroy(gcp_config[0]); - - // No assertions are possible on this test, it's meant to be used along valgrind to check memory leaks. -} - -/* wm_gcp_bucket_main */ -static void test_wm_gcp_bucket_main_disabled(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - - gcp_config->enabled = 0; - - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module disabled. Exiting."); - - wm_gcp_bucket_main(gcp_config); -} - -static void test_wm_gcp_bucket_main_run_on_start(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - void *ret; - - snprintf(cur_bucket->bucket, OS_SIZE_1024, "wazuh-gcp-test"); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - gcp_config->enabled = 1; - gcp_config->run_on_start = 1; - - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module started."); - - expect_value(__wrap_sched_scan_get_time_until_next_scan, config, &gcp_config->scan_config); - expect_string(__wrap_sched_scan_get_time_until_next_scan, MODULE_TAG, WM_GCP_BUCKET_LOGTAG); - expect_value(__wrap_sched_scan_get_time_until_next_scan, run_on_start, 1); - will_return(__wrap_sched_scan_get_time_until_next_scan, 0); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Starting fetching of logs."); - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name wazuh-gcp-test --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Executing Bucket Analysis: (Bucket: wazuh-gcp-test, " - "Path: access_logs/, Type: access_logs, Credentials file: /wazuh/credentials/test.json)"); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Fetching logs finished."); - - will_return(__wrap_FOREVER, 0); - - - ret = wm_gcp_bucket_main(gcp_config); - - assert_null(ret); -} - -static void test_wm_gcp_bucket_main_sleep_then_run(void **state) { - wm_gcp_bucket_base *gcp_config = *state; - wm_gcp_bucket *cur_bucket = gcp_config->buckets; - void *ret; - - os_free(cur_bucket->bucket); - snprintf(cur_bucket->type, OS_SIZE_1024, "access_logs"); - snprintf(cur_bucket->credentials_file, OS_SIZE_1024, "/wazuh/credentials/test.json"); - snprintf(cur_bucket->prefix, OS_SIZE_1024, "access_logs/"); - snprintf(cur_bucket->only_logs_after, OS_SIZE_1024, "2021-JAN-01"); - - cur_bucket->remove_from_bucket = 1; // enabled - gcp_config->enabled = 1; - gcp_config->run_on_start = 1; - - int create_time = 123456789; - gcp_config->scan_config.next_scheduled_scan_time = create_time; // sleep 10 seconds - - char *create_time_timestamp = NULL; - os_strdup("20/10/21 15:35:48.111", create_time_timestamp); - - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module started."); - - expect_value(__wrap_sched_scan_get_time_until_next_scan, config, &gcp_config->scan_config); - expect_string(__wrap_sched_scan_get_time_until_next_scan, MODULE_TAG, WM_GCP_BUCKET_LOGTAG); - expect_value(__wrap_sched_scan_get_time_until_next_scan, run_on_start, 1); - will_return(__wrap_sched_scan_get_time_until_next_scan, create_time); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Sleeping until: 20/10/21 15:35:48.111"); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Starting fetching of logs."); - - expect_string(__wrap__mtdebug2, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug2, formatted_msg, "Create argument list"); - - will_return(__wrap_isDebug, 1); - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Launching command: " - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - - expect_string(__wrap_wm_exec, command, - "wodles/gcloud/gcloud --integration_type access_logs --bucket_name --credentials_file " - "/wazuh/credentials/test.json --prefix access_logs/ --only_logs_after 2021-JAN-01 --remove --log_level 1"); - expect_value(__wrap_wm_exec, secs, 0); - expect_value(__wrap_wm_exec, add_path, NULL); - - will_return(__wrap_wm_exec, "Test output"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_string(__wrap__mtinfo, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Executing Bucket Analysis: (Bucket: unknown_bucket, " - "Path: access_logs/, Type: access_logs, Credentials file: /wazuh/credentials/test.json)"); - - will_return(__wrap_isDebug, 1); - - expect_string(__wrap__mtdebug1, tag, WM_GCP_BUCKET_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Fetching logs finished."); - - will_return(__wrap_FOREVER, 0); - - ret = wm_gcp_bucket_main(gcp_config); - - assert_null(ret); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - /* wm_gcp_pubsub_run */ - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_error_running_command, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_unknown_error, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_unknown_error_no_description, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_error_parsing_args, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_error_parsing_args_no_description, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_generic_error, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_generic_error_no_description, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_warning_message_warning, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_warning_multiline_message_error, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_warning_multimessage_message_error, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_debug_message_not_debug, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_debug_message_not_debug_discarded, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_info_message_info, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_info_message_debug, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_info_message_warning, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_warning_message_warning, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_run_logging_warning_message_error, setup_group_pubsub, teardown_group_pubsub), - - /* wm_gcp_pubsub_dump */ - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_dump_success_logging_debug, setup_gcp_pubsub_dump, teardown_gcp_pubsub_dump), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_dump_success_logging_info, setup_gcp_pubsub_dump, teardown_gcp_pubsub_dump), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_dump_success_logging_warning, setup_gcp_pubsub_dump, teardown_gcp_pubsub_dump), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_dump_error_allocating_wm_wd, setup_gcp_pubsub_dump, teardown_gcp_pubsub_dump), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_dump_error_allocating_root, setup_gcp_pubsub_dump, teardown_gcp_pubsub_dump), - - /* wm_gcp_pubsub_destroy */ - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_destroy, setup_gcp_pubsub_destroy, teardown_gcp_pubsub_destroy), - - /* wm_gcp_pubsub_main */ - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_main_disabled, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_main_pull_on_start, setup_group_pubsub, teardown_group_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_main_sleep_then_run, setup_group_pubsub, teardown_group_pubsub), - - /* wm_gcp_bucket_run */ - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_success, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_error_running_command, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_error, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_error_no_description, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_error_parsing_args, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_error_parsing_args_no_description, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_generic_error, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_generic_error_no_description, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_debug_message_debug, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_debug_message_not_debug, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_debug_message_not_debug_discarded, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_info_message_info, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_info_message_debug, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_info_message_warning, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_warning_message_warning, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_warning_message_debug, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_warning_message_error, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_warning_multiline_message_error, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_run_logging_warning_multimessage_message_error, setup_group_bucket, teardown_group_bucket), - - /* wm_gcp_bucket_dump */ - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_dump_success, setup_gcp_bucket_dump, teardown_gcp_bucket_dump), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_dump_error_allocating_wm_wd, setup_gcp_bucket_dump, teardown_gcp_bucket_dump), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_dump_error_allocating_root, setup_gcp_bucket_dump, teardown_gcp_bucket_dump), - - /* wm_gcp_bucket_destroy */ - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_destroy, setup_gcp_bucket_destroy, teardown_gcp_bucket_destroy), - - /* wm_gcp_bucket_main */ - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_main_disabled, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_main_run_on_start, setup_group_bucket, teardown_group_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_main_sleep_then_run, setup_group_bucket, teardown_group_bucket), - }; - return cmocka_run_group_tests(tests, group_setup, group_teardown); -} diff --git a/src/unit_tests/wazuh_modules/gcp/test_wmodules_gcp.c b/src/unit_tests/wazuh_modules/gcp/test_wmodules_gcp.c deleted file mode 100644 index 17a0ff08eaa..00000000000 --- a/src/unit_tests/wazuh_modules/gcp/test_wmodules_gcp.c +++ /dev/null @@ -1,1428 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -#include "../../headers/shared.h" -#include "../../os_xml/os_xml.h" -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/wm_gcp.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../../wrappers/wazuh/shared/schedule_scan_wrappers.h" - -static const char *XML_ENABLED = "enabled"; -static const char *XML_PROJECT_ID = "project_id"; -static const char *XML_SUBSCRIPTION_NAME = "subscription_name"; -static const char *XML_CREDENTIALS_FILE = "credentials_file"; -static const char *XML_MAX_MESSAGES = "max_messages"; -static const char *XML_NUM_THREADS = "num_threads"; -static const char *XML_PULL_ON_START = "pull_on_start"; -static const char *XML_LOGGING = "logging"; - -static const char *XML_RUN_ON_START = "run_on_start"; -static const char *XML_BUCKET = "bucket"; -static const char *XML_BUCKET_TYPE = "type"; -static const char *XML_BUCKET_NAME = "name"; -static const char *XML_PREFIX = "path"; -static const char *XML_ONLY_LOGS_AFTER = "only_logs_after"; -static const char *XML_REMOVE_FROM_BUCKET = "remove_from_bucket"; - -static const char *ACCESS_LOGS_BUCKET_TYPE = "access_logs"; - -typedef struct __group_data_s { - OS_XML *xml; - xml_node **nodes; - wmodule *module; -} group_data_t; - -/* Auxiliar functions */ -int replace_configuration_value(XML_NODE nodes, const char *tag, const char *new_value) { - int i; - - if(tag == NULL || nodes == NULL || *nodes == NULL) - return -1; - - // find the required tag and change it to the new value - for(i = 0; nodes[i]; i++) { - if(!strcmp(nodes[i]->element, tag)) { - os_free(nodes[i]->content); - if(new_value != NULL){ - nodes[i]->content = strdup(new_value); - - if(nodes[i]->content == NULL) - return -1; - } else { - nodes[i]->content = NULL; - } - return 0; - } - } - // If we got here, the given tag was not found - return -2; -} - -int replace_bucket_configuration_value(group_data_t *data, const char *tag, const char *new_value) { - int i; - int j; - OS_XML *xml = data->xml; - XML_NODE nodes = data->nodes; - xml_node **children = NULL; - - if(xml == NULL || tag == NULL || nodes == NULL || *nodes == NULL) - return -1; - - // find the required tag and change it to the new value - for(i = 0; nodes[i]; i++) { - if(!strcmp(nodes[i]->element, "bucket")) { - if (!(children = OS_GetElementsbyNode(xml, nodes[i]))) - continue; - - for (j = 0; children[j]; j++) { - if (!strcmp(children[j]->element, tag)) { - OS_ClearNode(children); - OS_ClearNode(data->nodes); - os_free(xml->ct[i+j+2]) - os_strdup(new_value, xml->ct[i+j+2]); - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - return 0; - } - } - OS_ClearNode(children); - } - } - // If we got here, the given tag was not found - return -2; -} - -int replace_bucket_configuration_attribute(group_data_t *data, const char *tag, const char *new_value) { - int i; - int j; - OS_XML *xml = data->xml; - XML_NODE nodes = data->nodes; - - if(xml == NULL || tag == NULL || nodes == NULL || *nodes == NULL) - return -1; - - // find the required tag and change it to the new value - for(i = 0; nodes[i]; i++) { - if(!strcmp(nodes[i]->element, "bucket")) { - if (strcmp(*nodes[i]->attributes, tag) == 0){ - os_free(xml->ct[i+1]) - os_strdup(new_value, xml->ct[i+1]); - OS_ClearNode(data->nodes); - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - return 0; - } - } - } - // If we got here, the given tag was not found - return -2; -} - -/* setup/teardown */ -static int setup_group(void **state) { - group_data_t *data; - os_calloc(1, sizeof(group_data_t), data); - - if(data == NULL) - return -1; - - if(os_calloc(1, sizeof(wmodule), data->module), data->module == NULL) - return -1; - - if(os_calloc(1, sizeof(OS_XML), data->xml), data->xml == NULL) - return -1; - - *state = data; - - return 0; -} - -static int teardown_group(void **state) { - group_data_t *data = *state; - - os_free(data->xml); - os_free(data->module); - - os_free(data); - - return 0; -} - -static int setup_test_pubsub(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "wazuh-gcp-pubsub-tests" - "testing-id" - "credentials.json" - "100" - "2" - "15"; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_pubsub_no_project_id(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "testing-id" - "credentials.json" - "100" - "2" - "15"; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_pubsub_no_subscription_name(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "wazuh-gcp-pubsub-tests" - "credentials.json" - "100" - "2" - "15"; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_pubsub_no_credentials_file(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "wazuh-gcp-pubsub-tests" - "testing-id" - "100" - "2" - "15"; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int teardown_test_pubsub(void **state) { - group_data_t *data = *state; - wm_gcp_pubsub *gcp = data->module->data; - - os_free(data->module->tag); - - if(gcp->project_id) os_free(gcp->project_id); - if(gcp->subscription_name) os_free(gcp->subscription_name); - if(gcp->credentials_file) os_free(gcp->credentials_file); - - os_free(gcp); - - data->module->data = NULL; - - OS_ClearXML(data->xml); - OS_ClearNode(data->nodes); - - return 0; -} - -static int setup_test_bucket(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - "credentials.json" - "2021-JUN-01" - "access_logs/" - "no" - "" - "" - "wazuh-gcp-bucket-tests-2" - "credentials.json" - "2021-JUN-02" - "access_logs/" - "yes" - "" - ""; - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_no_bucket(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no"; - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_element_invalid(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - ""; - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_bucket_attribute_invalid(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - "credentials.json" - "2021-JUN-01" - "access_logs/" - "no" - ""; - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_bucket_no_bucket(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "credentials.json" - "2021-JUN-01" - "access_logs/" - "no" - ""; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_bucket_no_bucket_type(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - "credentials.json" - "2021-JUN-01" - "access_logs/" - "no" - ""; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - - -static int setup_test_bucket_no_only_logs_after(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - "credentials.json" - "access_logs/" - "no" - ""; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_bucket_no_credentials_file(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - "credentials.json" - "2021-JUN-01" - "access_logs/" - "no" - "" - "" - "wazuh-gcp-bucket-tests" - "2021-JUN-01" - "access_logs/" - "no" - ""; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_bucket_no_path(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - "credentials.json" - "2021-JUN-01" - "no" - ""; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int setup_test_bucket_no_remove(void **state) { - group_data_t *data = *state; - char *base_config = "yes" - "no" - "" - "wazuh-gcp-bucket-tests" - "credentials.json" - "2021-JUN-01" - "access_logs/" - ""; - - - if(OS_ReadXMLString(base_config, data->xml) != 0){ - return -1; - } - - if(data->nodes = OS_GetElementsbyNode(data->xml, NULL), data->nodes == NULL) - return -1; - - return 0; -} - -static int teardown_test_bucket(void **state) { - group_data_t *data = *state; - wm_gcp_bucket_base *gcp_config = data->module->data;; - wm_gcp_bucket *gcp_bucket = gcp_config->buckets; - - os_free(data->module->tag); - - if (gcp_bucket) { - if (gcp_bucket->next) { - if (gcp_bucket->next->next) { - os_free(gcp_bucket->next->next); - } - if (gcp_bucket->next->bucket) os_free(gcp_bucket->next->bucket); - if (gcp_bucket->next->type) os_free(gcp_bucket->next->type); - if (gcp_bucket->next->credentials_file) os_free(gcp_bucket->next->credentials_file); - if (gcp_bucket->next->prefix) os_free(gcp_bucket->next->prefix); - if (gcp_bucket->next->only_logs_after) os_free(gcp_bucket->next->only_logs_after); - os_free(gcp_bucket->next); - } - if (gcp_bucket->bucket) os_free(gcp_bucket->bucket); - if (gcp_bucket->type) os_free(gcp_bucket->type); - if (gcp_bucket->credentials_file) os_free(gcp_bucket->credentials_file); - if (gcp_bucket->prefix) os_free(gcp_bucket->prefix); - if (gcp_bucket->only_logs_after) os_free(gcp_bucket->only_logs_after); - os_free(gcp_bucket); - } - os_free(gcp_config); - - data->module->data = NULL; - - OS_ClearXML(data->xml); - OS_ClearNode(data->nodes); - - return 0; -} - -/* tests */ -/* wm_gcp_pubsub_read */ -static void test_wm_gcp_pubsub_read_full_configuration(void **state) { - group_data_t *data = *state; - wm_gcp_pubsub *gcp; - int ret; - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_PUBSUB_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, 0); - - gcp = data->module->data; - - assert_non_null(gcp); - assert_int_equal(gcp->enabled, 1); - assert_int_equal(gcp->pull_on_start, 0); - assert_string_equal(gcp->project_id, "wazuh-gcp-pubsub-tests"); - assert_string_equal(gcp->subscription_name, "testing-id"); - assert_string_equal(gcp->credentials_file, "credentials.json"); - assert_int_equal(gcp->max_messages, 100); - assert_int_equal(gcp->num_threads, 2); - - assert_ptr_equal(data->module->context, &WM_GCP_PUBSUB_CONTEXT); - assert_string_equal(data->module->tag, GCP_PUBSUB_WM_NAME); -} - -static void test_wm_gcp_pubsub_read_sched_read_invalid(void **state) { - group_data_t *data = *state; - wm_gcp_pubsub *gcp; - int ret; - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_PUBSUB_WM_NAME); - will_return(__wrap_sched_scan_read, -1); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, -1); -} - -static void test_wm_gcp_pubsub_read_enabled_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_ENABLED, "invalid") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'enabled'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_project_id_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_PROJECT_ID, "") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'project_id' at module 'gcp-pubsub'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_no_project_id_tag(void **state) { - group_data_t *data = *state; - int ret; - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_PUBSUB_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - expect_string(__wrap__merror, formatted_msg, "No value defined for tag 'project_id' in module 'gcp-pubsub'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_subscription_name_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_SUBSCRIPTION_NAME, "") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'subscription_name' at module 'gcp-pubsub'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_no_subscription_name_tag(void **state) { - group_data_t *data = *state; - int ret; - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_PUBSUB_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - expect_string(__wrap__merror, formatted_msg, "No value defined for tag 'subscription_name' in module 'gcp-pubsub'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_credentials_file_full_path(void **state) { - group_data_t *data = *state; - wm_gcp_pubsub *gcp; - int ret; - - if(replace_configuration_value(data->nodes, XML_CREDENTIALS_FILE, "/some/path/credentials.json") != 0) - fail(); - - expect_string(__wrap_IsFile, file, "/some/path/credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_PUBSUB_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, 0); - - gcp = data->module->data; - - assert_non_null(gcp); - assert_int_equal(gcp->enabled, 1); - assert_int_equal(gcp->pull_on_start, 0); - assert_string_equal(gcp->project_id, "wazuh-gcp-pubsub-tests"); - assert_string_equal(gcp->subscription_name, "testing-id"); - assert_string_equal(gcp->credentials_file, "/some/path/credentials.json"); - assert_int_equal(gcp->max_messages, 100); - assert_int_equal(gcp->num_threads, 2); - - assert_ptr_equal(data->module->context, &WM_GCP_PUBSUB_CONTEXT); - assert_string_equal(data->module->tag, GCP_PUBSUB_WM_NAME); -} - -static void test_wm_gcp_pubsub_read_credentials_file_tag_empty(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_CREDENTIALS_FILE, "") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'credentials_file' at module 'gcp-pubsub'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_credentials_file_tag_too_long(void **state) { - group_data_t *data = *state; - char buffer[OS_MAXSTR]; - int ret; - - memset(buffer, 'a', OS_MAXSTR); - buffer[OS_MAXSTR - 1] = '\0'; - - if(replace_configuration_value(data->nodes, XML_CREDENTIALS_FILE, buffer) != 0) - fail(); - - snprintf(buffer, OS_MAXSTR, "File path is too long. Max path length is %d.", PATH_MAX); - expect_string(__wrap__merror, formatted_msg, buffer); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_credentials_file_tag_realpath_error(void **state) { - group_data_t *data = *state; - int ret; - - expect_string(__wrap_realpath, path, "credentials.json"); - - will_return(__wrap_realpath, (char *) NULL); // realpath failed - - expect_string(__wrap__merror, formatted_msg, "File '' from tag 'credentials_file' not found."); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_credentials_file_tag_file_not_found(void **state) { - group_data_t *data = *state; - int ret; - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap__merror, formatted_msg, "File 'credentials.json' not found. Check your configuration."); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_no_credentials_file_tag(void **state) { - group_data_t *data = *state; - int ret; - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_PUBSUB_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - expect_string(__wrap__merror, formatted_msg, "No value defined for tag 'credentials_file' in module 'gcp-pubsub'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_max_messages_tag_empty(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_MAX_MESSAGES, "") != 0) - fail(); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'max_messages'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_max_messages_tag_not_digit(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_MAX_MESSAGES, "invalid") != 0) - fail(); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "Tag 'max_messages' from the 'gcp-pubsub' module should not have an alphabetic character."); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_num_threads_tag_empty(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_NUM_THREADS, "") != 0) - fail(); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'num_threads'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_num_threads_tag_not_digit(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_NUM_THREADS, "invalid") != 0) - fail(); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "Tag 'num_threads' from the 'gcp-pubsub' module should not have an alphabetic character."); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_pull_on_start_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_PULL_ON_START, "invalid") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'pull_on_start'"); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_pubsub_read_invalid_tag(void **state) { - group_data_t *data = *state; - int ret; - - // Make an invalid XML tag element - os_free(data->nodes[0]->element); - - if(data->nodes[0]->element = strdup("invalid"), data->nodes[0]->element == NULL) - fail(); - - expect_string(__wrap__merror, formatted_msg, "No such tag 'invalid' at module 'gcp-pubsub'."); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, -1); -} - -static void test_wm_gcp_pubsub_read_invalid_element(void **state) { - group_data_t *data = *state; - int ret; - - // Make an invalid XML tag element - os_free(data->nodes[0]->element); - data->nodes[0]->element = NULL; - - expect_string(__wrap__merror, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - ret = wm_gcp_pubsub_read(data->nodes, data->module); - - assert_int_equal(ret, -1); -} - -static void test_wm_gcp_pubsub_read_invalid_nodes(void **state) { - group_data_t *data = *state; - int ret; - - expect_string(__wrap__merror, formatted_msg, "Empty configuration at module 'gcp-pubsub'."); - - ret = wm_gcp_pubsub_read(NULL, data->module); - - assert_int_equal(ret, -1); -} - -/* tests */ -/* wm_gcp_pubsub_read */ -static void test_wm_gcp_bucket_read_full_configuration(void **state) { - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - group_data_t *data = *state; - wm_gcp_bucket_base *gcp; - - int ret; - - expect_string_count(__wrap_realpath, path, "credentials.json", 2); - will_return_count(__wrap_realpath, "credentials.json", 2); - - expect_string_count(__wrap_IsFile, file, "credentials.json", 2); - will_return_count(__wrap_IsFile, 0, 2); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_BUCKET_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, 0); - - gcp = data->module->data; - - assert_non_null(gcp); - assert_int_equal(gcp->enabled, 1); - assert_int_equal(gcp->run_on_start, 0); - assert_string_equal(gcp->buckets->bucket, "wazuh-gcp-bucket-tests"); - assert_string_equal(gcp->buckets->only_logs_after, "2021-JUN-01"); - assert_string_equal(gcp->buckets->credentials_file, "credentials.json"); - assert_string_equal(gcp->buckets->prefix, "access_logs/"); - assert_int_equal(gcp->buckets->remove_from_bucket, 0); - - assert_ptr_equal(data->module->context, &WM_GCP_BUCKET_CONTEXT); - assert_string_equal(data->module->tag, GCP_BUCKET_WM_NAME); -} - -static void test_wm_gcp_bucket_read_sched_read_invalid(void **state) { - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - group_data_t *data = *state; - wm_gcp_bucket_base *gcp; - - int ret; - - expect_string_count(__wrap_realpath, path, "credentials.json", 2); - will_return_count(__wrap_realpath, "credentials.json", 2); - - expect_string_count(__wrap_IsFile, file, "credentials.json", 2); - will_return_count(__wrap_IsFile, 0, 2); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_BUCKET_WM_NAME); - will_return(__wrap_sched_scan_read, -1); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, -1); -} - -static void test_wm_gcp_bucket_read_enabled_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_ENABLED, "invalid") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'enabled'"); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_no_bucket(void **state) { - group_data_t *data = *state; - int ret; - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_BUCKET_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - expect_string(__wrap__merror, formatted_msg, "No buckets or services definitions found at module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_no_bucket_type(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - expect_string(__wrap__merror, formatted_msg, "No bucket type was specified. The valid one is 'access_logs'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - - -static void test_wm_gcp_bucket_read_bucket_type_invalid(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_attribute(data, XML_BUCKET_TYPE, "") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Invalid bucket type ''. The valid one is 'access_logs'"); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_bucket_element_invalid(void **state) { - group_data_t *data = *state; - int ret; - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - expect_string(__wrap__merror, formatted_msg, "No such child tag 'invalid' of bucket at module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_bucket_attribute_invalid(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - expect_string(__wrap__merror, formatted_msg, "Attribute name 'invalid' is not valid. The valid one is 'type'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_bucket_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_value(data, XML_BUCKET_NAME, "") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'name' at module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_no_bucket_tag(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "No value defined for tag 'name' in module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_remove_from_bucket_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_value(data, XML_REMOVE_FROM_BUCKET, "") != 0) - fail(); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'remove_from_bucket' at module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_path_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_value(data, XML_PREFIX, "") != 0) - fail(); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'path' at module 'gcp-bucket'"); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_only_logs_after_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_value(data, XML_ONLY_LOGS_AFTER, "") != 0) - fail(); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'only_logs_after' at module 'gcp-bucket'"); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_credentials_file_full_path(void **state) { - group_data_t *data = *state; - wm_gcp_bucket_base *gcp; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_value(data, XML_CREDENTIALS_FILE, "/some/path/credentials.json") != 0) - fail(); - - expect_string(__wrap_IsFile, file, "/some/path/credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_value(__wrap_sched_scan_read, nodes, data->nodes); - expect_string(__wrap_sched_scan_read, MODULE_NAME, GCP_BUCKET_WM_NAME); - will_return(__wrap_sched_scan_read, 0); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, 0); - - gcp = data->module->data; - - assert_non_null(gcp); - assert_int_equal(gcp->enabled, 1); - assert_int_equal(gcp->run_on_start, 0); - assert_string_equal(gcp->buckets->bucket, "wazuh-gcp-bucket-tests"); - assert_string_equal(gcp->buckets->only_logs_after, "2021-JUN-01"); - assert_string_equal(gcp->buckets->credentials_file, "/some/path/credentials.json"); - assert_string_equal(gcp->buckets->prefix, "access_logs/"); - assert_int_equal(gcp->buckets->remove_from_bucket, 0); - - assert_ptr_equal(data->module->context, &WM_GCP_BUCKET_CONTEXT); - assert_string_equal(data->module->tag, GCP_BUCKET_WM_NAME); -} - -static void test_wm_gcp_bucket_read_credentials_file_tag_empty(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_value(data, XML_CREDENTIALS_FILE, "") != 0) - fail(); - - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'credentials_file' at module 'gcp-bucket'"); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_credentials_file_tag_too_long(void **state) { - group_data_t *data = *state; - char buffer[OS_MAXSTR + 1] = {0}; - int ret; - - memset(buffer, 'a', OS_MAXSTR); - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - if(replace_bucket_configuration_value(data, XML_CREDENTIALS_FILE, buffer) != 0) - fail(); - - snprintf(buffer, OS_MAXSTR, "File path is too long. Max path length is %d.", PATH_MAX); - expect_string(__wrap__merror, formatted_msg, buffer); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_credentials_file_tag_realpath_error(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - expect_string(__wrap_realpath, path, "credentials.json"); - - will_return(__wrap_realpath, (char *) NULL); // realpath failed - - expect_string(__wrap__merror, formatted_msg, "File '' from tag 'credentials_file' not found."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_credentials_file_tag_file_not_found(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 1); - - expect_string(__wrap__merror, formatted_msg, "File 'credentials.json' not found. Check your configuration."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_no_credentials_file_tag(void **state) { - group_data_t *data = *state; - int ret; - - expect_any_always(__wrap__mtdebug2, tag); - expect_any_always(__wrap__mtdebug2, formatted_msg); - - expect_string(__wrap_realpath, path, "credentials.json"); - will_return(__wrap_realpath, "credentials.json"); - - expect_string(__wrap_IsFile, file, "credentials.json"); - will_return(__wrap_IsFile, 0); - - expect_string(__wrap__merror, formatted_msg, "No value defined for tag 'credentials_file' in module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_run_on_start_tag_invalid(void **state) { - group_data_t *data = *state; - int ret; - - if(replace_configuration_value(data->nodes, XML_RUN_ON_START, "invalid") != 0) - fail(); - - - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'run_on_start'"); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, OS_INVALID); -} - -static void test_wm_gcp_bucket_read_invalid_tag(void **state) { - group_data_t *data = *state; - int ret; - - // Make an invalid XML tag element - os_free(data->nodes[0]->element); - - if(data->nodes[0]->element = strdup("invalid"), data->nodes[0]->element == NULL) - fail(); - - expect_string(__wrap__merror, formatted_msg, "No such tag 'invalid' at module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, -1); -} - -static void test_wm_gcp_bucket_read_invalid_element(void **state) { - group_data_t *data = *state; - int ret; - - // Make an invalid XML tag element - os_free(data->nodes[0]->element); - data->nodes[0]->element = NULL; - - expect_string(__wrap__merror, formatted_msg, "(1231): Invalid NULL element in the configuration."); - - ret = wm_gcp_bucket_read(data->xml, data->nodes, data->module); - - assert_int_equal(ret, -1); -} - -static void test_wm_gcp_bucket_read_invalid_nodes(void **state) { - group_data_t *data = *state; - int ret; - - expect_string(__wrap__merror, formatted_msg, "Empty configuration at module 'gcp-bucket'."); - - ret = wm_gcp_bucket_read(data->xml, NULL, data->module); - - assert_int_equal(ret, -1); -} - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_full_configuration, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_sched_read_invalid, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_enabled_tag_invalid, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_project_id_tag_invalid, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_no_project_id_tag, setup_test_pubsub_no_project_id, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_subscription_name_tag_invalid, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_no_subscription_name_tag, setup_test_pubsub_no_subscription_name, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_credentials_file_full_path, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_credentials_file_tag_empty, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_credentials_file_tag_too_long, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_credentials_file_tag_realpath_error, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_credentials_file_tag_file_not_found, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_no_credentials_file_tag, setup_test_pubsub_no_credentials_file, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_max_messages_tag_empty, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_max_messages_tag_not_digit, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_num_threads_tag_empty, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_num_threads_tag_not_digit, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_pull_on_start_tag_invalid, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_invalid_tag, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_invalid_element, setup_test_pubsub, teardown_test_pubsub), - cmocka_unit_test_setup_teardown(test_wm_gcp_pubsub_read_invalid_nodes, setup_test_pubsub, teardown_test_pubsub), - - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_full_configuration, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_sched_read_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_enabled_tag_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_no_bucket, setup_test_no_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_bucket_element_invalid, setup_test_element_invalid, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_bucket_type_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_bucket_attribute_invalid, setup_test_bucket_attribute_invalid, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_no_bucket_type, setup_test_bucket_no_bucket_type, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_bucket_tag_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_no_bucket_tag, setup_test_bucket_no_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_remove_from_bucket_tag_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_path_tag_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_only_logs_after_tag_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_credentials_file_full_path, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_credentials_file_tag_empty, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_credentials_file_tag_too_long, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_credentials_file_tag_realpath_error, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_credentials_file_tag_file_not_found, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_no_credentials_file_tag, setup_test_bucket_no_credentials_file, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_run_on_start_tag_invalid, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_invalid_tag, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_invalid_element, setup_test_bucket, teardown_test_bucket), - cmocka_unit_test_setup_teardown(test_wm_gcp_bucket_read_invalid_nodes, setup_test_bucket, teardown_test_bucket), - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/github/CMakeLists.txt b/src/unit_tests/wazuh_modules/github/CMakeLists.txt deleted file mode 100644 index 13b411c8f0b..00000000000 --- a/src/unit_tests/wazuh_modules/github/CMakeLists.txt +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Tests list and flags -list(APPEND tests_names "test_wm_github") -set(WM_GITHUB_BASE_FLAGS "-Wl,--wrap,_mwarn -Wl,--wrap,_mdebug1 -Wl,--wrap,_merror -Wl,--wrap,_mtinfo -Wl,--wrap,_mterror\ - -Wl,--wrap,_mtwarn -Wl,--wrap,_mtdebug1 -Wl,--wrap,_mtdebug2 -Wl,--wrap,StartMQ -Wl,--wrap,sleep \ - -Wl,--wrap,OS_IsValidIP -Wl,--wrap,OSMatch_Execute -Wl,--wrap,wm_sendmsg -Wl,--wrap,OSRegex_Compile \ - -Wl,--wrap,wm_state_io -Wl,--wrap,OSRegex_Execute -Wl,--wrap,OSRegex_Execute_ex -Wl,--wrap,OSMatch_Compile \ - -Wl,--wrap,OSRegex_FreePattern -Wl,--wrap,wurl_http_request -Wl,--wrap,strftime -Wl,--wrap,gmtime_r \ - -Wl,--wrap,isDebug") -if(${TARGET} STREQUAL "winagent") - list(APPEND tests_flags "${WM_GITHUB_BASE_FLAGS} -Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck -Wl,--wrap=is_fim_shutdown \ - -Wl,--wrap=fim_db_teardown -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize") -else() - list(APPEND tests_flags "${WM_GITHUB_BASE_FLAGS}") -endif() - -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB github ../../../wazuh_modules/*.o) -list(REMOVE_ITEM github ../../../wazuh_modules/main.o) - -add_library(GITHUB_O STATIC ${github}) - -set_source_files_properties( - ${github} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - GITHUB_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(GITHUB_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - GITHUB_O - -lcmocka - -ldl - -fprofile-arcs - -ftest-coverage - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - if(${TARGET} STREQUAL "winagent") - target_link_libraries(${test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - endif() - - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/github/test_wm_github.c b/src/unit_tests/wazuh_modules/github/test_wm_github.c deleted file mode 100644 index 3f61f521f0a..00000000000 --- a/src/unit_tests/wazuh_modules/github/test_wm_github.c +++ /dev/null @@ -1,1417 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for github Module - * */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../../../wazuh_modules/wm_github.h" -#include "../../../wazuh_modules/wm_github.c" - -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/os_regex/os_regex_wrappers.c" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wmodules_wrappers.h" -#include "../../wrappers/wazuh/shared/url_wrappers.h" -#include "../../wrappers/libc/time_wrappers.h" - -unsigned int __wrap_sleep(unsigned int __seconds) { - check_expected(__seconds); - return mock_type(unsigned int); -} - -unsigned int __wrap_gmtime_r(__attribute__ ((__unused__)) const time_t *t, __attribute__ ((__unused__)) struct tm *tm) { - return mock_type(unsigned int); -} - -int __wrap_isDebug() { - return mock(); -} - -//////////////// test wm-github ///////////////// - -typedef struct test_struct { - wm_github *github_config; - curl_response* response; - char *root_c; -} test_struct_t; - -static int setup_conf(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t), init_data); - os_calloc(1, sizeof(wm_github), init_data->github_config); - test_mode = 1; - *state = init_data; - return 0; -} - -static int teardown_conf(void **state) { - test_struct_t *data = (test_struct_t *)*state; - test_mode = 0; - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtinfo, formatted_msg, "Module GitHub finished."); - wm_github_destroy(data->github_config); - os_free(data->root_c); - os_free(data); - - return 0; -} - -void test_github_main_disabled(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 0; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtinfo, formatted_msg, "Module GitHub disabled."); - - wm_github_main(data->github_config); -} - -void test_github_main_fail_StartMQ(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtinfo, formatted_msg, "Module GitHub started."); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mterror, formatted_msg, "Can't connect to queue. Closing module."); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, -1); - - wm_github_main(data->github_config); -} - -void test_github_main_enable(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - data->github_config->interval = 2; - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 1); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtinfo, formatted_msg, "Module GitHub started."); - - expect_value(__wrap_sleep, __seconds, 2); - will_return(__wrap_sleep, 0); - - wm_github_main(data->github_config); -} - -void test_github_get_next_page_warn(void **state) { - char *header = "test"; - - expect_string(__wrap_OSRegex_Compile, pattern,"<(\\S+)>;\\s*rel=\"next\""); - will_return(__wrap_OSRegex_Compile, 0); - - expect_string(__wrap__mwarn, formatted_msg, "Cannot compile regex."); - - assert_null(wm_read_http_header_element(header, GITHUB_NEXT_PAGE_REGEX)); -} - -void test_github_get_next_page_execute(void **state) { - char *header = "test"; - - expect_string(__wrap_OSRegex_Compile, pattern, "<(\\S+)>;\\s*rel=\"next\""); - will_return(__wrap_OSRegex_Compile, 1); - - expect_string(__wrap_OSRegex_Execute, str, "test"); - will_return(__wrap_OSRegex_Execute, NULL); - - expect_any(__wrap_OSRegex_FreePattern, reg); - - expect_string(__wrap__mdebug1, formatted_msg, "No match regex."); - - assert_null(wm_read_http_header_element(header, GITHUB_NEXT_PAGE_REGEX)); -} - -void test_github_get_next_page_sub_string(void **state) { - char *header = "test"; - - expect_string(__wrap_OSRegex_Compile, pattern, "<(\\S+)>;\\s*rel=\"next\""); - will_return(__wrap_OSRegex_Compile, 1); - - expect_string(__wrap_OSRegex_Execute, str, "test"); - will_return(__wrap_OSRegex_Execute, "yes"); - - expect_any(__wrap_OSRegex_FreePattern, reg); - - expect_string(__wrap__mdebug1, formatted_msg, "No element was captured."); - - assert_null(wm_read_http_header_element(header, GITHUB_NEXT_PAGE_REGEX)); -} - -void test_github_get_next_page_complete(void **state) { - wm_github* github_config = *state; - char *header = "test_1"; - char *next_page = NULL; - - expect_string(__wrap_OSRegex_Compile, pattern, "<(\\S+)>;\\s*rel=\"next\""); - will_return(__wrap_OSRegex_Compile, 1); - - expect_string(__wrap_OSRegex_Execute, str, "test_1"); - will_return(__wrap_OSRegex_Execute, "yes"); - - expect_any(__wrap_OSRegex_FreePattern, reg); - - next_page = wm_read_http_header_element(header, GITHUB_NEXT_PAGE_REGEX); - - assert_string_equal(next_page, "https://api.com/"); - os_free(next_page); -} - -void test_github_dump_no_options(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *test = "{\"github\":{\"enabled\":\"no\",\"only_future_events\":\"no\"}}"; - - cJSON *root = wm_github_dump(data->github_config); - data->root_c = cJSON_PrintUnformatted(root); - cJSON_Delete(root); - - assert_string_equal(data->root_c, test); -} - -void test_github_dump_yes_options(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - data->github_config->only_future_events = 1; - data->github_config->interval = 10; - data->github_config->time_delay = 1; - data->github_config->curl_max_size = 2; - os_calloc(1, sizeof(wm_github_auth), data->github_config->auth); - os_strdup("test_token", data->github_config->auth->api_token); - os_strdup("test_org", data->github_config->auth->org_name); - os_strdup("all", data->github_config->event_type); - - char *test = "{\"github\":{\"enabled\":\"yes\",\"only_future_events\":\"yes\",\"interval\":10,\"time_delay\":1,\"curl_max_size\":2,\"api_auth\":[{\"org_name\":\"test_org\",\"api_token\":\"test_token\"}],\"event_type\":\"all\"}}"; - - cJSON *root = wm_github_dump(data->github_config); - data->root_c = cJSON_PrintUnformatted(root); - cJSON_Delete(root); - - assert_string_equal(data->root_c, test); -} - -void test_github_scan_failure_action_1(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_calloc(1, sizeof(wm_github_fail), data->github_config->fails); - data->github_config->fails->fails = 1; - os_strdup("test_org", data->github_config->fails->org_name); - os_strdup("test_event", data->github_config->fails->event_type); - data->github_config->fails->next = NULL; - char *org_name = "test_org"; - char *event_type = "test_event"; - char *error_msg = "test_error"; - int queue_fd = 1; - - wm_github_scan_failure_action(&data->github_config->fails, org_name, event_type, error_msg, queue_fd); - - assert_string_equal(data->github_config->fails->org_name, "test_org"); - assert_string_equal(data->github_config->fails->event_type, "test_event"); - assert_int_equal(data->github_config->fails->fails, 2); -} - -void test_github_scan_failure_action_2(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_calloc(1, sizeof(wm_github_fail), data->github_config->fails); - data->github_config->fails->fails = 1; - os_strdup("test_org", data->github_config->fails->org_name); - os_strdup("test_event", data->github_config->fails->event_type); - os_calloc(1, sizeof(wm_github_fail), data->github_config->fails->next); - data->github_config->fails->next->fails = 1; - os_strdup("test_org2", data->github_config->fails->next->org_name); - os_strdup("test_event2", data->github_config->fails->next->event_type); - data->github_config->fails->next->next = NULL; - char *org_name = "test_org3"; - char *event_type = "test_event3"; - char *error_msg = "test_error"; - int queue_fd = 1; - - wm_github_scan_failure_action(&data->github_config->fails, org_name, event_type, error_msg, queue_fd); - - assert_string_equal(data->github_config->fails->org_name, "test_org"); - assert_string_equal(data->github_config->fails->event_type, "test_event"); - assert_string_equal(data->github_config->fails->next->org_name, "test_org2"); - assert_string_equal(data->github_config->fails->next->event_type, "test_event2"); - assert_string_equal(data->github_config->fails->next->next->org_name, "test_org3"); - assert_string_equal(data->github_config->fails->next->next->event_type, "test_event3"); - assert_int_equal(data->github_config->fails->fails, 1); - assert_int_equal(data->github_config->fails->next->fails, 1); - assert_int_equal(data->github_config->fails->next->next->fails, 1); -} - -void test_github_scan_failure_action_3(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_calloc(1, sizeof(wm_github_fail), data->github_config->fails); - data->github_config->fails->fails = 2; - os_strdup("test_org", data->github_config->fails->org_name); - os_strdup("test_event", data->github_config->fails->event_type); - data->github_config->fails->next = NULL; - char *org_name = "test_org"; - char *event_type = "test_event"; - char *error_msg = "test_error"; - int queue_fd = 1; - wm_max_eps = 1; - - int result = 0; - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, 1); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\",\"organization\":\"test_org\",\"event_type\":\"test_event\",\"response\":\"Unknown error\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "github"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtwarn, formatted_msg, "Sending GitHub internal message: '{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\",\"organization\":\"test_org\",\"event_type\":\"test_event\",\"response\":\"Unknown error\"}}'"); - - wm_github_scan_failure_action(&data->github_config->fails, org_name, event_type, error_msg, queue_fd); - - assert_string_equal(data->github_config->fails->org_name, "test_org"); - assert_string_equal(data->github_config->fails->event_type, "test_event"); - assert_int_equal(data->github_config->fails->fails, 3); -} - -void test_github_scan_failure_action_4(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_calloc(1, sizeof(wm_github_fail), data->github_config->fails); - data->github_config->fails->fails = 2; - os_strdup("test_org", data->github_config->fails->org_name); - os_strdup("test_event", data->github_config->fails->event_type); - data->github_config->fails->next = NULL; - char *org_name = "test_org"; - char *event_type = "test_event"; - char *error_msg = "{\"test\":\"test_error\"}"; - int queue_fd = 1; - wm_max_eps = 1; - - int result = 0; - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, 1); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\",\"organization\":\"test_org\",\"event_type\":\"test_event\",\"response\":\"{\\\"test\\\":\\\"test_error\\\"}\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "github"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtwarn, formatted_msg, "Sending GitHub internal message: '{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\",\"organization\":\"test_org\",\"event_type\":\"test_event\",\"response\":\"{\\\"test\\\":\\\"test_error\\\"}\"}}'"); - - wm_github_scan_failure_action(&data->github_config->fails, org_name, event_type, error_msg, queue_fd); - - assert_string_equal(data->github_config->fails->org_name, "test_org"); - assert_string_equal(data->github_config->fails->event_type, "test_event"); - assert_int_equal(data->github_config->fails->fails, 3); -} - -void test_github_scan_failure_action_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - os_calloc(1, sizeof(wm_github_fail), data->github_config->fails); - data->github_config->fails->fails = 2; - os_strdup("test_org", data->github_config->fails->org_name); - os_strdup("test_event", data->github_config->fails->event_type); - data->github_config->fails->next = NULL; - char *org_name = "test_org"; - char *event_type = "test_event"; - char *error_msg = "test_error"; - int queue_fd = 1; - wm_max_eps = 1; - - int result = -1; - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, 1); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\",\"organization\":\"test_org\",\"event_type\":\"test_event\",\"response\":\"Unknown error\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "github"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtwarn, formatted_msg, "Sending GitHub internal message: '{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\",\"organization\":\"test_org\",\"event_type\":\"test_event\",\"response\":\"Unknown error\"}}'"); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mterror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'Success'"); - - wm_github_scan_failure_action(&data->github_config->fails, org_name, event_type, error_msg, queue_fd); - - assert_string_equal(data->github_config->fails->org_name, "test_org"); - assert_string_equal(data->github_config->fails->event_type, "test_event"); - assert_int_equal(data->github_config->fails->fails, 3); -} - -void test_github_scan_failure_action_org_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->fails = NULL; - char *org_name = "test_org"; - char *event_type = "test_event"; - char *error_msg = "test_error"; - int queue_fd = 1; - wm_max_eps = 1; - - wm_github_scan_failure_action(&data->github_config->fails, org_name, event_type, error_msg, queue_fd); - - assert_string_equal(data->github_config->fails->org_name, "test_org"); - assert_string_equal(data->github_config->fails->event_type, "test_event"); - assert_int_equal(data->github_config->fails->fails, 1); -} - -void test_github_execute_scan(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - data->github_config->only_future_events = 1; - data->github_config->interval = 10; - data->github_config->time_delay = 1; - data->github_config->curl_max_size = 2; - os_calloc(1, sizeof(wm_github_auth), data->github_config->auth); - os_strdup("test_token", data->github_config->auth->api_token); - os_strdup("test_org", data->github_config->auth->org_name); - data->github_config->auth->next = NULL; - os_strdup("all", data->github_config->event_type); - - int initial_scan = 1; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning organization: 'test_org'"); - - will_return(__wrap_isDebug, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2021-05-07T12:24:56Z' for organization 'test_org' and event type 'git', waiting '10' seconds to run first scan."); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-git"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-git"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - will_return(__wrap_isDebug, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07T11:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2021-05-07T11:24:56Z' for organization 'test_org' and event type 'web', waiting '10' seconds to run first scan."); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-web"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-web"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - wm_github_execute_scan(data->github_config, initial_scan); -} - -void test_github_execute_scan_current_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->auth = NULL; - - int initial_scan = 1; - - wm_github_execute_scan(data->github_config, initial_scan); -} - -void test_github_execute_scan_no_initial_scan(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - data->github_config->only_future_events = 1; - data->github_config->interval = 10; - data->github_config->time_delay = 1; - data->github_config->curl_max_size = 2; - os_calloc(1, sizeof(wm_github_auth), data->github_config->auth); - os_strdup("test_token", data->github_config->auth->api_token); - os_strdup("test_org", data->github_config->auth->org_name); - data->github_config->auth->next = NULL; - os_strdup("git", data->github_config->event_type); - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 404; - data->response->body = NULL; - - int initial_scan = 0; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning organization: 'test_org'"); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-git"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:34:56"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_GITHUB_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - wm_github_execute_scan(data->github_config, initial_scan); - - assert_int_equal(data->github_config->fails->fails, 1); - assert_string_equal(data->github_config->fails->org_name, "test_org"); -} - -void test_github_execute_scan_status_code_200(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - data->github_config->only_future_events = 1; - data->github_config->interval = 10; - data->github_config->time_delay = 1; - data->github_config->curl_max_size = 2; - os_calloc(1, sizeof(wm_github_auth), data->github_config->auth); - os_strdup("test_token", data->github_config->auth->api_token); - os_strdup("test_org", data->github_config->auth->org_name); - data->github_config->auth->next = NULL; - os_strdup("web", data->github_config->event_type); - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - data->response->body = NULL; - - int initial_scan = 0; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning organization: 'test_org'"); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-web"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:34:56"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error parsing response body."); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_GITHUB_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - wm_github_execute_scan(data->github_config, initial_scan); - - assert_int_equal(data->github_config->fails->fails, 1); - assert_string_equal(data->github_config->fails->org_name, "test_org"); -} - -void test_github_execute_scan_status_code_200_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - data->github_config->only_future_events = 1; - data->github_config->interval = 10; - data->github_config->time_delay = 1; - data->github_config->curl_max_size = 2; - os_calloc(1, sizeof(wm_github_auth), data->github_config->auth); - os_strdup("test_token", data->github_config->auth->api_token); - os_strdup("test_org", data->github_config->auth->org_name); - data->github_config->auth->next = NULL; - os_strdup("git", data->github_config->event_type); - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"github\":{\"actor\":\"wazuh\"}}", data->response->body); - os_strdup("test", data->response->header); - - int initial_scan = 0; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning organization: 'test_org'"); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-git"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:34:56"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_GITHUB_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, 0); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "github"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, 0); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug2, formatted_msg, "Sending GitHub log: '{\"integration\":\"github\",\"github\":{\"actor\":\"wazuh\"}}'"); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-git"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mterror, formatted_msg, "Couldn't save running state."); - - wm_github_execute_scan(data->github_config, initial_scan); -} - -void test_github_execute_scan_max_size_reached(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->github_config->enabled = 1; - data->github_config->only_future_events = 1; - data->github_config->interval = 10; - data->github_config->time_delay = 1; - data->github_config->curl_max_size = 2; - os_calloc(1, sizeof(wm_github_auth), data->github_config->auth); - os_strdup("test_token", data->github_config->auth->api_token); - os_strdup("test_org", data->github_config->auth->org_name); - data->github_config->auth->next = NULL; - os_strdup("web", data->github_config->event_type); - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - data->response->max_size_reached = true; - - int initial_scan = 0; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning organization: 'test_org'"); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-web"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07T12:34:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_GITHUB_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Libcurl error, reached maximum response size."); - - expect_string(__wrap_wm_state_io, tag, "github-test_org-web"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:github"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2021-05-07T12:34:56Z' for organization 'test_org' and event type 'web', waiting '10' seconds to run next scan."); - - wm_github_execute_scan(data->github_config, initial_scan); - -} - -//////////////// test wmodules-github ///////////////// - -static int setup_test_read(void **state) { - test_structure *test; - os_calloc(1, sizeof(test_structure), test); - os_calloc(1, sizeof(wmodule), test->module); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - if((wm_github*)test->module->data){ - if(((wm_github*)test->module->data)->auth){ - os_free(((wm_github*)test->module->data)->auth->org_name); - os_free(((wm_github*)test->module->data)->auth->api_token); - if(((wm_github*)test->module->data)->auth->next) { - os_free(((wm_github*)test->module->data)->auth->next->org_name); - os_free(((wm_github*)test->module->data)->auth->next->api_token); - os_free(((wm_github*)test->module->data)->auth->next->next); - } - os_free(((wm_github*)test->module->data)->auth->next); - os_free(((wm_github*)test->module->data)->auth); - } - os_free(((wm_github*)test->module->data)->event_type); - } - os_free(test->module->data); - os_free(test->module->tag); - os_free(test->module); - os_free(test); - return 0; -} - -void test_read_configuration(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "2048" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->interval, 600); - assert_int_equal(module_data->time_delay, 1); - assert_int_equal(module_data->curl_max_size, 2048); - assert_int_equal(module_data->only_future_events, 0); - assert_string_equal(module_data->auth->org_name, "Wazuh"); - assert_string_equal(module_data->auth->api_token, "Wazuh_token"); - assert_string_equal(module_data->event_type, "git"); -} - -void test_read_configuration_1(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "2k" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "Wazuh1" - "Wazuh_token1" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->interval, 600); - assert_int_equal(module_data->time_delay, 1); - assert_int_equal(module_data->curl_max_size, 2048); - assert_int_equal(module_data->only_future_events, 0); - assert_string_equal(module_data->auth->org_name, "Wazuh"); - assert_string_equal(module_data->auth->api_token, "Wazuh_token"); - assert_string_equal(module_data->auth->next->org_name, "Wazuh1"); - assert_string_equal(module_data->auth->next->api_token, "Wazuh_token1"); - assert_string_equal(module_data->event_type, "git"); -} - -void test_read_default_configuration(void **state) { - const char *string = - "" - "Wazuh" - "Wazuh_token" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->enabled, 1); - assert_int_equal(module_data->interval, 60); - assert_int_equal(module_data->time_delay, 30); - assert_int_equal(module_data->only_future_events, 1); - assert_string_equal(module_data->auth->org_name, "Wazuh"); - assert_string_equal(module_data->auth->api_token, "Wazuh_token"); - assert_string_equal(module_data->event_type, "all"); -} - -void test_read_interval(void **state) { - const char *string = - "yes\n" - "10\n" - "10" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->interval, 10); -} - -void test_read_interval_s(void **state) { - const char *string = - "no\n" - "50s\n" - "10" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->interval, 50); -} - -void test_read_interval_m(void **state) { - const char *string = - "no\n" - "1m\n" - "10" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->interval, 60); -} - -void test_read_interval_h(void **state) { - const char *string = - "no\n" - "2h\n" - "10" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->interval, 7200); -} - -void test_read_interval_d(void **state) { - const char *string = - "no\n" - "3d\n" - "10" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->interval, 259200); -} - -void test_read_curl_max_size(void **state) { - const char *string = - "yes\n" - "10\n" - "10" - "2k" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->curl_max_size, 2048); -} - -void test_repeatd_tag(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "2k" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - "" - "git" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),0); - wm_github *module_data = (wm_github*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->interval, 600); - assert_int_equal(module_data->time_delay, 1); - assert_int_equal(module_data->only_future_events, 0); - assert_string_equal(module_data->auth->org_name, "Wazuh"); - assert_string_equal(module_data->auth->api_token, "Wazuh_token"); - assert_string_equal(module_data->event_type, "git"); -} - -void test_fake_tag(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "2k" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - "ASD" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'fake-tag' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_2(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "2k" - "yes" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "invalid" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'event_type' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_3(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "2k" - "invalid" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'only_future_events' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_4(void **state) { - const char *string = - "invalid\n" - "10m\n" - "1s" - "2k" - "yes" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'enabled' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_5(void **state) { - const char *string = - "no\n" - "invalid\n" - "1s" - "2k" - "yes" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_6(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "invalid" - "yes" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'github'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_time_delay_1(void **state) { - const char *string = - "no\n" - "10m\n" - "-1" - "2k" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "invalid" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'time_delay' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_time_delay_2(void **state) { - const char *string = - "no\n" - "10m\n" - "1y" - "2k" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "invalid" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'time_delay' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_curl_max_size_1(void **state) { - const char *string = - "no\n" - "10m\n" - "10" - "100" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "invalid" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'github'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_curl_max_size_2(void **state) { - const char *string = - "no\n" - "10m\n" - "10" - "-1m" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "invalid" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'github'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_curl_max_size_3(void **state) { - const char *string = - "no\n" - "10m\n" - "10" - "invalid" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "invalid" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'github'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_auth(void **state) { - const char *string = - "no\n" - "10m\n" - "1" - "no" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'api_auth' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_auth_1(void **state) { - const char *string = - "no\n" - "10m\n" - "1" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'invalid' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_org_name(void **state) { - const char *string = - "no\n" - "10m\n" - "1" - "no" - "" - "" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'org_name' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_org_name_1(void **state) { - const char *string = - "no\n" - "10m\n" - "1" - "no" - "" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "'org_name' is missing at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_token(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "no" - "" - "Wazuh" - "" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'api_token' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_token_1(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "no" - "" - "Wazuh" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "'api_token' is missing at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_event_type_1(void **state) { - const char *string = - "no\n" - "10m\n" - "1s" - "no" - "" - "Wazuh" - "Wazuh_token" - "" - "" - "all" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'invalid' at module 'github'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_github_read(&(test->xml), test->nodes, test->module),-1); -} - -int main(void) { - - const struct CMUnitTest tests_functionality[] = { - #ifndef WIN32 - cmocka_unit_test_setup_teardown(test_github_main_fail_StartMQ, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_main_enable, setup_conf, teardown_conf), - #endif - cmocka_unit_test_setup_teardown(test_github_main_disabled, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_get_next_page_warn, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_get_next_page_execute, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_get_next_page_sub_string, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_get_next_page_complete, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_dump_no_options, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_dump_yes_options, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_scan_failure_action_1, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_scan_failure_action_2, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_scan_failure_action_3, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_scan_failure_action_4, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_scan_failure_action_error, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_scan_failure_action_org_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_execute_scan_current_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_execute_scan, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_execute_scan_no_initial_scan, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_execute_scan_status_code_200, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_execute_scan_status_code_200_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_github_execute_scan_max_size_reached, setup_conf, teardown_conf), - }; - const struct CMUnitTest tests_configuration[] = { - cmocka_unit_test_setup_teardown(test_read_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_configuration_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_default_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_s, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_m, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_h, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_d, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_curl_max_size, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_repeatd_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_2, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_3, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_4, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_5, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_6, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_time_delay_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_time_delay_2, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_curl_max_size_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_curl_max_size_2, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_curl_max_size_3, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_auth, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_auth_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_org_name, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_org_name_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_token, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_token_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_event_type_1, setup_test_read, teardown_test_read), - }; - int result; - result = cmocka_run_group_tests(tests_functionality, NULL, NULL); - result += cmocka_run_group_tests(tests_configuration, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/ms_graph/CMakeLists.txt b/src/unit_tests/wazuh_modules/ms_graph/CMakeLists.txt deleted file mode 100644 index 9acd16bef52..00000000000 --- a/src/unit_tests/wazuh_modules/ms_graph/CMakeLists.txt +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (C) 2023, InfoDefense Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Tests list and flags -list(APPEND tests_names "test_wm_ms_graph") -list(APPEND tests_flags "-Wl,--wrap=_merror -Wl,--wrap=_mtinfo -Wl,--wrap=_mtwarn -Wl,--wrap,_mtdebug1 -Wl,--wrap=_mterror -Wl,--wrap,wurl_http_request \ - -Wl,--wrap,atexit -Wl,--wrap,time -Wl,--wrap,wm_state_io -Wl,--wrap,StartMQ -Wl,--wrap,gmtime_r -Wl,--wrap,isDebug \ - -Wl,--wrap,sched_scan_get_time_until_next_scan -Wl,--wrap,is_fim_shutdown -Wl,--wrap,fim_db_teardown -Wl,--wrap,Start_win32_Syscheck \ - -Wl,--wrap,strftime -Wl,--wrap,_mtdebug2 -Wl,--wrap,wm_sendmsg -Wl,--wrap,strerror -Wl,--wrap,_imp__rsync_initialize \ - -Wl,--wrap,syscom_dispatch -Wl,--wrap,_imp__dbsync_initialize -Wl,--wrap,w_get_timestamp -Wl,--wrap,FOREVER") - - -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB ms_graph ../../../wazuh_modules/*.o) -list(REMOVE_ITEM ms_graph ../../../wazuh_modules/main.o) - -add_library(MS_GRAPH_O STATIC ${ms_graph}) - -set_source_files_properties( - ${ms_graph} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - MS_GRAPH_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(MS_GRAPH_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - MS_GRAPH_O - -lcmocka - -ldl - -fprofile-arcs - -ftest-coverage - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - endif() - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/ms_graph/test_wm_ms_graph.c b/src/unit_tests/wazuh_modules/ms_graph/test_wm_ms_graph.c deleted file mode 100644 index 4e37cb119ed..00000000000 --- a/src/unit_tests/wazuh_modules/ms_graph/test_wm_ms_graph.c +++ /dev/null @@ -1,3094 +0,0 @@ -/* - * Copyright (C) 2023, InfoDefense Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for ms-graph Module - * */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/wm_ms_graph.h" -#include "../../wazuh_modules/wm_ms_graph.c" - -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wmodules_wrappers.h" -#include "../../wrappers/wazuh/shared/time_op_wrappers.h" -#include "../../wrappers/wazuh/shared/url_wrappers.h" -#include "../../wrappers/wazuh/shared/schedule_scan_wrappers.h" -#include "../../wrappers/libc/time_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" - -#define TEST_MAX_DATES 5 -#define TEST_MAX_TENANT 3 - -static wmodule *ms_graph_module; -static OS_XML *lxml; - -unsigned int __wrap_gmtime_r(__attribute__ ((__unused__)) const time_t *t, __attribute__ ((__unused__)) struct tm *tm) { - return mock_type(unsigned int); -} - -int __wrap_isDebug() { - return mock(); -} - -static void wmodule_cleanup(wmodule *module){ - wm_ms_graph* module_data = (wm_ms_graph*)module->data; - if(module_data){ - os_free(module_data->version); - for(unsigned int resource = 0; resource < module_data->num_resources; resource++){ - for(unsigned int relationship = 0; relationship < module_data->resources[resource].num_relationships; relationship++){ - os_free(module_data->resources[resource].relationships[relationship]); - } - os_free(module_data->resources[resource].relationships); - os_free(module_data->resources[resource].name); - } - os_free(module_data->resources); - for(int i = 0; module_data->auth_config[i]; i++) { - os_free(module_data->auth_config[i]->tenant_id); - os_free(module_data->auth_config[i]->client_id); - os_free(module_data->auth_config[i]->secret_value); - os_free(module_data->auth_config[i]->access_token); - os_free(module_data->auth_config[i]->login_fqdn); - os_free(module_data->auth_config[i]->query_fqdn); - - os_free(module_data->auth_config[i]); - } - - os_free(module_data->auth_config); - os_free(module_data); - } - os_free(module->tag); - os_free(module); -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wm_ms_graph* module_data = (wm_ms_graph*)test->module->data; - if(module_data && &(module_data->scan_config)){ - sched_scan_free(&(module_data->scan_config)); - } - wmodule_cleanup(test->module); - os_free(test); - return 0; -} - -static int setup_conf(void **state) { - wm_ms_graph* init_data = NULL; - os_calloc(1,sizeof(wm_ms_graph), init_data); - test_mode = true; - *state = init_data; - return 0; -} - -static int teardown_conf(void **state) { - wm_ms_graph *data = (wm_ms_graph *)*state; - test_mode = false; - wm_ms_graph_destroy(data); - return 0; -} - -// XML reading tests -void test_bad_tag(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1233): Invalid attribute 'invalid' in the configuration: 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_empty_module(void **state) { - const char* config = ""; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty configuration found in module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_invalid_enabled(void **state) { - const char* config = - "invalid\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'enabled' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_enabled_no(void **state) { - const char* config = - "no\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_SUCCESS); - wm_ms_graph *module_data = (wm_ms_graph*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->only_future_events, 1); - assert_int_equal(module_data->curl_max_size, OS_SIZE_1048576); - assert_int_equal(module_data->run_on_start, 1); - assert_string_equal(module_data->version, "v1.0"); - - assert_string_equal(module_data->auth_config[0]->tenant_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->client_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->secret_value, "example_string"); - assert_int_equal(module_data->num_resources, 2); - assert_string_equal(module_data->resources[0].name, "security"); - assert_int_equal(module_data->resources[0].num_relationships, 2); - assert_string_equal(module_data->resources[0].relationships[0], "alerts_v2"); - assert_string_equal(module_data->resources[0].relationships[1], "incidents"); - assert_string_equal(module_data->resources[1].name, "identityProtection"); - assert_int_equal(module_data->resources[1].num_relationships, 1); - assert_string_equal(module_data->resources[1].relationships[0], "riskyUsers"); -} - -void test_invalid_only_future_events(void **state) { - const char* config = - "yes\n" - "invalid\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'only_future_events' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_disabled_only_future_events(void **state) { - const char* config = - "yes\n" - "no\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_SUCCESS); - wm_ms_graph *module_data = (wm_ms_graph*)test->module->data; - assert_int_equal(module_data->enabled, 1); - assert_int_equal(module_data->only_future_events, 0); - assert_int_equal(module_data->curl_max_size, OS_SIZE_1048576); - assert_int_equal(module_data->run_on_start, 1); - assert_string_equal(module_data->version, "v1.0"); - assert_string_equal(module_data->auth_config[0]->tenant_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->client_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->secret_value, "example_string"); - assert_int_equal(module_data->num_resources, 2); - assert_string_equal(module_data->resources[0].name, "security"); - assert_int_equal(module_data->resources[0].num_relationships, 2); - assert_string_equal(module_data->resources[0].relationships[0], "alerts_v2"); - assert_string_equal(module_data->resources[0].relationships[1], "incidents"); - assert_string_equal(module_data->resources[1].name, "identityProtection"); - assert_int_equal(module_data->resources[1].num_relationships, 1); - assert_string_equal(module_data->resources[1].relationships[0], "riskyUsers"); -} - -void test_invalid_curl_max_size(void **state) { - const char* config = - "yes\n" - "yes\n" - "invalid\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'ms-graph'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_invalid_negative_curl_max_size(void **state) { - const char* config = - "yes\n" - "yes\n" - "-1\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'ms-graph'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_value_curl_max_size(void **state) { - const char* config = - "yes\n" - "yes\n" - "4k\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_SUCCESS); - wm_ms_graph *module_data = (wm_ms_graph*)test->module->data; - assert_int_equal(module_data->curl_max_size, 4096); -} - -void test_invalid_run_on_start(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "invalid\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'run_on_start' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_disabled_run_on_start(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "no\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_SUCCESS); - wm_ms_graph *module_data = (wm_ms_graph*)test->module->data; - assert_int_equal(module_data->enabled, 1); - assert_int_equal(module_data->only_future_events, 1); - assert_int_equal(module_data->curl_max_size, OS_SIZE_1048576); - assert_int_equal(module_data->run_on_start, 0); - assert_string_equal(module_data->version, "v1.0"); - assert_string_equal(module_data->auth_config[0]->tenant_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->client_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->secret_value, "example_string"); - assert_int_equal(module_data->num_resources, 2); - assert_string_equal(module_data->resources[0].name, "security"); - assert_int_equal(module_data->resources[0].num_relationships, 2); - assert_string_equal(module_data->resources[0].relationships[0], "alerts_v2"); - assert_string_equal(module_data->resources[0].relationships[1], "incidents"); - assert_string_equal(module_data->resources[1].name, "identityProtection"); - assert_int_equal(module_data->resources[1].num_relationships, 1); - assert_string_equal(module_data->resources[1].relationships[0], "riskyUsers"); -} - -void test_invalid_interval(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "invalid\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_INVALID); -} - -void test_invalid_version(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "invalid\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'version' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_api_auth(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'api_auth' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_empty_api_auth(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'api_auth' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_invalid_client_id(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " \n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'client_id' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_client_id(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'client_id' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_invalid_tenant_id(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " \n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'tenant_id' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_tenant_id(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'tenant_id' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_invalid_secret_value(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " \n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'secret_value' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_secret_value(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'secret_value' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_invalid_api_type(void **state){ - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " invalid\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'api_type' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_api_type(void **state){ - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'api_type' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_empty_api_type(void **state){ - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " \n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'api_type' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_invalid_attribute_api_type(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - " attribute\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1233): Invalid attribute 'invalid' in the configuration: 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_resource(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'resource' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_empty_resource(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'resource' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_name(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'name' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_empty_name(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " \n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'name' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_missing_relationship(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1228): Element 'relationship' without any option."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_NOTFOUND); -} - -void test_empty_relationship(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " \n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'relationship' at module 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -void test_invalid_attribute_resource(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " resource\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "(1233): Invalid attribute 'invalid' in the configuration: 'ms-graph'."); - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_CFGERR); -} - -// Main program tests -void test_normal_config(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " global\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_SUCCESS); - wm_ms_graph *module_data = (wm_ms_graph*)test->module->data; - assert_int_equal(module_data->enabled, 1); - assert_int_equal(module_data->only_future_events, 1); - assert_int_equal(module_data->curl_max_size, OS_SIZE_1048576); - assert_int_equal(module_data->run_on_start, 1); - assert_string_equal(module_data->version, "v1.0"); - assert_string_equal(module_data->auth_config[0]->tenant_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->client_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->secret_value, "example_string"); - assert_int_equal(module_data->num_resources, 2); - assert_string_equal(module_data->resources[0].name, "security"); - assert_int_equal(module_data->resources[0].num_relationships, 2); - assert_string_equal(module_data->resources[0].relationships[0], "alerts_v2"); - assert_string_equal(module_data->resources[0].relationships[1], "incidents"); - assert_string_equal(module_data->resources[1].name, "identityProtection"); - assert_int_equal(module_data->resources[1].num_relationships, 1); - assert_string_equal(module_data->resources[1].relationships[0], "riskyUsers"); -} - -void test_normal_config_api_type_gcc(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " gcc-high\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_SUCCESS); - wm_ms_graph *module_data = (wm_ms_graph*)test->module->data; - assert_int_equal(module_data->enabled, 1); - assert_int_equal(module_data->only_future_events, 1); - assert_int_equal(module_data->curl_max_size, OS_SIZE_1048576); - assert_int_equal(module_data->run_on_start, 1); - assert_string_equal(module_data->version, "v1.0"); - assert_string_equal(module_data->auth_config[0]->tenant_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->client_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->secret_value, "example_string"); - assert_string_equal(module_data->auth_config[0]->login_fqdn, "login.microsoftonline.us"); - assert_string_equal(module_data->auth_config[0]->query_fqdn, "graph.microsoft.us"); - assert_int_equal(module_data->num_resources, 2); - assert_string_equal(module_data->resources[0].name, "security"); - assert_int_equal(module_data->resources[0].num_relationships, 2); - assert_string_equal(module_data->resources[0].relationships[0], "alerts_v2"); - assert_string_equal(module_data->resources[0].relationships[1], "incidents"); - assert_string_equal(module_data->resources[1].name, "identityProtection"); - assert_int_equal(module_data->resources[1].num_relationships, 1); - assert_string_equal(module_data->resources[1].relationships[0], "riskyUsers"); -} - -void test_normal_config_api_type_dod(void **state) { - const char* config = - "yes\n" - "yes\n" - "1M\n" - "yes\n" - "5m\n" - "v1.0\n" - "\n" - " example_string\n" - " example_string\n" - " example_string\n" - " dod\n" - "\n" - "\n" - " security\n" - " alerts_v2\n" - " incidents\n" - "\n" - "\n" - " identityProtection\n" - " riskyUsers\n" - "\n" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(config, &(test->xml)); - assert_int_equal(wm_ms_graph_read(&(test->xml), test->nodes, test->module), OS_SUCCESS); - wm_ms_graph *module_data = (wm_ms_graph*)test->module->data; - assert_int_equal(module_data->enabled, 1); - assert_int_equal(module_data->only_future_events, 1); - assert_int_equal(module_data->curl_max_size, OS_SIZE_1048576); - assert_int_equal(module_data->run_on_start, 1); - assert_string_equal(module_data->version, "v1.0"); - assert_string_equal(module_data->auth_config[0]->tenant_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->client_id, "example_string"); - assert_string_equal(module_data->auth_config[0]->secret_value, "example_string"); - assert_string_equal(module_data->auth_config[0]->login_fqdn, "login.microsoftonline.us"); - assert_string_equal(module_data->auth_config[0]->query_fqdn, "dod-graph.microsoft.us"); - assert_int_equal(module_data->num_resources, 2); - assert_string_equal(module_data->resources[0].name, "security"); - assert_int_equal(module_data->resources[0].num_relationships, 2); - assert_string_equal(module_data->resources[0].relationships[0], "alerts_v2"); - assert_string_equal(module_data->resources[0].relationships[1], "incidents"); - assert_string_equal(module_data->resources[1].name, "identityProtection"); - assert_int_equal(module_data->resources[1].num_relationships, 1); - assert_string_equal(module_data->resources[1].relationships[0], "riskyUsers"); -} - -void test_cleanup() { - expect_string(__wrap__mtinfo, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module shutdown."); - wm_ms_graph_cleanup(); -} - -void test_setup_complete(void **state) { - wm_ms_graph* module_data = (wm_ms_graph *)*state; - - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_string", module_data->auth_config[0]->client_id); - os_strdup("example_string", module_data->auth_config[0]->tenant_id); - os_strdup("example_string", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource) * 2, module_data->resources); - os_strdup("security", module_data->resources[0].name); - os_strdup("identityProtection", module_data->resources[1].name); - module_data->num_resources = 2; - os_malloc(sizeof(char*) * 2, module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - os_strdup("incidents", module_data->resources[0].relationships[1]); - module_data->resources[0].num_relationships = 2; - os_malloc(sizeof(char*) * 2, module_data->resources[1].relationships); - os_strdup("alerts_v1", module_data->resources[1].relationships[0]); - os_strdup("incidents1", module_data->resources[1].relationships[1]); - module_data->resources[1].num_relationships = 2; - - expect_string(__wrap_wm_state_io, tag, "ms-graph"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_value(__wrap_wm_state_io, state, &module_data->state); - expect_value(__wrap_wm_state_io, size, sizeof(module_data->state)); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, -1); - - expect_string(__wrap__mterror, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "Unable to connect to Message Queue. Exiting..."); - - wm_ms_graph_setup(module_data); -} - -void test_main_token(void **state) { - current_time = 1; - unsigned int run_on_start = 1; - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"access_token\":\"token_value\",\"expires_in\":-1}", response->body); - os_strdup("test", response->header); - - will_return(__wrap_FOREVER, 1); - - expect_string(__wrap_wm_state_io, tag, "ms-graph"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_value(__wrap_wm_state_io, state, &module_data->state); - expect_value(__wrap_wm_state_io, size, sizeof(module_data->state)); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 1); - - expect_string(__wrap__mtinfo, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Started module."); - - expect_value(__wrap_sched_scan_get_time_until_next_scan, config, &module_data->scan_config); - expect_string(__wrap_sched_scan_get_time_until_next_scan, MODULE_TAG, WM_MS_GRAPH_LOGTAG); - expect_value(__wrap_sched_scan_get_time_until_next_scan, run_on_start, 1); - will_return(__wrap_sched_scan_get_time_until_next_scan, 1); - - char* test_date = strdup("2023/08/07 12:00:00"); - expect_value(__wrap_w_get_timestamp, time, 0); - will_return(__wrap_w_get_timestamp, test_date); - - expect_string(__wrap__mtdebug1, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mtdebug1, formatted_msg, "Waiting until: 2023/08/07 12:00:00"); - - expect_string(__wrap__mtinfo, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Obtaining access token."); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - will_return(__wrap_FOREVER, 0); - - wm_ms_graph_main(module_data); -} - -void test_main_relationships(void **state) { - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = true; - - os_strdup("token", module_data->auth_config[0]->access_token); - module_data->auth_config[0]->token_expiration_time = 276447231; - - will_return(__wrap_FOREVER, 1); - - expect_string(__wrap_wm_state_io, tag, "ms-graph"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_value(__wrap_wm_state_io, state, &module_data->state); - expect_value(__wrap_wm_state_io, size, sizeof(module_data->state)); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 1); - - expect_value(__wrap_sched_scan_get_time_until_next_scan, config, &module_data->scan_config); - expect_string(__wrap_sched_scan_get_time_until_next_scan, MODULE_TAG, WM_MS_GRAPH_LOGTAG); - expect_value(__wrap_sched_scan_get_time_until_next_scan, run_on_start, 1); - will_return(__wrap_sched_scan_get_time_until_next_scan, 0); - - expect_string(__wrap__mtinfo, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Started module."); - - expect_string(__wrap__mtinfo, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Scanning tenant 'example_tenant'"); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - will_return(__wrap_isDebug, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2023-02-08T12:24:56Z' for tenant 'example_tenant' resource 'security' and relationship 'alerts_v2', waiting '60' seconds to run first scan."); - - will_return(__wrap_FOREVER, 0); - - wm_ms_graph_main(module_data); -} - -void test_disabled(void **state) { - wm_ms_graph* module_data = (wm_ms_graph *)*state; - module_data->enabled = false; - - expect_string(__wrap__mtinfo, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mtinfo, formatted_msg, "Module disabled. Exiting..."); - - wm_ms_graph_main(module_data); -} - -void test_no_resources(void **state) { - wm_ms_graph* module_data = (wm_ms_graph *)*state; - module_data->enabled = true; - module_data->num_resources = 0; - - expect_string(__wrap__mterror, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "Invalid module configuration (Missing API info, resources, relationships). Exiting..."); - - wm_ms_graph_main(module_data); -} - -void test_no_relationships(void **state) { - wm_ms_graph* module_data = (wm_ms_graph *)*state; - module_data->enabled = true; - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - module_data->resources[0].num_relationships = 0; - module_data->num_resources = 1; - - expect_string(__wrap__mterror, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "Invalid module configuration (Missing API info, resources, relationships). Exiting..."); - - wm_ms_graph_main(module_data); - - os_free(module_data->resources); - module_data->num_resources = 0; -} - -void test_dump(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_string", module_data->auth_config[0]->client_id); - os_strdup("example_string", module_data->auth_config[0]->tenant_id); - os_strdup("example_string", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - - cJSON* dump = wm_ms_graph_dump(module_data); - char* dump_text = cJSON_PrintUnformatted(dump); - - assert_string_equal(dump_text, "{\"ms_graph\":{\"enabled\":\"yes\",\"only_future_events\":\"no\",\"curl_max_size\":1024,\"run_on_start\":\"yes\",\"version\":\"v1.0\",\"wday\":\"sunday\",\"api_auth\":{\"client_id\":\"example_string\",\"tenant_id\":\"example_string\",\"secret_value\":\"example_string\",\"api_type\":\"global\",\"name\":\"security\"},\"resources\":[{\"relationship\":\"alerts_v2\"}]}}"); - - cJSON_Delete(dump); - os_free(dump_text); -} - -void test_dump_gcc_configuration(void **state) { - /* - no - yes - 1M - no - v1.0 - - example_string - example_string - example_string - gcc-high - - - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = false; - module_data->only_future_events = true; - module_data->curl_max_size = 1024L; - module_data->run_on_start = false; - os_strdup("v1.0", module_data->version); - os_strdup("example_string", module_data->auth_config[0]->client_id); - os_strdup("example_string", module_data->auth_config[0]->tenant_id); - os_strdup("example_string", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GCC_HIGH_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GCC_HIGH_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - module_data->resources[0].name = NULL; - module_data->num_resources = 1; - - cJSON* dump = wm_ms_graph_dump(module_data); - char* dump_text = cJSON_PrintUnformatted(dump); - - assert_string_equal(dump_text, "{\"ms_graph\":{\"enabled\":\"no\",\"only_future_events\":\"yes\",\"curl_max_size\":1024,\"run_on_start\":\"no\",\"version\":\"v1.0\",\"wday\":\"sunday\",\"api_auth\":{\"client_id\":\"example_string\",\"tenant_id\":\"example_string\",\"secret_value\":\"example_string\",\"api_type\":\"gcc-high\"}}}"); - - cJSON_Delete(dump); - os_free(dump_text); - os_free(module_data->resources[0].name); - os_free(module_data->resources); - module_data->num_resources = 0; -} - -void test_dump_dod_configuration(void **state) { - /* - no - yes - 1M - no - v1.0 - - example_string - example_string - example_string - dod - - - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = false; - module_data->only_future_events = true; - module_data->curl_max_size = 1024L; - module_data->run_on_start = false; - os_strdup("v1.0", module_data->version); - os_strdup("example_string", module_data->auth_config[0]->client_id); - os_strdup("example_string", module_data->auth_config[0]->tenant_id); - os_strdup("example_string", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_DOD_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_DOD_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - - cJSON* dump = wm_ms_graph_dump(module_data); - char* dump_text = cJSON_PrintUnformatted(dump); - - assert_string_equal(dump_text, "{\"ms_graph\":{\"enabled\":\"no\",\"only_future_events\":\"yes\",\"curl_max_size\":1024,\"run_on_start\":\"no\",\"version\":\"v1.0\",\"wday\":\"sunday\",\"api_auth\":{\"client_id\":\"example_string\",\"tenant_id\":\"example_string\",\"secret_value\":\"example_string\",\"api_type\":\"dod\"}}}"); - - cJSON_Delete(dump); - os_free(dump_text); -} - -void test_wm_ms_graph_get_access_token_no_response(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "No response received when attempting to obtain access token."); - - wm_ms_graph_get_access_token(module_data->auth_config[0], max_size); - - assert_null(module_data->auth_config[0]->access_token); -} - -void test_wm_ms_graph_get_access_token_unsuccessful_status_code(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 400; - os_strdup("{\"error\":\"bad_request\"}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Received unsuccessful status code when attempting to obtain access token: Status code was '400' & response was '{\"error\":\"bad_request\"}'"); - - wm_ms_graph_get_access_token(module_data->auth_config[0], max_size); - - assert_null(module_data->auth_config[0]->access_token); -} - -void test_wm_ms_graph_get_access_token_curl_max_size(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = true; - os_strdup("{\"error\":\"bad_request\"}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Reached maximum CURL size when attempting to obtain access token. Consider increasing the value of 'curl_max_size'."); - - wm_ms_graph_get_access_token(module_data->auth_config[0], max_size); - - assert_null(module_data->auth_config[0]->access_token); -} - -void test_wm_ms_graph_get_access_token_parse_json_fail(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("no json", response->body); - os_strdup("test", response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Failed to parse access token JSON body."); - - wm_ms_graph_get_access_token(module_data->auth_config[0], max_size); - - assert_null(module_data->auth_config[0]->access_token); -} - -void test_wm_ms_graph_get_access_token_success(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - curl_response* response; - current_time = 100; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"access_token\":\"token_value\",\"expires_in\":123}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - wm_ms_graph_get_access_token(module_data->auth_config[0], max_size); - - assert_string_equal(module_data->auth_config[0]->access_token, "token_value"); -#ifdef WIN32 - assert_int_equal(module_data->auth_config[0]->token_expiration_time, 123); -#else - assert_int_equal(module_data->auth_config[0]->token_expiration_time, 223); -#endif -} - -void test_wm_ms_graph_get_access_token_no_access_token(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"no_access_token\":\"token_value\",\"expires_in\":123}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Incomplete access token response, value or expiration time not present."); - - wm_ms_graph_get_access_token(module_data->auth_config[0], max_size); -} - -void test_wm_ms_graph_get_access_token_no_expire_time(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_string - example_string - example_string - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"access_token\":\"token_value\",\"no_expires_in\":123}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Access Token URL: 'https://login.microsoftonline.com/example_tenant/oauth2/v2.0/token'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Incomplete access token response, value or expiration time not present."); - - wm_ms_graph_get_access_token(module_data->auth_config[0], max_size); -} - -void test_wm_ms_graph_scan_relationships_single_initial_only_no(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = true; - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - will_return(__wrap_isDebug, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2023-02-08T12:24:56Z' for tenant 'example_tenant' resource 'security' and relationship 'alerts_v2', waiting '60' seconds to run first scan."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_initial_only_yes_fail_write(void **state) { - /* - yes - yes - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - module_data->enabled = true; - module_data->only_future_events = true; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = true; - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap__mterror, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "Couldn't save running state."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_initial_only_no_next_time_no_response(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_strdup("token", module_data->auth_config[0]->access_token); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = true; - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "No response received when attempting to get relationship 'alerts_v2' from resource 'security' on API version 'v1.0'."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_no_initial_no_timestamp(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - will_return(__wrap_isDebug, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2023-02-08T12:24:56Z' for tenant 'example_tenant' resource 'security' and relationship 'alerts_v2', waiting '60' seconds to run first scan."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_unsuccessful_status_code(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 400; - os_strdup("{\"error\":\"bad_request\"}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Received unsuccessful status code when attempting to get relationship 'alerts_v2' logs: Status code was '400' & response was '{\"error\":\"bad_request\"}'"); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_reached_curl_size(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = true; - os_strdup("{\"error\":\"bad_request\"}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Reached maximum CURL size when attempting to get relationship 'alerts_v2' logs. Consider increasing the value of 'curl_max_size'."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_failed_parse(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("no json", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtwarn, formatted_msg, "Failed to parse relationship 'alerts_v2' JSON body."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_no_logs(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - curl_response* response; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"value\":[]}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug2, formatted_msg, "No new logs received."); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2023-02-08T12:24:56Z' for tenant 'example_tenant' resource 'security' and relationship 'alerts_v2', waiting '60' seconds to run next scan."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_success_one_log(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - curl_response* response; - wm_max_eps = 1; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"value\":[{\"full_log\":\"log1\"}]}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug2, formatted_msg, "Sending log: '{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}'"); - - int result = 1; - queue_fd = 0; - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "ms-graph"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, result); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2023-02-08T12:24:56Z' for tenant 'example_tenant' resource 'security' and relationship 'alerts_v2', waiting '60' seconds to run next scan."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_success_two_logs(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource), module_data->resources); - os_strdup("security", module_data->resources[0].name); - module_data->num_resources = 1; - os_malloc(sizeof(char*), module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - curl_response* response; - wm_max_eps = 1; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"value\":[{\"full_log\":\"log1\"},{\"full_log\":\"log2\"}]}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug2, formatted_msg, "Sending log: '{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}'"); - - queue_fd = 0; - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "ms-graph"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, -1); - - will_return(__wrap_strerror, "Error"); - - expect_string(__wrap__mterror, tag, WM_MS_GRAPH_LOGTAG); - expect_string(__wrap__mterror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'Error'"); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug2, formatted_msg, "Sending log: '{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log2\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}'"); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log2\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "ms-graph"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2023-02-08T12:24:56Z' for tenant 'example_tenant' resource 'security' and relationship 'alerts_v2', waiting '60' seconds to run next scan."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -void test_wm_ms_graph_scan_relationships_single_success_two_resources(void **state) { - /* - yes - no - 1M - yes - v1.0 - - example_client - example_tenant - example_secret - global - - - security - alerts_v2 - - - auditlogs - signIns - - */ - wm_ms_graph* module_data = (wm_ms_graph *)*state; - wm_ms_graph_state_t relationship_state_struc; - wm_ms_graph_state_t relationship_state_struc_2; - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config); - os_calloc(1, sizeof(wm_ms_graph_auth), module_data->auth_config[0]); - relationship_state_struc.next_time = 10; - relationship_state_struc_2.next_time = 10; - module_data->enabled = true; - module_data->only_future_events = false; - module_data->curl_max_size = 1024L; - module_data->run_on_start = true; - module_data->scan_config.interval = 60; - os_strdup("v1.0", module_data->version); - os_strdup("example_client", module_data->auth_config[0]->client_id); - os_strdup("example_tenant", module_data->auth_config[0]->tenant_id); - os_strdup("example_secret", module_data->auth_config[0]->secret_value); - os_strdup(WM_MS_GRAPH_GLOBAL_API_LOGIN_FQDN, module_data->auth_config[0]->login_fqdn); - os_strdup(WM_MS_GRAPH_GLOBAL_API_QUERY_FQDN, module_data->auth_config[0]->query_fqdn); - os_malloc(sizeof(wm_ms_graph_resource) * 2, module_data->resources); - os_strdup("security", module_data->resources[0].name); - os_strdup("auditlogs", module_data->resources[1].name); - module_data->num_resources = 2; - os_malloc(sizeof(char*) * 2, module_data->resources[0].relationships); - os_strdup("alerts_v2", module_data->resources[0].relationships[0]); - module_data->resources[0].num_relationships = 1; - os_malloc(sizeof(char*) * 2, module_data->resources[1].relationships); - os_strdup("signIns", module_data->resources[1].relationships[0]); - module_data->resources[1].num_relationships = 1; - size_t max_size = OS_SIZE_8192; - bool initial = false; - curl_response* response; - wm_max_eps = 1; - - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"value\":[{\"full_log\":\"log1\"}]}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/security/alerts_v2?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug2, formatted_msg, "Sending log: '{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}'"); - - queue_fd = 0; - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1\",\"resource\":\"security\",\"relationship\":\"alerts_v2\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "ms-graph"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-security-alerts_v2"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2023-02-08T12:24:56Z' for tenant 'example_tenant' resource 'security' and relationship 'alerts_v2', waiting '60' seconds to run next scan."); - - // resource auditlogs - os_calloc(1, sizeof(curl_response), response); - response->status_code = 200; - response->max_size_reached = false; - os_strdup("{\"value\":[{\"full_log\":\"log1_resource_2\"}]}", response->body); - os_strdup("test", response->header); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-auditlogs-signIns"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&relationship_state_struc_2); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug1, formatted_msg, "Microsoft Graph API Log URL: 'https://graph.microsoft.com/v1.0/auditlogs/signIns?$filter=createdDateTime+gt+2023-02-08T12:24:56Z'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_MS_GRAPH_DEFAULT_TIMEOUT); - will_return(__wrap_wurl_http_request, response); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mtdebug2, formatted_msg, "Sending log: '{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1_resource_2\",\"resource\":\"auditlogs\",\"relationship\":\"signIns\"}}'"); - - queue_fd = 0; - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"ms-graph\",\"ms-graph\":{\"full_log\":\"log1_resource_2\",\"resource\":\"auditlogs\",\"relationship\":\"signIns\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "ms-graph"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2023-02-08T12:24:56Z"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap_wm_state_io, tag, "ms-graph-example_tenant-auditlogs-signIns"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:ms-graph"); - expect_string(__wrap__mterror, formatted_msg, "Couldn't save running state."); - - wm_ms_graph_scan_relationships(module_data, initial); -} - -int main(void) { - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test(test_cleanup), - cmocka_unit_test_setup_teardown(test_bad_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_empty_module, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_enabled, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_enabled_no, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_only_future_events, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_disabled_only_future_events, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_curl_max_size, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_negative_curl_max_size, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_value_curl_max_size, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_run_on_start, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_disabled_run_on_start, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_version, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_api_auth, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_empty_api_auth, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_client_id, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_client_id, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_tenant_id, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_tenant_id, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_secret_value, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_secret_value, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_api_type, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_api_type, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_empty_api_type, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_attribute_api_type, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_resource, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_empty_resource, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_name, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_empty_name, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_missing_relationship, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_empty_relationship, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_attribute_resource, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_normal_config, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_normal_config_api_type_gcc, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_normal_config_api_type_dod, setup_test_read, teardown_test_read) - }; - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_setup_complete, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_main_token, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_main_relationships, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_disabled, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_no_resources, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_no_relationships, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_dump, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_dump_gcc_configuration, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_dump_dod_configuration, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_get_access_token_no_response, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_get_access_token_unsuccessful_status_code, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_get_access_token_curl_max_size, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_get_access_token_parse_json_fail, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_get_access_token_success, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_get_access_token_no_access_token, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_get_access_token_no_expire_time, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_initial_only_no, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_initial_only_yes_fail_write, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_initial_only_no_next_time_no_response, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_no_initial_no_timestamp, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_unsuccessful_status_code, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_reached_curl_size, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_failed_parse, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_no_logs, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_success_one_log, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_success_two_logs, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_ms_graph_scan_relationships_single_success_two_resources, setup_conf, teardown_conf) - }; - int result = 0; - result = cmocka_run_group_tests(tests_without_startup, NULL, NULL); - result += cmocka_run_group_tests(tests_with_startup, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/office365/CMakeLists.txt b/src/unit_tests/wazuh_modules/office365/CMakeLists.txt deleted file mode 100644 index 62df7a2b3c3..00000000000 --- a/src/unit_tests/wazuh_modules/office365/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Tests list and flags -list(APPEND tests_names "test_wm_office365") -list(APPEND tests_flags "-Wl,--wrap,access -Wl,--wrap,wurl_http_request \ - -Wl,--wrap,wurl_free_response -Wl,--wrap,wm_sendmsg -Wl,--wrap,strftime -Wl,--wrap,gmtime_r \ - -Wl,--wrap,wm_state_io -Wl,--wrap,time -Wl,--wrap,StartMQ -Wl,--wrap,wfopen \ - -Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck \ -Wl,--wrap=is_fim_shutdown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown \ - -Wl,--wrap,fim_sync_push_msg -Wl,--wrap,fim_run_integrity -Wl,--wrap,fim_db_remove_path \ - -Wl,--wrap,fim_db_get_path -Wl,--wrap,fim_db_transaction_start -Wl,--wrap,fim_db_transaction_deleted_rows \ - -Wl,--wrap,fim_db_transaction_sync_row -Wl,--wrap,fim_db_file_update -Wl,--wrap,fim_db_file_pattern_search \ - -Wl,--wrap,fim_db_init ${DEBUG_OP_WRAPPERS} -Wl,--wrap,isDebug") - -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB office365 ../../../wazuh_modules/*.o) -list(REMOVE_ITEM office365 ../../../wazuh_modules/main.o) - -add_library(OFFICE365_O STATIC ${office365}) - -set_source_files_properties( - ${office365} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - OFFICE365_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(OFFICE365_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -if(${TARGET} STREQUAL "winagent") - link_directories(${SRC_FOLDER}/syscheckd/build/bin) -endif(${TARGET} STREQUAL "winagent") - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - OFFICE365_O - -lcmocka - -ldl - -fprofile-arcs - -ftest-coverage - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - if(${TARGET} STREQUAL "winagent") - target_link_libraries(${test_name} fimdb) - endif(${TARGET} STREQUAL "winagent") - endif() - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/office365/test_wm_office365.c b/src/unit_tests/wazuh_modules/office365/test_wm_office365.c deleted file mode 100644 index 49381b9f854..00000000000 --- a/src/unit_tests/wazuh_modules/office365/test_wm_office365.c +++ /dev/null @@ -1,3261 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for Office365 Module - * */ - -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../wazuh_modules/wmodules.h" -#include "../wazuh_modules/wm_office365.h" -#include "../wazuh_modules/wm_office365.c" - -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wmodules_wrappers.h" -#include "../../wrappers/wazuh/shared/time_op_wrappers.h" -#include "../../wrappers/wazuh/shared/url_wrappers.h" -#include "../../wrappers/libc/time_wrappers.h" -#ifdef WIN32 -#include "../../wrappers/wazuh/shared/file_op_wrappers.h" -#endif - -int __wrap_access(const char *__name, int __type) { - check_expected(__name); - return mock_type(int); -} - -unsigned int __wrap_sleep(unsigned int __seconds) { - check_expected(__seconds); - return mock_type(unsigned int); -} - -unsigned int __wrap_gmtime_r(__attribute__ ((__unused__)) const time_t *t, __attribute__ ((__unused__)) struct tm *tm) { - return mock_type(unsigned int); -} - -int __wrap_isDebug() { - return mock(); -} - -//////////////// test wmodules-office365 ///////////////// - -typedef struct test_struct { - wm_office365 *office365_config; - curl_response* response; - char *root_c; -} test_struct_t; - -static int setup_conf(void **state) { - test_struct_t *init_data = NULL; - os_calloc(1,sizeof(test_struct_t), init_data); - os_calloc(1, sizeof(wm_office365), init_data->office365_config); - test_mode = 1; - *state = init_data; - return 0; -} - -static int teardown_conf(void **state) { - test_struct_t *data = (test_struct_t *)*state; - test_mode = 0; - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtinfo, formatted_msg, "Module Office365 finished."); - - wm_office365_destroy(data->office365_config); - os_free(data->root_c); - os_free(data); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test; - os_calloc(1, sizeof(test_structure), test); - os_calloc(1, sizeof(wmodule), test->module); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - if ((wm_office365*)test->module->data) { - if (((wm_office365*)test->module->data)->auth) { - os_free(((wm_office365*)test->module->data)->auth->tenant_id); - os_free(((wm_office365*)test->module->data)->auth->client_id); - os_free(((wm_office365*)test->module->data)->auth->client_secret_path); - os_free(((wm_office365*)test->module->data)->auth->client_secret); - os_free(((wm_office365*)test->module->data)->auth->login_fqdn); - os_free(((wm_office365*)test->module->data)->auth->management_fqdn); - if (((wm_office365*)test->module->data)->auth->next) { - os_free(((wm_office365*)test->module->data)->auth->next->tenant_id); - os_free(((wm_office365*)test->module->data)->auth->next->client_id); - os_free(((wm_office365*)test->module->data)->auth->next->client_secret_path); - os_free(((wm_office365*)test->module->data)->auth->next->client_secret); - os_free(((wm_office365*)test->module->data)->auth->next->login_fqdn); - os_free(((wm_office365*)test->module->data)->auth->next->management_fqdn); - if (((wm_office365*)test->module->data)->auth->next->next) { - os_free(((wm_office365*)test->module->data)->auth->next->next->tenant_id); - os_free(((wm_office365*)test->module->data)->auth->next->next->client_id); - os_free(((wm_office365*)test->module->data)->auth->next->next->client_secret_path); - os_free(((wm_office365*)test->module->data)->auth->next->next->client_secret); - os_free(((wm_office365*)test->module->data)->auth->next->next->login_fqdn); - os_free(((wm_office365*)test->module->data)->auth->next->next->management_fqdn); - os_free(((wm_office365*)test->module->data)->auth->next->next->next); - } - os_free(((wm_office365*)test->module->data)->auth->next->next); - } - os_free(((wm_office365*)test->module->data)->auth->next); - os_free(((wm_office365*)test->module->data)->auth); - } - if (((wm_office365*)test->module->data)->subscription) { - os_free(((wm_office365*)test->module->data)->subscription->subscription_name); - if (((wm_office365*)test->module->data)->subscription->next) { - os_free(((wm_office365*)test->module->data)->subscription->next->subscription_name); - } - if (((wm_office365*)test->module->data)->subscription->next->next) { - os_free(((wm_office365*)test->module->data)->subscription->next->next->subscription_name); - } - if (((wm_office365*)test->module->data)->subscription->next->next->next) { - os_free(((wm_office365*)test->module->data)->subscription->next->next->next->subscription_name); - } - if (((wm_office365*)test->module->data)->subscription->next->next->next->next) { - os_free(((wm_office365*)test->module->data)->subscription->next->next->next->next->subscription_name); - } - os_free(((wm_office365*)test->module->data)->subscription->next->next->next->next); - os_free(((wm_office365*)test->module->data)->subscription->next->next->next); - os_free(((wm_office365*)test->module->data)->subscription->next->next); - os_free(((wm_office365*)test->module->data)->subscription->next); - os_free(((wm_office365*)test->module->data)->subscription); - } - } - os_free(test->module->data); - os_free(test->module->tag); - os_free(test->module); - os_free(test); - return 0; -} - -void test_read_configuration(void **state) { - const char *string = - "no" - "no" - "10m" - "2048" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->only_future_events, 0); - assert_int_equal(module_data->interval, 600); - assert_int_equal(module_data->curl_max_size, 2048); - assert_string_equal(module_data->auth->tenant_id, "your_tenant_id"); - assert_string_equal(module_data->auth->client_id, "your_client_id"); - assert_string_equal(module_data->auth->client_secret, "your_secret"); - assert_string_equal(module_data->auth->login_fqdn, WM_OFFICE365_DEFAULT_API_LOGIN_FQDN); // retrocompatability test - assert_string_equal(module_data->auth->management_fqdn, WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN); // retrocompatability test - assert_string_equal(module_data->subscription->subscription_name, "Audit.AzureActiveDirectory"); - assert_string_equal(module_data->subscription->next->subscription_name, "Audit.Exchange"); - assert_string_equal(module_data->subscription->next->next->subscription_name, "Audit.SharePoint"); - assert_string_equal(module_data->subscription->next->next->next->subscription_name, "Audit.General"); - assert_string_equal(module_data->subscription->next->next->next->next->subscription_name, "DLP.All"); -} - -void test_read_configuration_1(void **state) { - const char *string = - "no" - "yes" - "10m" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "your_tenant_id_1" - "your_client_id_1" - "your_secret_1" - "gcc" - "" - "" - "your_tenant_id_2" - "your_client_id_2" - "/path/to/secret" - "gcc-high" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap_access, __name, "/path/to/secret"); - will_return(__wrap_access, 0); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->only_future_events, 1); - assert_int_equal(module_data->interval, 600); - assert_int_equal(module_data->curl_max_size, 2048); - assert_string_equal(module_data->auth->tenant_id, "your_tenant_id"); - assert_string_equal(module_data->auth->client_id, "your_client_id"); - assert_string_equal(module_data->auth->client_secret, "your_secret"); - assert_string_equal(module_data->auth->login_fqdn, WM_OFFICE365_DEFAULT_API_LOGIN_FQDN); - assert_string_equal(module_data->auth->management_fqdn, WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN); - assert_string_equal(module_data->auth->next->tenant_id, "your_tenant_id_1"); - assert_string_equal(module_data->auth->next->client_id, "your_client_id_1"); - assert_string_equal(module_data->auth->next->client_secret, "your_secret_1"); - assert_string_equal(module_data->auth->next->login_fqdn, WM_OFFICE365_GCC_API_LOGIN_FQDN); - assert_string_equal(module_data->auth->next->management_fqdn, WM_OFFICE365_GCC_API_MANAGEMENT_FQDN); - assert_string_equal(module_data->auth->next->next->tenant_id, "your_tenant_id_2"); - assert_string_equal(module_data->auth->next->next->client_id, "your_client_id_2"); - assert_string_equal(module_data->auth->next->next->client_secret_path, "/path/to/secret"); - assert_string_equal(module_data->auth->next->next->login_fqdn, WM_OFFICE365_GCC_HIGH_API_LOGIN_FQDN); - assert_string_equal(module_data->auth->next->next->management_fqdn, WM_OFFICE365_GCC_HIGH_API_MANAGEMENT_FQDN); - assert_string_equal(module_data->subscription->subscription_name, "Audit.AzureActiveDirectory"); - assert_string_equal(module_data->subscription->next->subscription_name, "Audit.Exchange"); - assert_string_equal(module_data->subscription->next->next->subscription_name, "Audit.SharePoint"); - assert_string_equal(module_data->subscription->next->next->next->subscription_name, "Audit.General"); - assert_string_equal(module_data->subscription->next->next->next->next->subscription_name, "DLP.All"); -} - -void test_read_default_configuration(void **state) { - const char *string = - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'subscriptions' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_interval(void **state) { - const char *string = - "no" - "no" - "10" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->only_future_events, 0); - assert_int_equal(module_data->interval, 10); - assert_int_equal(module_data->curl_max_size, 2048); - assert_string_equal(module_data->auth->tenant_id, "your_tenant_id"); - assert_string_equal(module_data->auth->client_id, "your_client_id"); - assert_string_equal(module_data->auth->client_secret, "your_secret"); - assert_string_equal(module_data->auth->login_fqdn, WM_OFFICE365_DEFAULT_API_LOGIN_FQDN); - assert_string_equal(module_data->auth->management_fqdn, WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN); - assert_string_equal(module_data->subscription->subscription_name, "Audit.AzureActiveDirectory"); - assert_string_equal(module_data->subscription->next->subscription_name, "Audit.Exchange"); - assert_string_equal(module_data->subscription->next->next->subscription_name, "Audit.SharePoint"); - assert_string_equal(module_data->subscription->next->next->next->subscription_name, "Audit.General"); - assert_string_equal(module_data->subscription->next->next->next->next->subscription_name, "DLP.All"); -} - -void test_read_interval_s(void **state) { - const char *string = - "no" - "no" - "50s" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->interval, 50); -} - -void test_read_interval_s_fail(void **state) { - const char *string = - "no" - "no" - "90000s" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'office365'. The maximum value allowed is 1 day."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_interval_m(void **state) { - const char *string = - "no" - "no" - "1m" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->interval, 60); -} - -void test_read_interval_m_fail(void **state) { - const char *string = - "no" - "no" - "1500m" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'office365'. The maximum value allowed is 1 day."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_interval_h(void **state) { - const char *string = - "no" - "no" - "2h" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->interval, 7200); -} - -void test_read_interval_h_fail(void **state) { - const char *string = - "no" - "no" - "30h" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'office365'. The maximum value allowed is 1 day."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_interval_d(void **state) { - const char *string = - "no" - "no" - "1d" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->interval, 86400); -} - -void test_read_interval_d_fail(void **state) { - const char *string = - "no" - "no" - "2d" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'office365'. The maximum value allowed is 1 day."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_curl_max_size(void **state) { - const char *string = - "no" - "no" - "10" - "4k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),0); - wm_office365 *module_data = (wm_office365*)test->module->data; - assert_int_equal(module_data->enabled, 0); - assert_int_equal(module_data->only_future_events, 0); - assert_int_equal(module_data->interval, 10); - assert_int_equal(module_data->curl_max_size, 4096); - assert_string_equal(module_data->auth->tenant_id, "your_tenant_id"); - assert_string_equal(module_data->auth->client_id, "your_client_id"); - assert_string_equal(module_data->auth->client_secret, "your_secret"); - assert_string_equal(module_data->auth->login_fqdn, WM_OFFICE365_DEFAULT_API_LOGIN_FQDN); - assert_string_equal(module_data->auth->management_fqdn, WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN); - assert_string_equal(module_data->subscription->subscription_name, "Audit.AzureActiveDirectory"); - assert_string_equal(module_data->subscription->next->subscription_name, "Audit.Exchange"); - assert_string_equal(module_data->subscription->next->next->subscription_name, "Audit.SharePoint"); - assert_string_equal(module_data->subscription->next->next->next->subscription_name, "Audit.General"); - assert_string_equal(module_data->subscription->next->next->next->next->subscription_name, "DLP.All"); -} - -void test_read_curl_max_size_invalid_1(void **state) { - const char *string = - "no" - "no" - "10" - "0" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'office365'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_curl_max_size_invalid_2(void **state) { - const char *string = - "no" - "no" - "10" - "-1" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'office365'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_curl_max_size_invalid_3(void **state) { - const char *string = - "no" - "no" - "10" - "invalid" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'curl_max_size' at module 'office365'. The minimum value allowed is 1KB."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_secret_path_and_secret(void **state) { - const char *string = - "" - "your_tenant_id" - "your_client_id" - "/path/to/secret" - "your_secret" - "commercial" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "It is not allowed to set 'client_secret' and 'client_secret_path' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_fake_tag(void **state) { - const char *string = - "no" - "no" - "1d" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - "ASD" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'fake-tag' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_fake_tag_1(void **state) { - const char *string = - "no" - "no" - "1d" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "ASD" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'fake-tag' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_1(void **state) { - const char *string = - "no" - "no" - "1d" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'subscription' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_2(void **state) { - const char *string = - "invalid\n" - "no" - "1d" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'enabled' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_3(void **state) { - const char *string = - "yes\n" - "no" - "invalid" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'office365'. The maximum value allowed is 1 day."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_content_4(void **state) { - const char *string = - "yes\n" - "invalid" - "yes" - "2k" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'only_future_events' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_invalid_interval(void **state) { - const char *string = - "yes\n" - "-10" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'interval' at module 'office365'. The maximum value allowed is 1 day."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_auth(void **state) { - const char *string = - "yes\n" - "10" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'api_auth' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_auth_1(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "No such tag 'invalid' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_tenant_id(void **state) { - const char *string = - "yes\n" - "10" - "" - "" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'tenant_id' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_tenant_id_1(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_client_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "'tenant_id' is missing at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_client_id(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'client_id' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_client_id_1(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "'client_id' is missing at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_client_secret(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_client_id" - "" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'client_secret' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_client_secret_1(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_client_id" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "'client_secret' is missing at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_client_secret_path(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_client_id" - "/path/to/secret" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap_access, __name, "/path/to/secret"); - will_return(__wrap_access, -1); - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'client_secret_path' at module 'office365': The path cannot be opened."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_client_secret_path_1(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_client_id" - "" - "commercial" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'client_secret_path' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_type(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "invalid" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Invalid content for tag 'api_type' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_error_api_type_1(void **state) { - const char *string = - "yes\n" - "10" - "" - "your_tenant_id" - "your_client_id" - "your_secret" - "" - "" - "" - "Audit.AzureActiveDirectory" - "Audit.Exchange" - "Audit.SharePoint" - "Audit.General" - "DLP.All" - "" - ; - test_structure *test = *state; - expect_string(__wrap__merror, formatted_msg, "Empty content for tag 'api_type' at module 'office365'."); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_office365_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_wm_office365_dump_no_options(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *test = "{\"office365\":{\"enabled\":\"no\",\"only_future_events\":\"no\"}}"; - - cJSON *root = wm_office365_dump(data->office365_config); - data->root_c = cJSON_PrintUnformatted(root); - cJSON_Delete(root); - - assert_string_equal(data->root_c, test); -} - -void test_wm_office365_dump_yes_options_empty_arrays(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->office365_config->enabled = 1; - data->office365_config->only_future_events = 1; - data->office365_config->interval = 10; - data->office365_config->curl_max_size = 1024; - data->office365_config->queue_fd = 1; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("", data->office365_config->subscription->subscription_name); - - char *test = "{\"office365\":{\"enabled\":\"yes\",\"only_future_events\":\"yes\",\"interval\":10,\"curl_max_size\":1024,\"api_auth\":[{}],\"subscriptions\":[\"\"]}}"; - - cJSON *root = wm_office365_dump(data->office365_config); - data->root_c = cJSON_PrintUnformatted(root); - cJSON_Delete(root); - - assert_string_equal(data->root_c, test); -} - -void test_wm_office365_dump_yes_options(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->office365_config->enabled = 1; - data->office365_config->only_future_events = 1; - data->office365_config->interval = 10; - data->office365_config->queue_fd = 1; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret_path", data->office365_config->auth->client_secret_path); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - char *test = "{\"office365\":{\"enabled\":\"yes\",\"only_future_events\":\"yes\",\"interval\":10,\"api_auth\":[{\"tenant_id\":\"test_tenant_id\",\"client_id\":\"test_client_id\",\"client_secret_path\":\"test_client_secret_path\",\"client_secret\":\"test_client_secret\",\"api_type\":\"commercial\"}],\"subscriptions\":[\"test_subscription_name\"]}}"; - - cJSON *root = wm_office365_dump(data->office365_config); - data->root_c = cJSON_PrintUnformatted(root); - cJSON_Delete(root); - - assert_string_equal(data->root_c, test); -} - -void test_wm_office365_main_disabled(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->office365_config->enabled = 0; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtinfo, formatted_msg, "Module Office365 disabled."); - - wm_office365_main(data->office365_config); -} - -void test_wm_office365_main_fail_StartMQ(void **state) { - test_struct_t *data = (test_struct_t *)*state; - data->office365_config->enabled = 1; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtinfo, formatted_msg, "Module Office365 started."); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mterror, formatted_msg, "Can't connect to queue. Closing module."); - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, -1); - - wm_office365_main(data->office365_config); -} - -void test_wm_office365_main_enable(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - - data->office365_config->enabled = 1; - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - data->office365_config->only_future_events = 1; - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 1); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtinfo, formatted_msg, "Module Office365 started."); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - will_return(__wrap_isDebug, 0); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting access token."); - - wm_office365_main(data->office365_config); -} - -void test_wm_office365_get_access_token_with_auth_secret(void **state) { - size_t max_size = OS_SIZE_8192; - test_struct_t *data = (test_struct_t *)*state; - data->response = NULL; - char *access_token = NULL; - char *error_msg = NULL; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting access token."); - - access_token = wm_office365_get_access_token(data->office365_config->auth, max_size, &error_msg); - - assert_null(access_token); - assert_null(error_msg); -} - -void test_wm_office365_get_access_token_with_auth_secret_path(void **state) { - size_t max_size = OS_SIZE_8192; - test_struct_t *data = (test_struct_t *)*state; - data->response = NULL; - char *access_token = NULL; - char *error_msg = NULL; - - const char *filename = "test_client_secret_path"; - FILE *outfile; - outfile = fopen(filename, "wb"); - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret_path", data->office365_config->auth->client_secret_path); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting access token."); - - test_mode = 0; - access_token = wm_office365_get_access_token(data->office365_config->auth, max_size, &error_msg); - test_mode = 1; - - fclose(outfile); - - assert_null(access_token); - assert_null(error_msg); -} - -void test_wm_office365_get_access_token_with_auth_secret_response_400(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *access_token = NULL; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":\"bad_request\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while getting access token: '{\"error\":\"bad_request\"}'"); - - expect_value(__wrap_wurl_free_response, response, data->response); - - access_token = wm_office365_get_access_token(data->office365_config->auth, max_size, &error_msg); - - assert_null(access_token); - assert_string_equal(error_msg, data->response->body); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - os_free(error_msg); -} - -void test_wm_office365_get_access_token_with_auth_secret_response_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *access_token = NULL; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":\"bad_request\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting access token."); - - access_token = wm_office365_get_access_token(data->office365_config->auth, max_size, &error_msg); - - assert_null(access_token); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_get_access_token_with_auth_secret_response_max_size_reached(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *access_token = NULL; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":\"bad_request\"}", data->response->body); - os_strdup("test", data->response->header); - data->response->max_size_reached = 1; - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Libcurl error, reached maximum response size."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - access_token = wm_office365_get_access_token(data->office365_config->auth, max_size, &error_msg); - - assert_null(access_token); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_get_access_token_with_auth_secret_error_json_response(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *access_token = NULL; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":\"bad_requ", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while parsing access token JSON response."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - access_token = wm_office365_get_access_token(data->office365_config->auth, max_size, &error_msg); - - assert_null(access_token); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_get_access_token_with_auth_secret_response_200(void **state) { - test_struct_t *data = (test_struct_t *)*state; - char *access_token = NULL; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"wazuh\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - - access_token = wm_office365_get_access_token(data->office365_config->auth, max_size, &error_msg); - - assert_string_equal(access_token, "wazuh"); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - os_free(access_token); -} - -void test_wm_office365_manage_subscription_start_response_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - char *token = "test_token"; - char* client_id = "test_client_id"; - char* management_fqdn = WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN; - int start = 1; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"wazuh\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while managing subscription."); - - value = wm_office365_manage_subscription(data->office365_config->subscription, management_fqdn, client_id, token, start, max_size, &error_msg); - - assert_int_equal(value, OS_INVALID); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_manage_subscription_start_code_200(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - char *token = "test_token"; - char* client_id = "test_client_id"; - char* management_fqdn = WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN; - int start = 1; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"wazuh\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - - value = wm_office365_manage_subscription(data->office365_config->subscription, management_fqdn, client_id, token, start, max_size, &error_msg); - - assert_int_equal(value, OS_SUCCESS); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_manage_subscription_stop_error_json_response(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - char *token = "test_token"; - char* client_id = "test_client_id"; - char* management_fqdn = WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN; - int start = 0; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":{\"code\":", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while parsing managing subscription JSON response."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - value = wm_office365_manage_subscription(data->office365_config->subscription, management_fqdn, client_id, token, start, max_size, &error_msg); - - assert_int_equal(value, OS_INVALID); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_manage_subscription_stop_error_max_size_reached(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - char *token = "test_token"; - char* client_id = "test_client_id"; - char* management_fqdn = WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN; - int start = 0; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":{\"code\":", data->response->body); - os_strdup("test", data->response->header); - data->response->max_size_reached = 1; - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Libcurl error, reached maximum response size."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - value = wm_office365_manage_subscription(data->office365_config->subscription, management_fqdn, client_id, token, start, max_size, &error_msg); - - assert_int_equal(value, OS_INVALID); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_manage_subscription_stop_code_400_error_AF20024(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - char *token = "test_token"; - char* client_id = "test_client_id"; - char* management_fqdn = WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN; - int start = 0; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":{\"code\":\"AF20024\"}}", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - - value = wm_office365_manage_subscription(data->office365_config->subscription, management_fqdn, client_id, token, start, max_size, &error_msg); - - assert_int_equal(value, OS_SUCCESS); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_manage_subscription_stop_code_400_error_different_AF20024(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - size_t max_size = OS_SIZE_8192; - char *error_msg = NULL; - - char *token = "test_token"; - char* client_id = "test_client_id"; - char* management_fqdn = WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN; - int start = 0; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":{\"code\":\"AF20023\"}}", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while managing subscription: '{\"error\":{\"code\":\"AF20023\"}}'"); - - expect_value(__wrap_wurl_free_response, response, data->response); - - value = wm_office365_manage_subscription(data->office365_config->subscription, management_fqdn, client_id, token, start, max_size, &error_msg); - - assert_int_equal(value, OS_INVALID); - assert_string_equal(error_msg, data->response->body); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - os_free(error_msg); -} - -void test_wm_office365_get_fail_by_tenant_and_subscription_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - wm_office365_fail *result = NULL; - wm_office365_fail *fails = NULL; - os_calloc(1, sizeof(wm_office365_fail), fails); - fails->subscription_name = "subscription"; - fails->tenant_id = "tenant"; - - char* subscription_name = "subscription_name"; - char* tenant_id = "tenant_id"; - - result = wm_office365_get_fail_by_tenant_and_subscription(fails, tenant_id, subscription_name); - assert_null(result); - os_free(fails); -} - -void test_wm_office365_get_fail_by_tenant_and_subscription_not_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - wm_office365_fail *result = NULL; - wm_office365_fail *fails = NULL; - os_calloc(1, sizeof(wm_office365_fail), fails); - fails->subscription_name = "subscription_name"; - fails->tenant_id = "tenant_id"; - - char* subscription_name = "subscription_name"; - char* tenant_id = "tenant_id"; - - result = wm_office365_get_fail_by_tenant_and_subscription(fails, tenant_id, subscription_name); - assert_string_equal(result->tenant_id, tenant_id); - assert_string_equal(result->subscription_name, subscription_name); - - os_free(fails); -} - -void test_wm_office365_get_content_blobs_response_null(void **state) { - size_t max_size = OS_SIZE_8192; - char* client_id = "test_client_id"; - const char* url = "test_url"; - const char* token = "test_token"; - char** next_page; - bool buffer_size_reached = 0; - char *error_msg = NULL; - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting content blobs."); - - cJSON *blob = wm_office365_get_content_blobs(url, token, next_page, max_size, &buffer_size_reached, &error_msg); - assert_null(blob); - assert_null(error_msg); - cJSON_Delete(blob); -} - -void test_wm_office365_get_content_blobs_response_max_size_reached(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - - char* client_id = "test_client_id"; - const char* url = "test_url"; - const char* token = "test_token"; - char** next_page; - bool buffer_size_reached = 0; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"wazuh\"}", data->response->body); - os_strdup("test", data->response->header); - data->response->max_size_reached = 1; - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Libcurl error, reached maximum response size."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - cJSON *blob = wm_office365_get_content_blobs(url, token, next_page, max_size, &buffer_size_reached, &error_msg); - assert_null(blob); - assert_null(error_msg); - assert_int_equal(buffer_size_reached, 1); - cJSON_Delete(blob); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_get_content_blobs_error_json_response(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - - char* client_id = "test_client_id"; - const char* url = "test_url"; - const char* token = "test_token"; - char** next_page; - bool buffer_size_reached = 0; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while parsing content blobs JSON response."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - cJSON *blob = wm_office365_get_content_blobs(url, token, next_page, max_size, &buffer_size_reached, &error_msg); - assert_null(blob); - assert_null(error_msg); - cJSON_Delete(blob); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_get_content_blobs_bad_response(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - - char* client_id = "test_client_id"; - const char* url = "test_url"; - const char* token = "test_token"; - char** next_page; - bool buffer_size_reached = 0; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"response\":\"test\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while getting content blobs: '{\"response\":\"test\"}'"); - - expect_value(__wrap_wurl_free_response, response, data->response); - - cJSON *blob = wm_office365_get_content_blobs(url, token, next_page, max_size, &buffer_size_reached, &error_msg); - assert_null(blob); - assert_string_equal(error_msg, data->response->body); - cJSON_Delete(blob); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - os_free(error_msg); -} - -void test_wm_office365_get_content_blobs_400_code_AF20055(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - - char* client_id = "test_client_id"; - const char* url = "test_url"; - const char* token = "test_token"; - char** next_page; - bool buffer_size_reached = 0; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":{\"code\":\"AF20055\"}}", data->response->body); - os_strdup("NextPageUri: valueNextPageUri", data->response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - - cJSON *blob = wm_office365_get_content_blobs(url, token, next_page, max_size, &buffer_size_reached, &error_msg); - assert_non_null(blob); - assert_null(error_msg); - cJSON_Delete(blob); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_scan_failure_action_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - wm_office365_fail *fails = NULL; - os_calloc(1, sizeof(wm_office365_fail), fails); - fails->subscription_name = "subscription"; - fails->tenant_id = "tenant"; - - char* subscription_name = "subscription_name"; - char* tenant_id = "tenant_id"; - int queue_fd = 0; - char *error_msg = NULL; - - wm_office365_scan_failure_action(&fails, tenant_id, subscription_name, error_msg, queue_fd); - assert_string_equal(fails->next->tenant_id, tenant_id); - assert_string_equal(fails->next->subscription_name, subscription_name); - - os_free(fails->next->tenant_id); - os_free(fails->next->subscription_name); - os_free(fails->next); - os_free(fails); -} - -void test_wm_office365_scan_failure_action_no_fail(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - wm_office365_fail *fails = NULL; - - char* subscription_name = "subscription_name"; - char* tenant_id = "tenant_id"; - int queue_fd = 0; - char *error_msg = NULL; - - wm_office365_scan_failure_action(&fails, tenant_id, subscription_name, error_msg, queue_fd); - assert_string_equal(fails->tenant_id, tenant_id); - assert_string_equal(fails->subscription_name, subscription_name); - - os_free(fails->tenant_id); - os_free(fails->subscription_name); - os_free(fails); -} - -void test_wm_office365_scan_failure_action_null_mult_next(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - wm_office365_fail *fails = NULL; - os_calloc(1, sizeof(wm_office365_fail), fails); - fails->subscription_name = "subscription"; - fails->tenant_id = "tenant"; - os_calloc(1, sizeof(wm_office365_fail), fails->next); - fails->next->subscription_name = "subscription1"; - fails->next->tenant_id = "tenant1"; - - char* subscription_name = "subscription_name"; - char* tenant_id = "tenant_id"; - int queue_fd = 0; - char *error_msg = NULL; - - wm_office365_scan_failure_action(&fails, tenant_id, subscription_name, error_msg, queue_fd); - assert_string_equal(fails->next->next->tenant_id, tenant_id); - assert_string_equal(fails->next->next->subscription_name, subscription_name); - - os_free(fails->next->next->tenant_id); - os_free(fails->next->next->subscription_name); - os_free(fails->next->next); - os_free(fails->next); - os_free(fails); -} - -void test_wm_office365_scan_failure_action_not_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - wm_office365_fail *fails = NULL; - os_calloc(1, sizeof(wm_office365_fail), fails); - fails->subscription_name = "subscription_name"; - fails->tenant_id = "tenant_id"; - fails->fails = 2; - wm_max_eps = 1; - - char* subscription_name = "subscription_name"; - char* tenant_id = "tenant_id"; - int queue_fd = 1; - char *error_msg = NULL; - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtwarn, formatted_msg, "Sending Office365 internal message: '{\"integration\":\"office365\",\"office365\":{\"actor\":\"wazuh\",\"tenant_id\":\"tenant_id\",\"subscription_name\":\"subscription_name\",\"response\":\"Unknown error\"}}'"); - - int result = -1; - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"office365\",\"office365\":{\"actor\":\"wazuh\",\"tenant_id\":\"tenant_id\",\"subscription_name\":\"subscription_name\",\"response\":\"Unknown error\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "office365"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mterror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'Success'"); - - wm_office365_scan_failure_action(&fails, tenant_id, subscription_name, error_msg, queue_fd); - - os_free(fails); -} - -void test_wm_office365_scan_failure_action_not_null_error_msg(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - wm_office365_fail *fails = NULL; - os_calloc(1, sizeof(wm_office365_fail), fails); - fails->subscription_name = "subscription_name"; - fails->tenant_id = "tenant_id"; - fails->fails = 2; - wm_max_eps = 1; - - char* subscription_name = "subscription_name"; - char* tenant_id = "tenant_id"; - int queue_fd = 1; - char *error_msg = "{\"response\":\"test\"}"; - - expect_string(__wrap__mtwarn, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtwarn, formatted_msg, "Sending Office365 internal message: '{\"integration\":\"office365\",\"office365\":{\"actor\":\"wazuh\",\"tenant_id\":\"tenant_id\",\"subscription_name\":\"subscription_name\",\"response\":\"{\\\"response\\\":\\\"test\\\"}\"}}'"); - - int result = -1; - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"office365\",\"office365\":{\"actor\":\"wazuh\",\"tenant_id\":\"tenant_id\",\"subscription_name\":\"subscription_name\",\"response\":\"{\\\"response\\\":\\\"test\\\"}\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "office365"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mterror, formatted_msg, "(1210): Queue 'queue/sockets/queue' not accessible: 'Success'"); - - wm_office365_scan_failure_action(&fails, tenant_id, subscription_name, error_msg, queue_fd); - - os_free(fails); -} - -void test_wm_office365_get_logs_from_blob_response_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - cJSON *logs_array = NULL; - - size_t max_size = OS_SIZE_8192; - char *token = "test_token"; - char *url = "https://test_url.com"; - bool buffer_size_reached = false; - char *error_msg = NULL; - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting logs from blob."); - - logs_array = wm_office365_get_logs_from_blob(url, token, max_size, &buffer_size_reached, &error_msg); - - assert_null(logs_array); - assert_null(error_msg); - -} - -void test_wm_office365_get_logs_from_blob_response_max_size_reached(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - cJSON *logs_array = NULL; - - size_t max_size = OS_SIZE_8192; - char *token = "test_token"; - char *url = "https://test_url.com"; - bool buffer_size_reached = false; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - data->response->max_size_reached = true; - os_strdup("[{\"test\":{\"code\":\"test\"", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Libcurl error, reached maximum response size."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - logs_array = wm_office365_get_logs_from_blob(url, token, max_size, &buffer_size_reached, &error_msg); - - assert_null(logs_array); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - -} - -void test_wm_office365_get_logs_from_blob_response_parsing_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - cJSON *logs_array = NULL; - - size_t max_size = OS_SIZE_8192; - char *token = "test_token"; - char *url = "https://test_url.com"; - bool buffer_size_reached = false; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - data->response->max_size_reached = false; - os_strdup("[{\"test\":{\"code\":\"test\"", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while parsing logs from blob JSON response."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - logs_array = wm_office365_get_logs_from_blob(url, token, max_size, &buffer_size_reached, &error_msg); - - assert_null(logs_array); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - -} - -void test_wm_office365_get_logs_from_blob_response_code_400(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - cJSON *logs_array = NULL; - - size_t max_size = OS_SIZE_8192; - char *token = "test_token"; - char *url = "https://test_url.com"; - bool buffer_size_reached = false; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - data->response->max_size_reached = false; - os_strdup("[{\"test\":{\"code\":\"test\"}}]", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while getting logs from blob: '[{\"test\":{\"code\":\"test\"}}]'"); - - expect_value(__wrap_wurl_free_response, response, data->response); - - logs_array = wm_office365_get_logs_from_blob(url, token, max_size, &buffer_size_reached, &error_msg); - - assert_null(logs_array); - assert_string_equal(error_msg, data->response->body); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - os_free(error_msg); - -} - -void test_wm_office365_get_logs_from_blob_response_no_array(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - cJSON *logs_array = NULL; - - size_t max_size = OS_SIZE_8192; - char *token = "test_token"; - char *url = "https://test_url.com"; - bool buffer_size_reached = false; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - data->response->max_size_reached = false; - os_strdup("{\"test\":{\"code\":\"test\"}}", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while getting logs from blob: '{\"test\":{\"code\":\"test\"}}'"); - - expect_value(__wrap_wurl_free_response, response, data->response); - - logs_array = wm_office365_get_logs_from_blob(url, token, max_size, &buffer_size_reached, &error_msg); - - assert_null(logs_array); - assert_string_equal(error_msg, data->response->body); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - os_free(error_msg); - -} - -void test_wm_office365_get_logs_from_blob_ok(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int value = 0; - cJSON *logs_array = NULL; - - size_t max_size = OS_SIZE_8192; - char *token = "test_token"; - char *url = "https://test_url.com"; - bool buffer_size_reached = false; - char *error_msg = NULL; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - data->response->max_size_reached = false; - os_strdup("[{\"test\":{\"code\":\"test\"}}]", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", token); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - - logs_array = wm_office365_get_logs_from_blob(url, token, max_size, &buffer_size_reached, &error_msg); - - assert_non_null(logs_array); - assert_null(error_msg); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - cJSON_Delete(logs_array); - -} - -void test_wm_office365_execute_scan_all(void **state) { - test_struct_t *data = (test_struct_t *)*state; - wm_office365_state tenant_state_struc; - tenant_state_struc.last_log_time = 160; - current_time = 161; - wm_max_eps = 1; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - data->office365_config->auth->next = NULL; - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - data->office365_config->subscription->next = NULL; - - os_calloc(1, sizeof(wm_office365_fail), data->office365_config->fails); - os_strdup("subscription_name", data->office365_config->fails->subscription_name); - os_strdup("tenant_id", data->office365_config->fails->tenant_id); - data->office365_config->interval = 10; - - int initial_scan = 1; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"wazuh\"}", data->response->body); - os_strdup("test", data->response->header); - - // wm_office365_get_content_blobs - curl_response *get_content_blobs_response; - os_calloc(1, sizeof(curl_response), get_content_blobs_response); - get_content_blobs_response->status_code = 200; - get_content_blobs_response->max_size_reached = false; - os_strdup("[{\"contentUri\":\"https://contentUri1.com\"}]", get_content_blobs_response->body); - os_strdup("test", get_content_blobs_response->header); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - const char expected_token_url[] = "Office 365 API access token URL: 'https://" WM_OFFICE365_DEFAULT_API_LOGIN_FQDN "/test_tenant_id/oauth2/v2.0/token'"; - expect_string(__wrap__mtdebug1, formatted_msg, expected_token_url); - - expect_value(__wrap_wurl_free_response, response, data->response); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&tenant_state_struc); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer wazuh"); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - const char expected_subscription_url[] = "Office 365 API subscription URL: 'https://" WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN "/api/v1.0/test_client_id/activity/feed/subscriptions/start?contentType=test_subscription_name'"; - expect_string(__wrap__mtdebug1, formatted_msg, expected_subscription_url); - - #ifndef WIN32 - will_return(__wrap_gmtime_r, 1); - will_return(__wrap_gmtime_r, 1); - #endif - - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - - expect_value(__wrap_wurl_free_response, response, data->response); - - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer wazuh"); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, get_content_blobs_response); - - expect_any(__wrap__mdebug1, formatted_msg); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - const char expected_blob_url[] = "Office 365 API content blobs URL: 'https://" WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN "/api/v1.0/test_client_id/activity/feed/subscriptions/content?contentType=test_subscription_name&startTime=2021-05-07 12:24:56&endTime=2021-05-07 12:24:56'"; - expect_string(__wrap__mtdebug1, formatted_msg, expected_blob_url); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Office 365 API content URI: 'https://contentUri1.com'"); - - expect_value(__wrap_wurl_free_response, response, get_content_blobs_response); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer wazuh"); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, get_content_blobs_response); - - expect_value(__wrap_wurl_free_response, response, get_content_blobs_response); - - expect_string(__wrap__mtdebug2, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug2, formatted_msg, "Sending Office365 log: '{\"integration\":\"office365\",\"office365\":{\"contentUri\":\"https://contentUri1.com\",\"Subscription\":\"test_subscription_name\"}}'"); - - int result = 1; - int queue_fd = 0; - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, queue_fd); - expect_string(__wrap_wm_sendmsg, message, "{\"integration\":\"office365\",\"office365\":{\"contentUri\":\"https://contentUri1.com\",\"Subscription\":\"test_subscription_name\"}}"); - expect_string(__wrap_wm_sendmsg, locmsg, "office365"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, result); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2021-05-07 12:24:56' for tenant 'test_tenant_id' and subscription 'test_subscription_name', waiting '10' seconds to run next scan."); - - wm_office365_execute_scan(data->office365_config, initial_scan); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - - os_free(get_content_blobs_response->body); - os_free(get_content_blobs_response->header); - os_free(get_content_blobs_response); -} - -void test_wm_office365_execute_scan_initial_scan_only_future_events(void **state) { - test_struct_t *data = (test_struct_t *)*state; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - data->office365_config->only_future_events = 1; - data->office365_config->interval = 10; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 1); - - will_return(__wrap_isDebug, 1); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Bookmark updated to '2021-05-07 12:24:56' for tenant 'test_tenant_id' and subscription 'test_subscription_name', waiting '10' seconds to run first scan."); - - wm_office365_execute_scan(data->office365_config, 1); -} - -void test_wm_office365_execute_scan_access_token_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - data->office365_config->only_future_events = 1; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 400; - os_strdup("{\"error\":\"bad_request\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Error while getting access token: '{\"error\":\"bad_request\"}'"); - - expect_value(__wrap_wurl_free_response, response, data->response); - - wm_office365_execute_scan(data->office365_config, 0); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_execute_scan_manage_subscription_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - wm_office365_state tenant_state_struc; - - tenant_state_struc.last_log_time = 123456789; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - data->office365_config->only_future_events = 0; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"wazuh\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&tenant_state_struc); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_any(__wrap_wurl_http_request, method); - - char expHeader[OS_SIZE_8192]; - snprintf(expHeader, OS_SIZE_8192 -1, "Authorization: Bearer %s", "wazuh"); - - expect_string(__wrap_wurl_http_request, header, expHeader); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while managing subscription."); - - wm_office365_execute_scan(data->office365_config, 0); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_execute_scan_saving_running_state_error(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int initial_scan = 0; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"access_token_value\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - /* wm_office365_get_access_token */ - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mterror, formatted_msg, "Couldn't save running state."); - - expect_value(__wrap_wurl_free_response, response, data->response); - - wm_office365_execute_scan(data->office365_config, initial_scan); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_execute_scan_content_blobs_fail(void **state) { - test_struct_t *data = (test_struct_t *)*state; - int initial_scan = 1; - - wm_office365_state tenant_state_struc; - tenant_state_struc.last_log_time = 123456789; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - data->office365_config->only_future_events = 0; - - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"access_token_value\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - /* wm_office365_get_access_token */ - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - /* wm_office365_get_access_token */ - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&tenant_state_struc); - - /* wm_office365_manage_subscription */ - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - expect_string(__wrap_wurl_http_request, header, "Authorization: Bearer access_token_value"); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - /* wm_office365_manage_subscription */ - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-07 12:24:56"); - will_return(__wrap_strftime, 20); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-05-08 12:24:55"); - will_return(__wrap_strftime, 20); - - /* wm_office365_get_content_blobs */ - expect_any(__wrap_wurl_http_request, method); - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - - expect_string(__wrap_wurl_http_request, header, "Authorization: Bearer access_token_value"); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting content blobs."); - /* wm_office365_get_content_blobs */ - - expect_value(__wrap_wurl_free_response, response, data->response); - - wm_office365_execute_scan(data->office365_config, initial_scan); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); -} - -void test_wm_office365_execute_scan_get_logs_from_blob_response_null(void **state) { - test_struct_t *data = (test_struct_t *)*state; - size_t max_size = OS_SIZE_8192; - wm_office365_state tenant_state_struc; - - tenant_state_struc.last_log_time = 123456789; - - os_calloc(1, sizeof(wm_office365_auth), data->office365_config->auth); - os_strdup("test_tenant_id", data->office365_config->auth->tenant_id); - os_strdup("test_client_id", data->office365_config->auth->client_id); - os_strdup("test_client_secret", data->office365_config->auth->client_secret); - os_strdup(WM_OFFICE365_DEFAULT_API_LOGIN_FQDN, data->office365_config->auth->login_fqdn); - os_strdup(WM_OFFICE365_DEFAULT_API_MANAGEMENT_FQDN, data->office365_config->auth->management_fqdn); - os_calloc(1, sizeof(wm_office365_subscription), data->office365_config->subscription); - os_strdup("test_subscription_name", data->office365_config->subscription->subscription_name); - data->office365_config->only_future_events = 0; - - os_calloc(1, sizeof(curl_response), data->response); - data->response->status_code = 200; - os_strdup("{\"access_token\":\"wazuh\"}", data->response->body); - os_strdup("test", data->response->header); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Scanning tenant: 'test_tenant_id'"); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, data->response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, data->response); - - expect_string(__wrap_wm_state_io, tag, "office365-test_tenant_id-test_subscription_name"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_any(__wrap_wm_state_io, state); - expect_any(__wrap_wm_state_io, size); - will_return(__wrap_wm_state_io, 0); - will_return(__wrap_wm_state_io, (void *)&tenant_state_struc); - - curl_response *manage_subscription_response; - os_calloc(1, sizeof(curl_response), manage_subscription_response); - manage_subscription_response->status_code = 200; - manage_subscription_response->max_size_reached = false; - os_strdup("{\"test\":\"wazuh\"}", manage_subscription_response->body); - os_strdup("test", manage_subscription_response->header); - - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, manage_subscription_response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, manage_subscription_response); - - // while ((end_time - start_time) > 0) -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-06-11T12:24:56Z"); - will_return(__wrap_strftime, 20); - -#ifndef WIN32 - will_return(__wrap_gmtime_r, 1); -#endif - - will_return(__wrap_strftime,"2021-06-11T12:34:56Z"); - will_return(__wrap_strftime, 20); - - // wm_office365_get_content_blobs - curl_response *get_content_blobs_response; - os_calloc(1, sizeof(curl_response), get_content_blobs_response); - get_content_blobs_response->status_code = 200; - get_content_blobs_response->max_size_reached = false; - os_strdup("[{\"contentUri\":\"https://contentUri1.com\"}]", get_content_blobs_response->body); - os_strdup("test", get_content_blobs_response->header); - - expect_any(__wrap__mdebug1, formatted_msg); - - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, get_content_blobs_response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_any(__wrap__mtdebug1, formatted_msg); - - expect_value(__wrap_wurl_free_response, response, get_content_blobs_response); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Office 365 API content URI: 'https://contentUri1.com'"); - - expect_string(__wrap_wurl_http_request, header, "Content-Type: application/json"); - expect_string(__wrap_wurl_http_request, header, "Authorization: Bearer wazuh"); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, method); - expect_any(__wrap_wurl_http_request, header); - expect_any(__wrap_wurl_http_request, url); - expect_any(__wrap_wurl_http_request, payload); - expect_any(__wrap_wurl_http_request, max_size); - expect_value(__wrap_wurl_http_request, timeout, WM_OFFICE365_DEFAULT_CURL_REQUEST_TIMEOUT); - will_return(__wrap_wurl_http_request, NULL); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:office365"); - expect_string(__wrap__mtdebug1, formatted_msg, "Unknown error while getting logs from blob."); - - wm_office365_execute_scan(data->office365_config, 0); - - os_free(data->response->body); - os_free(data->response->header); - os_free(data->response); - - os_free(manage_subscription_response->body); - os_free(manage_subscription_response->header); - os_free(manage_subscription_response); - - os_free(get_content_blobs_response->body); - os_free(get_content_blobs_response->header); - os_free(get_content_blobs_response); -} - -int main(void) { - const struct CMUnitTest tests_configuration[] = { - cmocka_unit_test_setup_teardown(test_read_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_configuration_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_default_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_s, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_s_fail, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_m, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_m_fail, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_h, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_h_fail, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_d, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_interval_d_fail, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_curl_max_size, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_curl_max_size_invalid_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_curl_max_size_invalid_2, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_curl_max_size_invalid_3, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_secret_path_and_secret, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_fake_tag_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_2, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_3, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_content_4, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_invalid_interval, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_auth, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_auth_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_tenant_id, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_tenant_id_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_client_id, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_client_id_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_client_secret, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_client_secret_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_client_secret_path, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_client_secret_path_1, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_type, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_error_api_type_1, setup_test_read, teardown_test_read), - }; - const struct CMUnitTest tests_functionality[] = { - cmocka_unit_test_setup_teardown(test_wm_office365_main_disabled, setup_conf, teardown_conf), - #ifndef WIN32 - cmocka_unit_test_setup_teardown(test_wm_office365_main_fail_StartMQ, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_main_enable, setup_conf, teardown_conf), - #endif - cmocka_unit_test_setup_teardown(test_wm_office365_dump_no_options, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_dump_yes_options_empty_arrays, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_dump_yes_options, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_access_token_with_auth_secret, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_access_token_with_auth_secret_path, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_access_token_with_auth_secret_response_400, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_access_token_with_auth_secret_response_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_access_token_with_auth_secret_response_max_size_reached, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_access_token_with_auth_secret_error_json_response, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_access_token_with_auth_secret_response_200, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_manage_subscription_stop_error_json_response, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_manage_subscription_stop_error_max_size_reached, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_manage_subscription_start_code_200, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_manage_subscription_start_response_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_manage_subscription_stop_code_400_error_AF20024, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_manage_subscription_stop_code_400_error_different_AF20024, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_fail_by_tenant_and_subscription_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_fail_by_tenant_and_subscription_not_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_content_blobs_response_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_content_blobs_response_max_size_reached, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_content_blobs_error_json_response, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_content_blobs_bad_response, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_content_blobs_400_code_AF20055, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_scan_failure_action_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_scan_failure_action_no_fail, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_scan_failure_action_null_mult_next, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_scan_failure_action_not_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_scan_failure_action_not_null_error_msg, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_logs_from_blob_response_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_logs_from_blob_response_max_size_reached, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_logs_from_blob_response_parsing_error, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_logs_from_blob_response_code_400, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_logs_from_blob_response_no_array, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_get_logs_from_blob_ok, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_execute_scan_initial_scan_only_future_events, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_execute_scan_access_token_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_execute_scan_manage_subscription_error, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_execute_scan_saving_running_state_error, setup_conf, teardown_conf), - #ifndef WIN32 - cmocka_unit_test_setup_teardown(test_wm_office365_execute_scan_content_blobs_fail, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_execute_scan_get_logs_from_blob_response_null, setup_conf, teardown_conf), - cmocka_unit_test_setup_teardown(test_wm_office365_execute_scan_all, setup_conf, teardown_conf), - #endif - }; - - int result; - result = cmocka_run_group_tests(tests_configuration, NULL, NULL); - result += cmocka_run_group_tests(tests_functionality, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/oscap/CMakeLists.txt b/src/unit_tests/wazuh_modules/oscap/CMakeLists.txt deleted file mode 100644 index 6bd33af3b80..00000000000 --- a/src/unit_tests/wazuh_modules/oscap/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_oscap") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror \ - -Wl,--wrap=_mtwarn,--wrap=_mtinfo,--wrap=_mterror,--wrap=wm_exec,--wrap=StartMQ,--wrap=FOREVER \ - -Wl,--wrap=wm_sendmsg,--wrap=SendMSG,--wrap=atexit,--wrap=wm_state_io") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB oscap ../../../wazuh_modules/*.o) -list(REMOVE_ITEM oscap ../../../wazuh_modules/main.o) - -add_library(OSCAP_O STATIC ${oscap}) - -set_source_files_properties( - ${oscap} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - OSCAP_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(OSCAP_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - OSCAP_O - -ldl - -lcmocka - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/oscap/test_wm_oscap.c b/src/unit_tests/wazuh_modules/oscap/test_wm_oscap.c deleted file mode 100644 index fa5b8c68df2..00000000000 --- a/src/unit_tests/wazuh_modules/oscap/test_wm_oscap.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for oscap Module - * */ - -#include -#include -#include -#include -#include -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../../../wazuh_modules/wm_oscap.h" -#include "../scheduling/wmodules_scheduling_helpers.h" -#include "../../wrappers/common.h" -#include "../../wrappers/libc/stdlib_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wmodules_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" - -#define TEST_MAX_DATES 5 - -static wmodule *oscap_module; -static OS_XML *lxml; -extern int test_mode; - -/******* Helpers **********/ - -static void wmodule_cleanup(wmodule *module){ - wm_oscap* module_data = (wm_oscap *)module->data; - if (module_data->evals) { - wm_oscap_eval* eval = module_data->evals; - while(eval->next){ - wm_oscap_eval* aux= eval; - eval = eval->next; - free(aux->path); - free(aux); - } - free(module_data->evals->path); - free(module_data->evals); - } - free(module_data); - free(module->tag); - free(module); -} - -/*** SETUPS/TEARDOWNS ******/ -static int setup_module() { - oscap_module = calloc(1, sizeof(wmodule)); - const char *string = - "1800\n" - "12h\n" - "no\n" - // Only one contect type to avoid repeating wm_exec command - "\n"; - lxml = malloc(sizeof(OS_XML)); - XML_NODE nodes = string_to_xml_node(string, lxml); - int ret = wm_oscap_read(lxml, nodes, oscap_module); - OS_ClearNode(nodes); - test_mode = 1; - return ret; -} - -static int teardown_module(){ - test_mode = 0; - wmodule_cleanup(oscap_module); - OS_ClearXML(lxml); - return 0; -} - -static int setup_test_executions(void **state) { - wm_max_eps = 1; - return 0; -} - -static int teardown_test_executions(void **state){ - wm_oscap* module_data = (wm_oscap *) *state; - sched_scan_free(&(module_data->scan_config)); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wm_oscap *module_data = (wm_oscap*)test->module->data; - sched_scan_free(&(module_data->scan_config)); - wmodule_cleanup(test->module); - os_free(test); - return 0; -} - -/****************************************************************/ - -/** Tests **/ -void test_interval_execution(void **state) { - wm_oscap* module_data = (wm_oscap *)oscap_module->data; - int i = 0; - - *state = module_data; - module_data->scan_config.next_scheduled_scan_time = 0; - module_data->scan_config.scan_day = 0; - module_data->scan_config.scan_wday = -1; - module_data->scan_config.interval = 60; // 1min - module_data->scan_config.month_interval = false; - - expect_any_count(__wrap_SendMSG, message, TEST_MAX_DATES + 1); - expect_string_count(__wrap_SendMSG, locmsg, xml_rootcheck, TEST_MAX_DATES + 1); - expect_value_count(__wrap_SendMSG, loc, ROOTCHECK_MQ, TEST_MAX_DATES + 1); - will_return_count(__wrap_SendMSG, 1, TEST_MAX_DATES + 1); - - for (i = 0; i < TEST_MAX_DATES + 1; i++) { - expect_any(__wrap_wm_exec, command); - expect_any(__wrap_wm_exec, secs); - expect_any(__wrap_wm_exec, add_path); - - will_return(__wrap_wm_exec, "TEST_STRING"); - will_return(__wrap_wm_exec, 0); - will_return(__wrap_wm_exec, 0); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, 0); - expect_string(__wrap_wm_sendmsg, message, "TEST_STRING"); - expect_string(__wrap_wm_sendmsg, locmsg, "wodle_open-scap"); - expect_value(__wrap_wm_sendmsg, loc, LOCALFILE_MQ); - will_return(__wrap_wm_sendmsg, 0); - - expect_value(__wrap_wm_sendmsg, usec, 1000000); - expect_value(__wrap_wm_sendmsg, queue, 0); - expect_string(__wrap_wm_sendmsg, message, "Ending OpenSCAP scan. File: ssg-centos-6-ds.xml. "); - expect_string(__wrap_wm_sendmsg, locmsg, "rootcheck"); - expect_value(__wrap_wm_sendmsg, loc, ROOTCHECK_MQ); - will_return(__wrap_wm_sendmsg, 0); - } - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 0); - - will_return_count(__wrap_FOREVER, 1, TEST_MAX_DATES); - will_return(__wrap_FOREVER, 0); - - expect_string(__wrap_wm_state_io, tag, "open-scap"); - expect_value(__wrap_wm_state_io, op, WM_IO_READ); - expect_value(__wrap_wm_state_io, state, &module_data->state); - expect_value(__wrap_wm_state_io, size, sizeof(module_data->state)); - will_return(__wrap_wm_state_io, 1); - - for (i = 0; i < TEST_MAX_DATES + 1; i++) { - expect_string(__wrap_wm_state_io, tag, "open-scap"); - expect_value(__wrap_wm_state_io, op, WM_IO_WRITE); - expect_value(__wrap_wm_state_io, state, &module_data->state); - expect_value(__wrap_wm_state_io, size, sizeof(module_data->state)); - will_return(__wrap_wm_state_io, -1); - } - - expect_string_count(__wrap__mterror, tag, "wazuh-modulesd:oscap", TEST_MAX_DATES + 1); - expect_string_count(__wrap__mterror, formatted_msg, "Couldn't save running state.", TEST_MAX_DATES + 1); - expect_any_always(__wrap__mtinfo, tag); - expect_any_always(__wrap__mtinfo, formatted_msg); - - oscap_module->context->start(module_data); -} - -void test_fake_tag(void **state) { - const char *string = - "1800\n" - "\n" - "no\n" - // Only one contect type to avoid repeating wm_exec command - "null\n"; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - expect_string(__wrap__merror, formatted_msg, "No such tag 'fake_tag' at module 'open-scap'."); - assert_int_equal(wm_oscap_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_scheduling_monthday_configuration(void **state) { - const char *string = - "1800\n" - "8\n" - "\n" - "no\n" - // Only one contect type to avoid repeating wm_exec command - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_oscap_read(&(test->xml), test->nodes, test->module),0); - wm_oscap *module_data = (wm_oscap*) test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 8); - assert_int_equal(module_data->scan_config.interval, 1); - assert_int_equal(module_data->scan_config.month_interval, true); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "01:15"); -} - -void test_read_scheduling_weekday_configuration(void **state) { - const char *string = - "1800\n" - "Saturday\n" - "\n" - "no\n" - // Only one contect type to avoid repeating wm_exec command - ; - test_structure *test = *state; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_oscap_read(&(test->xml), test->nodes, test->module),0); - wm_oscap *module_data = (wm_oscap*) test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 604800); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, 6); - assert_string_equal(module_data->scan_config.scan_time, "01:15"); -} - -void test_read_scheduling_daytime_configuration(void **state) { - const char *string = - "1800\n" - "\n" - "no\n" - // Only one contect type to avoid repeating wm_exec command - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_oscap_read(&(test->xml), test->nodes, test->module),0); - wm_oscap *module_data = (wm_oscap*) test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "21:43"); -} - -void test_read_scheduling_interval_configuration(void **state) { - const char *string = - "1800\n" - "90m\n" - "no\n" - // Only one contect type to avoid repeating wm_exec command - ; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_oscap_read(&(test->xml), test->nodes, test->module),0); - wm_oscap *module_data = (wm_oscap*) test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 90*60); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); -} - -int main(void) { - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_interval_execution, setup_test_executions, teardown_test_executions) - }; - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_monthday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_weekday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_daytime_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_interval_configuration, setup_test_read, teardown_test_read) - }; - int result; - result = cmocka_run_group_tests(tests_with_startup, setup_module, teardown_module); - result += cmocka_run_group_tests(tests_without_startup, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/osquery/CMakeLists.txt b/src/unit_tests/wazuh_modules/osquery/CMakeLists.txt deleted file mode 100644 index 4501b024186..00000000000 --- a/src/unit_tests/wazuh_modules/osquery/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_osquery_already_running") -list(APPEND tests_flags "-Wl,--wrap,access -Wl,--wrap,wurl_http_request \ - -Wl,--wrap,wurl_free_response -Wl,--wrap,wm_sendmsg -Wl,--wrap,strftime \ - -Wl,--wrap,wm_state_io -Wl,--wrap,time -Wl,--wrap,StartMQ \ - -Wl,--wrap=syscom_dispatch -Wl,--wrap=Start_win32_Syscheck \ -Wl,--wrap=is_fim_shutdown \ - -Wl,--wrap=_imp__dbsync_initialize -Wl,--wrap=_imp__rsync_initialize -Wl,--wrap=fim_db_teardown \ - -Wl,--wrap,fim_sync_push_msg -Wl,--wrap,fim_run_integrity -Wl,--wrap,fim_db_remove_path \ - -Wl,--wrap,fim_db_get_path -Wl,--wrap,fim_db_transaction_start -Wl,--wrap,fim_db_transaction_deleted_rows \ - -Wl,--wrap,fim_db_transaction_sync_row -Wl,--wrap,fim_db_file_update -Wl,--wrap,fim_db_file_pattern_search \ - -Wl,--wrap,fim_db_init,--wrap,getpid") - -# Generate wazuh modules library -file(GLOB osquery ../../../wazuh_modules/*.o) -list(REMOVE_ITEM osquery ../../../wazuh_modules/main.o) - -add_library(OSQUERY_O STATIC ${osquery}) - -set_source_files_properties( - ${osquery} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - OSQUERY_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(OSQUERY_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - if(${TARGET} STREQUAL "server") - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - OSQUERY_O - -lcmocka - -ldl - -fprofile-arcs - -ftest-coverage - ) - else() - target_link_libraries( - ${test_name} - ${TEST_DEPS} - ) - endif() - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/osquery/test_wm_osquery_already_running.c b/src/unit_tests/wazuh_modules/osquery/test_wm_osquery_already_running.c deleted file mode 100644 index a5b8b1737cf..00000000000 --- a/src/unit_tests/wazuh_modules/osquery/test_wm_osquery_already_running.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include -#include - -char * wm_osquery_already_running(char * text); - -void test_wm_osquery_already_running_null(void **state) -{ - char *input = NULL; - char *output = wm_osquery_already_running(input); - - assert_null(output); -} - -void test_wm_osquery_already_running_pattern_1(void **state) -{ - char input[] = "osqueryd (1000) is already running"; - char *output = wm_osquery_already_running(input); - - assert_non_null(output); - assert_string_equal(output, "1000"); - - free(output); -} - -void test_wm_osquery_already_running_pattern_2(void **state) -{ - char input[] = "Pidfile::Error::Busy"; - char *output = wm_osquery_already_running(input); - - assert_non_null(output); - assert_string_equal(output, "unknown"); - - free(output); -} - -void test_wm_osquery_already_running_no_match(void **state) -{ - char input[] = "No match"; - char *output = wm_osquery_already_running(input); - assert_null(output); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_osquery_already_running - cmocka_unit_test(test_wm_osquery_already_running_null), - cmocka_unit_test(test_wm_osquery_already_running_pattern_1), - cmocka_unit_test(test_wm_osquery_already_running_pattern_2), - cmocka_unit_test(test_wm_osquery_already_running_no_match), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/sca/CMakeLists.txt b/src/unit_tests/wazuh_modules/sca/CMakeLists.txt deleted file mode 100644 index 399dc438fab..00000000000 --- a/src/unit_tests/wazuh_modules/sca/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wm_sca") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror \ - -Wl,--wrap=_mtwarn,--wrap=_mtinfo,--wrap=_mterror,--wrap=FOREVER,--wrap=IsFile,--wrap=getDefine_Int \ - -Wl,--wrap=StartMQ,--wrap=CreateThread,--wrap=wm_exec,--wrap=wm_sendmsg,--wrap=opendir,--wrap=realpath,--wrap=atexit \ - -Wl,--wrap=w_expression_compile -Wl,--wrap=w_expression_match -Wl,--wrap,wfopen") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.h") -list(APPEND shared_libs "../scheduling/wmodules_scheduling_helpers.c") - -# Generate wazuh modules library -file(GLOB sca ../../../wazuh_modules/*.o) -list(REMOVE_ITEM sca ../../../wazuh_modules/main.o) - -add_library(SCA_O STATIC ${sca}) - -set_source_files_properties( - ${sca} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - SCA_O - PROPERTIES - LINKER_LANGUAGE C - ) - -target_link_libraries(SCA_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - SCA_O - -ldl - -lcmocka - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/sca/test_wm_sca.c b/src/unit_tests/wazuh_modules/sca/test_wm_sca.c deleted file mode 100644 index ecb82dc98e9..00000000000 --- a/src/unit_tests/wazuh_modules/sca/test_wm_sca.c +++ /dev/null @@ -1,828 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * for SCA Module - * */ - -#include -#include -#include -#include -#include -#include - -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "../scheduling/wmodules_scheduling_helpers.h" - -#include "../../wrappers/common.h" -#include "../../wrappers/posix/dirent_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/file_op_wrappers.h" -#include "../../wrappers/wazuh/shared/mq_op_wrappers.h" -#include "../../wrappers/wazuh/shared/pthreads_op_wrappers.h" -#include "../../wrappers/wazuh/shared/validate_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wmodules_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_exec_wrappers.h" - -#define TEST_MAX_DATES 3 - -static wmodule *sca_module; -static OS_XML *lxml; -extern int test_mode; - -extern void wm_sca_send_policies_scanned(wm_sca_t * data); -extern int wm_sca_test_positive_minterm(const char * const pattern, const char * const str, char ** reason, w_expression_t * regex_engine); -extern int wm_sca_regex_numeric_comparison(const char * const pattern, const char * const str, char ** reason, w_expression_t * regex_engine); -extern int wm_sca_apply_numeric_partial_comparison(const char * const partial_comparison, const long int number, char ** reason, w_expression_t * regex_engine); - -extern w_queue_t * request_queue; -extern char **last_sha256; -extern OSHash **cis_db; -extern struct cis_db_hash_info_t *cis_db_for_hash; -extern unsigned int policies_count; - -void wm_sca_send_policies_scanned(wm_sca_t * data) -{ - // Will wrap this function to check running times in order to check scheduling - return; -} - -/******* Helpers **********/ - -static void wmodule_cleanup(wmodule *module){ - wm_sca_t* module_data = (wm_sca_t *)module->data; - int i; - for(i = 0; i < policies_count; i++) { - os_free(module_data->policies[i]->policy_path); - os_free(module_data->policies[i]); - } - os_free(module_data->alert_msg); - os_free(module_data->policies); - os_free(module_data); - os_free(module->tag); - os_free(module); -} - -/*** SETUPS/TEARDOWNS ******/ -static int setup_module() { - sca_module = calloc(1, sizeof(wmodule)); - const char *string = - "yes\n" - "12h\n" - "no\n" - "\n" - " /var/ossec/etc/shared/your_policy_file.yml\n" - "\n"; - lxml = malloc(sizeof(OS_XML)); - - will_return(__wrap_opendir, 0); - expect_string(__wrap__mtinfo, tag, "sca"); - expect_any(__wrap__mtinfo, formatted_msg); - expect_string(__wrap_realpath, path, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_realpath, "/var/ossec/etc/shared/your_policy_file.yml"); - expect_string(__wrap_IsFile, file, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_IsFile, 0); - - XML_NODE nodes = string_to_xml_node(string, lxml); - int ret = wm_sca_read(lxml, nodes, sca_module); - OS_ClearNode(nodes); - test_mode = 0; - - return ret; -} - -static int teardown_module(){ - test_mode = 1; - wm_sca_t* module_data = (wm_sca_t *)sca_module->data; - wmodule_cleanup(sca_module); - OS_ClearXML(lxml); - return 0; -} - -static int setup_test_executions(void **state) { - wm_max_eps = 1; - return 0; -} - -static int teardown_test_executions(void **state) { - wm_sca_t* module_data = (wm_sca_t *)sca_module->data; - sched_scan_free(&(module_data->scan_config)); - int i; - for(i = 0; module_data->policies[i]; i++) { - os_free(last_sha256[i]); - OSHash_Free(cis_db[i]); - os_free(cis_db_for_hash[i].elem); - } - queue_free(request_queue); - return 0; -} - -static int setup_test_read(void **state) { - test_structure *test = calloc(1, sizeof(test_structure)); - test->module = calloc(1, sizeof(wmodule)); - *state = test; - return 0; -} - -static int teardown_test_read(void **state) { - test_structure *test = *state; - OS_ClearNode(test->nodes); - OS_ClearXML(&(test->xml)); - wmodule *module = test->module; - wm_sca_t* module_data = (wm_sca_t *)module->data; - sched_scan_free(&(module_data->scan_config)); - wmodule_cleanup(module); - os_free(test); - return 0; -} - -/****************************************************************/ - - -/** Tests **/ -void test_interval_execution(void **state) { - wm_sca_t* module_data = (wm_sca_t *)sca_module->data; - *state = module_data; - module_data->scan_config.next_scheduled_scan_time = 0; - module_data->scan_config.scan_day = 0; - module_data->scan_config.scan_wday = -1; - module_data->scan_config.interval = 60; // 1min - module_data->scan_config.month_interval = false; - - expect_string(__wrap_StartMQ, path, DEFAULTQUEUE); - expect_value(__wrap_StartMQ, type, WRITE); - will_return(__wrap_StartMQ, 0); - - will_return_count(__wrap_FOREVER, 1, TEST_MAX_DATES); - will_return(__wrap_FOREVER, 0); - expect_any_always(__wrap__mtinfo, tag); - expect_any_always(__wrap__mtinfo, formatted_msg); - expect_any_always(__wrap__mtwarn, tag); - expect_any_always(__wrap__mtwarn, formatted_msg); - - sca_module->context->start(module_data); -} - -void test_fake_tag(void **state) { - const char *string = - "yes\n" - "no\n" - "\n" - "\n" - " /var/ossec/etc/shared/your_policy_file.yml\n" - "\n" - "invalid"; - test_structure *test = *state; - test->nodes = string_to_xml_node(string, &(test->xml)); - - expect_string(__wrap__mterror, tag, "sca"); - expect_string(__wrap__mterror, formatted_msg, "No such tag 'fake' at module 'sca'."); - will_return(__wrap_opendir, 0); - expect_string(__wrap__mtinfo, tag, "sca"); - expect_any(__wrap__mtinfo, formatted_msg); - expect_string(__wrap_realpath, path, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_realpath, "/var/ossec/etc/shared/your_policy_file.yml"); - expect_string(__wrap_IsFile, file, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_IsFile, 0); - - assert_int_equal(wm_sca_read(&(test->xml), test->nodes, test->module),-1); -} - -void test_read_scheduling_monthday_configuration(void **state) { - const char *string = - "yes\n" - "no\n" - "7\n" - "\n" - "\n" - " /var/ossec/etc/shared/your_policy_file.yml\n" - "\n"; - test_structure *test = *state; - - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - will_return(__wrap_opendir, 0); - expect_string(__wrap__mtinfo, tag, "sca"); - expect_any(__wrap__mtinfo, formatted_msg); - expect_string(__wrap_realpath, path, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_realpath, "/var/ossec/etc/shared/your_policy_file.yml"); - expect_string(__wrap_IsFile, file, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_IsFile, 0); - - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_sca_read(&(test->xml), test->nodes, test->module),0); - wm_sca_t* module_data = (wm_sca_t *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 7); - assert_int_equal(module_data->scan_config.interval, 1); - assert_int_equal(module_data->scan_config.month_interval, true); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "03:30"); -} - -void test_read_scheduling_weekday_configuration(void **state) { - const char *string = - "yes\n" - "no\n" - "Monday\n" - "\n" - "\n" - " /var/ossec/etc/shared/your_policy_file.yml\n" - "\n"; - test_structure *test = *state; - - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - will_return(__wrap_opendir, 0); - expect_string(__wrap__mtinfo, tag, "sca"); - expect_any(__wrap__mtinfo, formatted_msg); - expect_string(__wrap_realpath, path, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_realpath, "/var/ossec/etc/shared/your_policy_file.yml"); - expect_string(__wrap_IsFile, file, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_IsFile, 0); - - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_sca_read(&(test->xml), test->nodes, test->module),0); - wm_sca_t* module_data = (wm_sca_t *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 604800); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, 1); - assert_string_equal(module_data->scan_config.scan_time, "04:30"); -} - -void test_read_scheduling_daytime_configuration(void **state) { - const char *string = - "yes\n" - "no\n" - "\n" - "\n" - " /var/ossec/etc/shared/your_policy_file.yml\n" - "\n"; - test_structure *test = *state; - - will_return(__wrap_opendir, 0); - expect_string(__wrap__mtinfo, tag, "sca"); - expect_any(__wrap__mtinfo, formatted_msg); - expect_string(__wrap_realpath, path, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_realpath, "/var/ossec/etc/shared/your_policy_file.yml"); - expect_string(__wrap_IsFile, file, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_IsFile, 0); - - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_sca_read(&(test->xml), test->nodes, test->module),0); - wm_sca_t* module_data = (wm_sca_t *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, WM_DEF_INTERVAL); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); - assert_string_equal(module_data->scan_config.scan_time, "05:30"); -} - -void test_read_scheduling_interval_configuration(void **state) { - const char *string = - "yes\n" - "no\n" - "2h\n" - "\n" - " /var/ossec/etc/shared/your_policy_file.yml\n" - "\n"; - test_structure *test = *state; - - will_return(__wrap_opendir, 0); - expect_string(__wrap__mtinfo, tag, "sca"); - expect_any(__wrap__mtinfo, formatted_msg); - expect_string(__wrap_realpath, path, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_realpath, "/var/ossec/etc/shared/your_policy_file.yml"); - expect_string(__wrap_IsFile, file, "/var/ossec/etc/shared/your_policy_file.yml"); - will_return(__wrap_IsFile, 0); - - test->nodes = string_to_xml_node(string, &(test->xml)); - assert_int_equal(wm_sca_read(&(test->xml), test->nodes, test->module),0); - wm_sca_t* module_data = (wm_sca_t *)test->module->data; - assert_int_equal(module_data->scan_config.scan_day, 0); - assert_int_equal(module_data->scan_config.interval, 7200); - assert_int_equal(module_data->scan_config.month_interval, false); - assert_int_equal(module_data->scan_config.scan_wday, -1); -} - -/* wm_sort_variables tests */ - -void test_wm_sort_variables_null(void **state) -{ - char **ret; - cJSON *variables_policy = NULL; - - ret = wm_sort_variables(variables_policy); - assert_null(ret); -} - -void test_wm_sort_variables_duplicated(void **state) -{ - char **ret; - char *expected_ret[] = {"$system_root", "$system_root"}; - const char *variables_json_mock = "{\n \ - \"variables\": {\n \ - \"$system_root\": \"/var\",\n \ - \"$system_root\": \"/etc\"\n \ - }\n \ - }"; - - cJSON *variables_list = cJSON_Parse(variables_json_mock); - cJSON *variables_policy = cJSON_GetObjectItem(variables_list, "variables"); - ret = wm_sort_variables(variables_policy); - - for (int i = 0; ret[i]; i++) { - assert_string_equal(ret[i], expected_ret[i]); - os_free(ret[i]); - } - os_free(ret); - cJSON_Delete(variables_list); -} - -void test_wm_sort_variables(void **state) -{ - char **ret; - char *expected_ret[] = {"$system_root_file", "$ssh_&_ssl_path", "$system_root", "$file"}; - const char *variables_json_mock = "{\n \ - \"variables\": {\n \ - \"$system_root\": \"/var\",\n \ - \"$file\": \"/\",\n \ - \"$ssh_&_ssl_path\": \"/new/directory\",\n \ - \"$system_root_file\": \"/var\"\n \ - }\n \ - }"; - - cJSON *variables_list = cJSON_Parse(variables_json_mock); - cJSON *variables_policy = cJSON_GetObjectItem(variables_list, "variables"); - ret = wm_sort_variables(variables_policy); - - for (int i = 0; ret[i]; i++) { - assert_string_equal(ret[i], expected_ret[i]); - os_free(ret[i]); - } - os_free(ret); - cJSON_Delete(variables_list); -} - -void test_wm_sca_test_positive_minterm_pcre2(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, true); - assert_int_equal(wm_sca_test_positive_minterm("r: test", "Status: test ok tested", NULL, regex), 1); - w_free_expression_t(®ex); -} - -void test_wm_sca_test_positive_minterm_pcre2_fail(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, false); - - assert_int_equal(wm_sca_test_positive_minterm("r: test", "Status: test ok tested", NULL, regex), 0); - w_free_expression_t(®ex); -} - -void test_wm_sca_test_positive_minterm_pcre2_fail_no_compile(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, false); - - assert_int_equal(wm_sca_test_positive_minterm("r: ???", "Status: test ok tested", NULL, regex), 0); - w_free_expression_t(®ex); -} - -void test_wm_sca_test_positive_minterm_pcre2_fail_no_match(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, false); - - assert_int_equal(wm_sca_test_positive_minterm("r: test", "Status: test ok tested", NULL, regex), 0); - w_free_expression_t(®ex); -} - -void test_wm_sca_test_positive_minterm_os_regex(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, true); - assert_int_equal(wm_sca_test_positive_minterm("r: test", "Status: test ok tested", NULL, regex), 1); - w_free_expression_t(®ex); -} - -void test_wm_sca_test_positive_minterm_os_regex_fail_no_match(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, false); - - assert_int_equal(wm_sca_test_positive_minterm("r: \\w\\w\\w\\d", "Status: test ok tested", NULL, regex), 0); - w_free_expression_t(®ex); -} - -void test_wm_sca_test_positive_minterm_exact_match(void **state) -{ - assert_int_equal(wm_sca_test_positive_minterm("test", "test", NULL, NULL), 1); -} - -void test_wm_sca_test_positive_minterm_no_exact_match(void **state) -{ - assert_int_equal(wm_sca_test_positive_minterm("test", "other thing", NULL, NULL), 0); -} - -void test_wm_sca_test_positive_minterm_numeric_expression(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "20"); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_test_positive_minterm("n:^\\s*\t*test\\s*\t*(\\d+) compare <= 30", "test 20", NULL, regex), 1); - w_free_expression_t(®ex); -} - -void test_wm_sca_test_positive_minterm_numeric_expression_fail(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, false); - - assert_int_equal(wm_sca_test_positive_minterm("n:^\\s*\t*test\\s*\t*(\\d+) compare <= 30", "test 20", NULL, regex), 0); - w_free_expression_t(®ex); -} - -void test_wm_sca_regex_numeric_comparison_PCRE2(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "20"); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_regex_numeric_comparison("n:^\\s*\t*test\\s*\t*(\\d+) compare < 30", "test 20", NULL, regex), 1); - w_free_expression_t(®ex); -} - -void test_wm_sca_regex_numeric_comparison_OS_REGEX(void **state) -{ - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "50"); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_regex_numeric_comparison("n:^\\s*\t*test\\s*\t*(\\d+) compare > 30", "test 50", NULL, regex), 1); - w_free_expression_t(®ex); -} - -void test_wm_sca_regex_numeric_comparison_without_compare_word_nor_reason(void **state) -{ - char *reason = NULL; - assert_int_equal(wm_sca_regex_numeric_comparison("n:^\\s*\t*test\\s*\t*(\\d+)", "test 50", &reason, NULL), 2); - os_free(reason); -} - -void test_wm_sca_regex_numeric_comparison_without_compare_word_with_reason(void **state) -{ - char * reason = NULL; - os_malloc(OS_MAXSTR, reason); - sprintf(reason, "This is a test"); - - assert_int_equal(wm_sca_regex_numeric_comparison("n:^\\s*\t*test\\s*\t*(\\d+)", "test 50", &reason, NULL), 2); - os_free(reason); -} - -void test_wm_sca_regex_numeric_comparison_without_compile_regex(void **state) -{ - char * reason = NULL; - - will_return(__wrap_w_expression_compile, false); - - assert_int_equal(wm_sca_regex_numeric_comparison("n:???", "test 50", &reason, NULL), 2); - os_free(reason); -} - -void test_wm_sca_regex_numeric_comparison_no_match(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, false); - - assert_int_equal(wm_sca_regex_numeric_comparison("n:^\\s*\t*test\\s*\t*(\\d+) compare > 30", "test 50", &reason, regex), 0); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_regex_numeric_comparison_no_detect_number_with_reason_null(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, true); - - assert_int_equal(wm_sca_regex_numeric_comparison("n:^\\s*\t*test\\s*\t*(\\d+) compare ", "test 50", &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_regex_numeric_comparison_no_detect_number_with_reason_not_null(void **state) -{ - char * reason = NULL; - os_malloc(OS_MAXSTR, reason); - sprintf(reason, "This is a test"); - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, true); - - assert_int_equal(wm_sca_regex_numeric_comparison("n:^\\s*\t*test\\s*\t*(\\d+) compare ", "test 50", &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_OS_REGEX(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("== 30", 30, &reason, regex), 1); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_PCRE2(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("< 30", 20, &reason, regex), 1); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_PCRE2_fail(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_PCRE2); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("< 30", 40, &reason, regex), 0); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_OS_REGEX_fail(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("== 30", 50, &reason, regex), 0); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_without_string_to_compare_with_reason_null(void **state) -{ - char * reason = NULL; - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "No comparison provided."); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison(NULL, 30, &reason, NULL), 2); - os_free(reason); -} - -void test_wm_sca_apply_numeric_partial_comparison_without_string_to_compare_with_reason_not_null(void **state) -{ - char * reason = NULL; - os_malloc(OS_MAXSTR, reason); - sprintf(reason, "This is a test"); - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "No comparison provided."); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison(NULL, 30, &reason, NULL), 2); - os_free(reason); -} - -void test_wm_sca_apply_numeric_partial_comparison_not_compile_with_reason_not_null(void **state) -{ - char * reason = NULL; - os_malloc(OS_MAXSTR, reason); - sprintf(reason, "This is a test"); - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, false); - - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "Cannot compile regex"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("???", 30, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_not_compile_with_reason_null(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, false); - - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "Cannot compile regex"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("???", 30, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_not_match_regex_with_reason_null(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "No integer was found within the comparison '< 30' "); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("< 30", 50, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_not_match_regex_with_reason_not_null(void **state) -{ - char * reason = NULL; - os_malloc(OS_MAXSTR, reason); - sprintf(reason, "This is a test"); - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, false); - - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "No integer was found within the comparison '< 30' "); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("< 30", 50, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_no_capture_number_with_reason_null(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, true); - - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "No number was captured."); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("< 30", 50, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_no_capture_number_with_reason_not_null(void **state) -{ - char * reason = NULL; - os_malloc(OS_MAXSTR, reason); - sprintf(reason, "This is a test"); - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, true); - - expect_string(__wrap__mtwarn, tag, "sca"); - expect_string(__wrap__mtwarn, formatted_msg, "No number was captured."); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("< 30", 50, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_no_operation_supported_with_reason_null(void **state) -{ - char * reason = NULL; - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("! 30", 50, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -void test_wm_sca_apply_numeric_partial_comparison_no_operation_supported_with_reason_not_null(void **state) -{ - char * reason = NULL; - os_malloc(OS_MAXSTR, reason); - sprintf(reason, "This is a test"); - w_expression_t * regex; - w_calloc_expression_t(®ex, EXP_TYPE_OSREGEX); - will_return(__wrap_w_expression_compile, true); - will_return(__wrap_w_expression_match, -1); - will_return(__wrap_w_expression_match, "30"); - - assert_int_equal(wm_sca_apply_numeric_partial_comparison("! 30", 50, &reason, regex), 2); - os_free(reason); - w_free_expression_t(®ex); -} - -/* main */ - -int main(void) { - const struct CMUnitTest tests_with_startup[] = { - cmocka_unit_test_setup_teardown(test_interval_execution, setup_test_executions, teardown_test_executions) - }; - const struct CMUnitTest tests_without_startup[] = { - cmocka_unit_test_setup_teardown(test_fake_tag, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_monthday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_weekday_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_daytime_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test_setup_teardown(test_read_scheduling_interval_configuration, setup_test_read, teardown_test_read), - cmocka_unit_test(test_wm_sort_variables_null), - cmocka_unit_test(test_wm_sort_variables_duplicated), - cmocka_unit_test(test_wm_sort_variables), - cmocka_unit_test(test_wm_sca_test_positive_minterm_pcre2), - cmocka_unit_test(test_wm_sca_test_positive_minterm_pcre2_fail), - cmocka_unit_test(test_wm_sca_test_positive_minterm_pcre2_fail_no_match), - cmocka_unit_test(test_wm_sca_test_positive_minterm_pcre2_fail_no_compile), - cmocka_unit_test(test_wm_sca_test_positive_minterm_os_regex), - cmocka_unit_test(test_wm_sca_test_positive_minterm_os_regex_fail_no_match), - cmocka_unit_test(test_wm_sca_test_positive_minterm_exact_match), - cmocka_unit_test(test_wm_sca_test_positive_minterm_no_exact_match), - cmocka_unit_test(test_wm_sca_test_positive_minterm_numeric_expression), - cmocka_unit_test(test_wm_sca_test_positive_minterm_numeric_expression_fail), - cmocka_unit_test(test_wm_sca_regex_numeric_comparison_PCRE2), - cmocka_unit_test(test_wm_sca_regex_numeric_comparison_OS_REGEX), - cmocka_unit_test(test_wm_sca_regex_numeric_comparison_without_compare_word_nor_reason), - cmocka_unit_test(test_wm_sca_regex_numeric_comparison_without_compare_word_with_reason), - cmocka_unit_test(test_wm_sca_regex_numeric_comparison_no_match), - cmocka_unit_test(test_wm_sca_regex_numeric_comparison_no_detect_number_with_reason_null), - cmocka_unit_test(test_wm_sca_regex_numeric_comparison_no_detect_number_with_reason_not_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_OS_REGEX), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_OS_REGEX_fail), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_PCRE2), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_PCRE2_fail), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_without_string_to_compare_with_reason_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_without_string_to_compare_with_reason_not_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_not_compile_with_reason_not_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_not_compile_with_reason_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_not_match_regex_with_reason_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_not_match_regex_with_reason_not_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_no_capture_number_with_reason_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_no_capture_number_with_reason_not_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_no_operation_supported_with_reason_null), - cmocka_unit_test(test_wm_sca_apply_numeric_partial_comparison_no_operation_supported_with_reason_not_null) - }; - int result; - result = cmocka_run_group_tests(tests_with_startup, setup_module, teardown_module); - result += cmocka_run_group_tests(tests_without_startup, NULL, NULL); - return result; -} diff --git a/src/unit_tests/wazuh_modules/scheduling/CMakeLists.txt b/src/unit_tests/wazuh_modules/scheduling/CMakeLists.txt deleted file mode 100644 index 5a459345a31..00000000000 --- a/src/unit_tests/wazuh_modules/scheduling/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Tests list and flags -list(APPEND tests_names "test_wmodules_scheduling") -list(APPEND tests_flags "-Wl,--wrap=time,--wrap=w_time_delay,--wrap=w_sleep_until,--wrap=_mwarn,--wrap=_minfo,--wrap=_merror") -list(APPEND use_shared_libs 1) - -list(APPEND shared_libs "wmodules_scheduling_helpers.h") -list(APPEND shared_libs "wmodules_scheduling_helpers.c") - -# Generate modulesd library -file(GLOB modulesd_files ../../../wazuh_modules/*.o) -list(REMOVE_ITEM modulesd_files ../../../wazuh_modules/main.o) -file(GLOB syscollector_files ../../../wazuh_modules/syscollector/*.o) - -add_library(SCHEDULING_MODULESD_O STATIC ${modulesd_files}) - -set_source_files_properties( - ${modulesd_files} - ${syscollector_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true - ) - -set_target_properties( - SCHEDULING_MODULESD_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(SCHEDULING_MODULESD_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - - -# Compiling tests -list(LENGTH tests_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET tests_names ${counter} test_name) - list(GET tests_flags ${counter} test_flags) - list(GET use_shared_libs ${counter} use_libs) - - if(use_libs EQUAL "1") - add_executable(${test_name} ${test_name}.c ${shared_libs}) - else () - add_executable(${test_name} ${test_name}.c) - endif() - - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - SCHEDULING_MODULESD_O - -ldl - -lcmocka - -fprofile-arcs - -ftest-coverage - ) - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(${test_name} ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/scheduling/test_wmodules_scheduling.c b/src/unit_tests/wazuh_modules/scheduling/test_wmodules_scheduling.c deleted file mode 100644 index 9d6ead948f7..00000000000 --- a/src/unit_tests/wazuh_modules/scheduling/test_wmodules_scheduling.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the scheduling capacities - * described in 'headers/schedule_scan.h' and - * 'shared/schedule_scan.c' files -* */ - -#include -#include -#include -#include -#include -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" -#include "wmodules_scheduling_helpers.h" - -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/time_op_wrappers.h" - -static const int TEST_INTERVAL = 5 * 60; -static const int TEST_DELAY = 5; -static const int TEST_DAY_MONTHS[] = {3, 8, 15, 21}; - -typedef struct state_structure { - OS_XML lxml; - sched_scan_config scan_config; - XML_NODE nodes; -} state_structure; - -static int test_setup(void **state) { - state_structure *test = calloc(1, sizeof(state_structure)); - *state = test; - sched_scan_init(&test->scan_config); - current_time = 0; - return 0; -} - -static int test_teardown(void **state) { - state_structure *test = *state; - sched_scan_free(&test->scan_config); - OS_ClearNode(test->nodes); - OS_ClearXML(&test->lxml); - free(test); - current_time = 0; - return 0; -} - -/** - * Test caclulated time for an INTERVAL with a sleep in - * between - * */ -static void test_interval_mode(void **state){ - state_structure *test = *state; - const char *string = - "5m" - ; - test->nodes = string_to_xml_node(string, &test->lxml); - sched_scan_read(&test->scan_config, test->nodes, ""); - time_t next_time = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_INTERVAL_MODE", 0); - // First time - assert_int_equal((int) next_time, TEST_INTERVAL); - // Sleep 5 secs - w_time_delay(1000 * TEST_INTERVAL); - next_time = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_INTERVAL_MODE", 0); - assert_int_equal((int) next_time, TEST_INTERVAL); -} - - -/** - * Test day of the month mode for different day values - * */ -static void test_day_of_the_month_mode(void **state){ - state_structure *test = *state; - // Set day of the month - test->scan_config.month_interval = true; - test->scan_config.interval = 1; - test->scan_config.scan_time = strdup("01:00"); - - for(int i = 0; i < (sizeof(TEST_DAY_MONTHS)/ sizeof(int)); i++){ - test->scan_config.scan_day = TEST_DAY_MONTHS[i]; - - time_t time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_DAY_MONTH_MODE", 0); - time_t next_time = time(NULL) + time_sleep; - - struct tm *date = localtime(&next_time); - // Assert execution time is the expected month day - assert_int_equal(date->tm_mday, TEST_DAY_MONTHS[i]); - } -} - -/** - * Test 2 consecutive day of the month - * */ -static void test_day_of_the_month_consecutive(void **state){ - state_structure *test = *state; - const char *string = - "20\n" - "" - ; - - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one month. New interval value: 1M"); - - test->nodes = string_to_xml_node(string, &test->lxml); - sched_scan_read(&test->scan_config, test->nodes, ""); - // Set to 2 months - test->scan_config.interval = 2; - - time_t time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_DAY_MONTH_MODE", 0); - // Sleep past execution moment by 1 hour - w_time_delay(time_sleep * 1000); - - time_t first_time = time(NULL) ; - struct tm first_date = *(localtime(&first_time)); - // Assert execution time is the expected month day - assert_int_equal(first_date.tm_mday, test->scan_config.scan_day); - - time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_DAY_MONTH_MODE", 0); - time_t second_time = time(NULL) + time_sleep; - - struct tm second_date = *(localtime(&second_time)); - - assert_int_equal(second_date.tm_mday, test->scan_config.scan_day); - // Check it is following month - assert_int_equal((first_date.tm_mon + test->scan_config.interval) % 12, second_date.tm_mon); -} - -/** - * Test 1 day of the week - * */ -static void test_day_of_the_week(void **state){ - state_structure *test = *state; - const char *string = - "tuesday\n" - "\n" - "3w\n" - ; - test->nodes = string_to_xml_node(string, &test->lxml); - sched_scan_read(&test->scan_config, test->nodes, ""); - - time_t time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_WDAY_MODE", 0); - // Sleep past execution moment by 1 hour - w_time_delay((time_sleep + 3600) * 1000); - - time_t first_time = time(NULL); - struct tm first_date = *(localtime(&first_time)); - - assert_int_equal(first_date.tm_wday, test->scan_config.scan_wday); - - time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_WDAY_MODE", 0); - time_t second_time = time(NULL) + time_sleep; - - struct tm second_date = *(localtime(&second_time)); - assert_int_equal(second_date.tm_wday, test->scan_config.scan_wday); - assert_int_equal(second_date.tm_yday, (first_date.tm_yday + 21) % 365); -} - -/** - * Test time of day execution - * */ -static void test_time_of_day(void **state){ - state_structure *test = *state; - const char *string = - "" - ; - test->nodes = string_to_xml_node(string, &test->lxml); - sched_scan_read(&test->scan_config, test->nodes, ""); - time_t time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_WDAY_MODE", 0); - w_time_delay(time_sleep * 1000); - - time_t aux_time = time(NULL); - struct tm date = *(localtime(&aux_time)); - - assert_int_equal(date.tm_hour, 5); - assert_int_equal(date.tm_min, 18); -} - -/** - * Test Parsing and dumping of configurations - * */ -static void test_parse_xml_and_dump(void **state){ - state_structure *test = *state; - const char *string = - "friday\n" - ""; - expect_string(__wrap__mwarn, formatted_msg, "Interval must be a multiple of one week. New interval value: 1w"); - test->nodes = string_to_xml_node(string, &test->lxml); - sched_scan_read(&test->scan_config, test->nodes, ""); - cJSON *data = cJSON_CreateObject(); - sched_scan_dump(&test->scan_config, data); - char *result_str = cJSON_PrintUnformatted(data); - assert_string_equal(result_str, "{\"interval\":604800,\"wday\":\"friday\",\"time\":\"13:14\"}"); - cJSON_Delete(data); - free(result_str); -} - - -/** - * Test month day calculation when close to end of year - * */ -static void test_day_of_month_wrap_year(void **state) { - state_structure *test = *state; - test->scan_config.month_interval = true; - test->scan_config.interval = 2; - test->scan_config.scan_day = 5; - test->scan_config.scan_time = strdup("00:00"); - - time_t aux_time = time(NULL); - struct tm tm = *(localtime(&aux_time)); - tm.tm_mon = 11; - tm.tm_mday = 5; // 5th of December - // Set simulation time - set_current_time(mktime(&tm)); - - time_t time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_DAY_MONTH_MODE", 0); - w_time_delay(time_sleep * 1000); - - time_t first_time = time(NULL) ; - struct tm first_date = *(localtime(&first_time)); - // Assert execution time is the expected month day - assert_int_equal(first_date.tm_mday, test->scan_config.scan_day); - assert_int_equal(first_date.tm_mon, 1); - assert_int_equal(first_date.tm_year, tm.tm_year + 1); -} - -static void test_day_of_month_very_long_time(void **state) { - state_structure *test = *state; - test->scan_config.month_interval = true; - test->scan_config.interval = 25; // 25 months interval - test->scan_config.scan_day = 1; - test->scan_config.scan_time = strdup("00:00"); - - time_t aux_time = time(NULL); - struct tm tm = *(localtime(&aux_time)); - tm.tm_mon = 10; - tm.tm_mday = 1; // 1st of November - // Set simulation time - set_current_time(mktime(&tm)); - - time_t time_sleep = sched_scan_get_time_until_next_scan(&test->scan_config, "TEST_DAY_MONTH_MODE", 0); - w_time_delay(time_sleep * 1000); - - time_t first_time = time(NULL) ; - struct tm first_date = *(localtime(&first_time)); - // Assert execution time is the expected month day - assert_int_equal(first_date.tm_mday, test->scan_config.scan_day); - assert_int_equal(first_date.tm_mon, 11); - assert_int_equal(first_date.tm_year, tm.tm_year + 2); -} - - -int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_interval_mode, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_day_of_the_month_mode, test_setup, test_teardown), - // cmocka_unit_test_setup_teardown(test_day_of_the_month_consecutive, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_day_of_the_week, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_time_of_day, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_parse_xml_and_dump, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_day_of_month_wrap_year, test_setup, test_teardown), - cmocka_unit_test_setup_teardown(test_day_of_month_very_long_time, test_setup, test_teardown) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/scheduling/wmodules_scheduling_helpers.c b/src/unit_tests/wazuh_modules/scheduling/wmodules_scheduling_helpers.c deleted file mode 100644 index c84ea26ffe7..00000000000 --- a/src/unit_tests/wazuh_modules/scheduling/wmodules_scheduling_helpers.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include "wmodules_scheduling_helpers.h" -#include "../../wrappers/wazuh/shared/time_op_wrappers.h" -#include - -extern time_t __real_time(time_t *_time); -/**************** Mocked functions *************/ -/** Mocked functions **/ - -time_t __wrap_time(time_t *_time){ - if(!current_time){ - current_time = 1606797884; - } - return current_time; -} - -/* Sets current simulation time */ -void set_current_time(time_t _time) { - current_time = _time; -} - -/***************** Helpers ********************/ -/** - * Receives a string in XML format and returnes it as an xml_node array structure - * Example: - * - * "no\n" - * "10m\n" - * "yes\n" - * "yes\n" - * "\n" - * " wazuh-aws-wodle\n" - * " config\n" - * " default\n" - * "" - * */ -const XML_NODE string_to_xml_node(const char * string, OS_XML *_lxml){ - XML_NODE nodes; - OS_ReadXMLString(string, _lxml); - nodes = OS_GetElementsbyNode(_lxml, NULL); - return nodes; -} - - -/** - * Inits a shched_config object based on an xml format string - * Example: - * "tuesday\n" - * "" - * */ -sched_scan_config init_config_from_string(const char* string){ - OS_XML _lxml; - XML_NODE nodes = string_to_xml_node(string, &_lxml); - - sched_scan_config scan_config; - sched_scan_init(&scan_config); - sched_scan_read(&scan_config, nodes, ""); - OS_ClearNode(nodes); - OS_ClearXML(&_lxml); - return scan_config; -} diff --git a/src/unit_tests/wazuh_modules/scheduling/wmodules_scheduling_helpers.h b/src/unit_tests/wazuh_modules/scheduling/wmodules_scheduling_helpers.h deleted file mode 100644 index 8ae444b8888..00000000000 --- a/src/unit_tests/wazuh_modules/scheduling/wmodules_scheduling_helpers.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#ifndef __WMODULES_SCHEDULING_HELPERS_H__ -#define __WMODULES_SCHEDULING_HELPERS_H__ - -#include -#include -#include -#include -#include "shared.h" -#include "../../../wazuh_modules/wmodules.h" - -typedef struct test_structure { - wmodule *module; - OS_XML xml; - XML_NODE nodes; -} test_structure; - -const XML_NODE string_to_xml_node(const char * string, OS_XML *_lxml); -sched_scan_config init_config_from_string(const char* string); - -/* Sets current simulation time */ -void set_current_time(time_t _time); - -#endif diff --git a/src/unit_tests/wazuh_modules/task_manager/CMakeLists.txt b/src/unit_tests/wazuh_modules/task_manager/CMakeLists.txt deleted file mode 100644 index 42a55e218cd..00000000000 --- a/src/unit_tests/wazuh_modules/task_manager/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -# Generate task manager library -file(GLOB task_files - ${SRC_FOLDER}/wazuh_modules/*.o - ${SRC_FOLDER}/wazuh_modules/task_manager/*.o) -list(REMOVE_ITEM task_files ${SRC_FOLDER}/wazuh_modules/main.o) - -add_library(TASK_O STATIC ${task_files}) - -set_source_files_properties( - ${task_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - TASK_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(TASK_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate task manager tests -list(APPEND task_names "test_wm_task_manager") -list(APPEND task_flags "-Wl,--wrap,pthread_exit -Wl,--wrap,CreateThread -Wl,--wrap,OS_BindUnixDomainWithPerms -Wl,--wrap,select -Wl,--wrap,close \ - -Wl,--wrap,accept -Wl,--wrap,OS_RecvSecureTCP -Wl,--wrap,OS_SendSecureTCP -Wl,--wrap,w_is_worker -Wl,--wrap,wm_task_manager_parse_message -Wl,--wrap,wm_task_manager_process_task \ - -Wl,--wrap,wm_task_manager_parse_data_response -Wl,--wrap,getpid ${DEBUG_OP_WRAPPERS}") - -list(APPEND task_names "test_wm_task_manager_parsing") -list(APPEND task_flags "-Wl,--wrap,w_get_timestamp ${DEBUG_OP_WRAPPERS}") - -list(APPEND task_names "test_wm_task_manager_commands") -list(APPEND task_flags "-Wl,--wrap,wm_task_manager_parse_data_response -Wl,--wrap,wm_task_manager_parse_data_result \ - -Wl,--wrap,wdbc_query_ex -Wl,--wrap,wdbc_parse_result -Wl,--wrap,time -Wl,--wrap,w_sleep_until \ - ${DEBUG_OP_WRAPPERS}") - -# Compilig tests -list(LENGTH task_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET task_names ${counter} test_name) - list(GET task_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - TASK_O - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager.c b/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager.c deleted file mode 100644 index d67f04f2f14..00000000000 --- a/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager.c +++ /dev/null @@ -1,1081 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/posix/pthread_wrappers.h" -#include "../../wrappers/posix/select_wrappers.h" -#include "../../wrappers/posix/unistd_wrappers.h" -#include "../../wrappers/wazuh/shared/cluster_op_wrappers.h" -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/pthreads_op_wrappers.h" -#include "../../wrappers/wazuh/os_net/os_net_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_task_manager_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/task_manager/wm_task_manager.h" -#include "../../wazuh_modules/task_manager/wm_task_manager_tasks.h" -#include "../../headers/shared.h" - -int wm_task_manager_init(wm_task_manager *task_config); -void* wm_task_manager_main(wm_task_manager* task_config); -void wm_task_manager_destroy(wm_task_manager* task_config); -cJSON* wm_task_manager_dump(const wm_task_manager* task_config); - -// Setup / teardown - -static int setup_group(void **state) { - wm_task_manager *config = NULL; - os_calloc(1, sizeof(wm_task_manager), config); - *state = config; - return 0; -} - -static int teardown_group(void **state) { - wm_task_manager *config = *state; - os_free(config); - return 0; -} - -static int teardown_json(void **state) { - if (state[1]) { - cJSON *json = state[1]; - cJSON_Delete(json); - } - return 0; -} - -static int teardown_string(void **state) { - if (state[1]) { - char *string = state[1]; - os_free(string); - } - return 0; -} - -// Wrappers - -int __wrap_accept() { - return mock(); -} - -// Tests - -void test_wm_task_manager_dump_enabled(void **state) -{ - wm_task_manager *config = *state; - - config->enabled = 1; - - cJSON *ret = wm_task_manager_dump(config); - - state[1] = ret; - - assert_non_null(ret); - cJSON *conf = cJSON_GetObjectItem(ret, "task-manager"); - assert_non_null(conf); - assert_non_null(cJSON_GetObjectItem(conf, "enabled")); - assert_string_equal(cJSON_GetObjectItem(conf, "enabled")->valuestring, "yes"); -} - -void test_wm_task_manager_dump_disabled(void **state) -{ - wm_task_manager *config = *state; - - config->enabled = 0; - - cJSON *ret = wm_task_manager_dump(config); - - state[1] = ret; - - assert_non_null(ret); - cJSON *conf = cJSON_GetObjectItem(ret, "task-manager"); - assert_non_null(conf); - assert_non_null(cJSON_GetObjectItem(conf, "enabled")); - assert_string_equal(cJSON_GetObjectItem(conf, "enabled")->valuestring, "no"); -} - -void test_wm_task_manager_destroy(void **state) -{ - wm_task_manager *config = NULL; - os_calloc(1, sizeof(wm_task_manager), config); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8201): Module Task Manager finished."); - - wm_task_manager_destroy(config); -} - -void test_wm_task_manager_init_ok(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - - config->enabled = 1; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - int ret = wm_task_manager_init(config); - - assert_int_equal(ret, sock); -} - -void test_wm_task_manager_init_bind_err(void **state) -{ - wm_task_manager *config = *state; - - config->enabled = 1; - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, OS_INVALID); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8251): Queue 'queue/tasks/task' not accessible: 'Success'. Exiting..."); - - expect_assert_failure(wm_task_manager_init(config)); -} - -void test_wm_task_manager_init_disabled(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - - config->enabled = 0; - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8202): Module disabled. Exiting..."); - - expect_assert_failure(wm_task_manager_init(config)); -} - -void test_wm_task_manager_dispatch_ok(void **state) -{ - char *response = NULL; - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(3, sizeof(int), agents); - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - os_strdup("upgrade_module", task_parameters->module); - os_strdup("node05", task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE; - task->parameters = task_parameters; - - cJSON *data_array = cJSON_CreateArray(); - - cJSON *response1 = cJSON_CreateObject(); - cJSON_AddNumberToObject(response1, "error", WM_TASK_SUCCESS); - cJSON_AddStringToObject(response1, "message", "Success"); - cJSON_AddNumberToObject(response1, "agent", 1); - - cJSON *response2 = cJSON_CreateObject(); - cJSON_AddNumberToObject(response2, "error", WM_TASK_SUCCESS); - cJSON_AddStringToObject(response2, "message", "Success"); - cJSON_AddNumberToObject(response2, "agent", 2); - - cJSON_AddItemToArray(data_array, response1); - cJSON_AddItemToArray(data_array, response2); - - char *result = "{\"error\":0,\"data\":[{\"error\":0,\"message\":\"Success\",\"agent\":1},{\"error\":0,\"message\":\"Success\",\"agent\":2}],\"message\":\"Success\"}"; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8204): Incomming message: '{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}'"); - - expect_string(__wrap_wm_task_manager_parse_message, msg, message); - will_return(__wrap_wm_task_manager_parse_message, task); - - expect_memory(__wrap_wm_task_manager_process_task, task, task, sizeof(task)); - will_return(__wrap_wm_task_manager_process_task, WM_TASK_SUCCESS); - will_return(__wrap_wm_task_manager_process_task, data_array); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8205): Response to message: '{\"error\":0,\"data\":[{\"error\":0,\"message\":\"Success\",\"agent\":1},{\"error\":0,\"message\":\"Success\",\"agent\":2}],\"message\":\"Success\"}'"); - - int ret = wm_task_manager_dispatch(message, &response); - - state[1] = response; - - assert_int_equal(ret, strlen(result)); - assert_string_equal(response, result); -} - -void test_wm_task_manager_dispatch_command_err(void **state) -{ - char *response = NULL; - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"unknown\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - - task->command = WM_TASK_UNKNOWN; - - cJSON *response_error = cJSON_CreateObject(); - cJSON_AddNumberToObject(response_error, "error", WM_TASK_INVALID_COMMAND); - cJSON_AddStringToObject(response_error, "message", "Invalid command"); - - char *result = "{\"error\":2,\"data\":[{\"error\":2,\"message\":\"Invalid command\"}],\"message\":\"Invalid command\"}"; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8204): Incomming message: '{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"unknown\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}'"); - - expect_string(__wrap_wm_task_manager_parse_message, msg, message); - will_return(__wrap_wm_task_manager_parse_message, task); - - expect_memory(__wrap_wm_task_manager_process_task, task, task, sizeof(task)); - will_return(__wrap_wm_task_manager_process_task, WM_TASK_INVALID_COMMAND); - will_return(__wrap_wm_task_manager_process_task, NULL); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8258): No action defined for command provided."); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_INVALID_COMMAND); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, OS_INVALID); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, response_error); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8205): Response to message: '{\"error\":2,\"data\":[{\"error\":2,\"message\":\"Invalid command\"}],\"message\":\"Invalid command\"}'"); - - int ret = wm_task_manager_dispatch(message, &response); - - state[1] = response; - - assert_int_equal(ret, strlen(result)); - assert_string_equal(response, result); -} - -void test_wm_task_manager_dispatch_db_err(void **state) -{ - char *response = NULL; - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(3, sizeof(int), agents); - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - os_strdup("upgrade_module", task_parameters->module); - os_strdup("node05", task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE; - task->parameters = task_parameters; - - cJSON *response_error = cJSON_CreateObject(); - cJSON_AddNumberToObject(response_error, "error", WM_TASK_DATABASE_ERROR); - cJSON_AddStringToObject(response_error, "message", "Database error"); - - char *result = "{\"error\":4,\"data\":[{\"error\":4,\"message\":\"Database error\"}],\"message\":\"Database error\"}"; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8204): Incomming message: '{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}'"); - - expect_string(__wrap_wm_task_manager_parse_message, msg, message); - will_return(__wrap_wm_task_manager_parse_message, task); - - expect_memory(__wrap_wm_task_manager_process_task, task, task, sizeof(task)); - will_return(__wrap_wm_task_manager_process_task, WM_TASK_DATABASE_ERROR); - will_return(__wrap_wm_task_manager_process_task, NULL); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8261): Database error."); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_DATABASE_ERROR); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, OS_INVALID); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, response_error); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8205): Response to message: '{\"error\":4,\"data\":[{\"error\":4,\"message\":\"Database error\"}],\"message\":\"Database error\"}'"); - - int ret = wm_task_manager_dispatch(message, &response); - - state[1] = response; - - assert_int_equal(ret, strlen(result)); - assert_string_equal(response, result); -} - -void test_wm_task_manager_dispatch_db_parse_err(void **state) -{ - char *response = NULL; - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(3, sizeof(int), agents); - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - os_strdup("upgrade_module", task_parameters->module); - os_strdup("node05", task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE; - task->parameters = task_parameters; - - cJSON *response_error = cJSON_CreateObject(); - cJSON_AddNumberToObject(response_error, "error", WM_TASK_DATABASE_PARSE_ERROR); - cJSON_AddStringToObject(response_error, "message", "Parse DB response error"); - - char *result = "{\"error\":5,\"data\":[{\"error\":5,\"message\":\"Parse DB response error\"}],\"message\":\"Parse DB response error\"}"; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8204): Incomming message: '{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}'"); - - expect_string(__wrap_wm_task_manager_parse_message, msg, message); - will_return(__wrap_wm_task_manager_parse_message, task); - - expect_memory(__wrap_wm_task_manager_process_task, task, task, sizeof(task)); - will_return(__wrap_wm_task_manager_process_task, WM_TASK_DATABASE_PARSE_ERROR); - will_return(__wrap_wm_task_manager_process_task, NULL); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8261): Database error."); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_DATABASE_PARSE_ERROR); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, OS_INVALID); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, response_error); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8205): Response to message: '{\"error\":5,\"data\":[{\"error\":5,\"message\":\"Parse DB response error\"}],\"message\":\"Parse DB response error\"}'"); - - int ret = wm_task_manager_dispatch(message, &response); - - state[1] = response; - - assert_int_equal(ret, strlen(result)); - assert_string_equal(response, result); -} - -void test_wm_task_manager_dispatch_db_request_err(void **state) -{ - char *response = NULL; - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(3, sizeof(int), agents); - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - os_strdup("upgrade_module", task_parameters->module); - os_strdup("node05", task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE; - task->parameters = task_parameters; - - cJSON *response_error = cJSON_CreateObject(); - cJSON_AddNumberToObject(response_error, "error", WM_TASK_DATABASE_REQUEST_ERROR); - cJSON_AddStringToObject(response_error, "message", "Error in DB request"); - - char *result = "{\"error\":6,\"data\":[{\"error\":6,\"message\":\"Error in DB request\"}],\"message\":\"Error in DB request\"}"; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8204): Incomming message: '{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}'"); - - expect_string(__wrap_wm_task_manager_parse_message, msg, message); - will_return(__wrap_wm_task_manager_parse_message, task); - - expect_memory(__wrap_wm_task_manager_process_task, task, task, sizeof(task)); - will_return(__wrap_wm_task_manager_process_task, WM_TASK_DATABASE_REQUEST_ERROR); - will_return(__wrap_wm_task_manager_process_task, NULL); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8261): Database error."); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_DATABASE_REQUEST_ERROR); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, OS_INVALID); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, response_error); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8205): Response to message: '{\"error\":6,\"data\":[{\"error\":6,\"message\":\"Error in DB request\"}],\"message\":\"Error in DB request\"}'"); - - int ret = wm_task_manager_dispatch(message, &response); - - state[1] = response; - - assert_int_equal(ret, strlen(result)); - assert_string_equal(response, result); -} - -void test_wm_task_manager_dispatch_parse_err(void **state) -{ - char *response = NULL; - char *message = "unknown json"; - - cJSON *response_json = cJSON_CreateObject(); - cJSON_AddNumberToObject(response_json, "error", WM_TASK_INVALID_MESSAGE); - cJSON_AddStringToObject(response_json, "message", "Invalid message"); - - char *result = "{\"error\":1,\"data\":[{\"error\":1,\"message\":\"Invalid message\"}],\"message\":\"Invalid message\"}"; - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8204): Incomming message: 'unknown json'"); - - expect_string(__wrap_wm_task_manager_parse_message, msg, message); - will_return(__wrap_wm_task_manager_parse_message, NULL); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_INVALID_MESSAGE); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, OS_INVALID); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, response_json); - - int ret = wm_task_manager_dispatch(message, &response); - - state[1] = response; - - assert_int_equal(ret, strlen(result)); - assert_string_equal(response, result); -} - -void test_wm_task_manager_main_ok(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(3, sizeof(int), agents); - agents[0] = 1; - agents[1] = 2; - agents[2] = OS_INVALID; - - os_strdup("upgrade_module", task_parameters->module); - os_strdup("node05", task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE; - task->parameters = task_parameters; - - cJSON *data_array = cJSON_CreateArray(); - - cJSON *response1 = cJSON_CreateObject(); - cJSON_AddNumberToObject(response1, "error", WM_TASK_SUCCESS); - cJSON_AddStringToObject(response1, "message", "Success"); - cJSON_AddNumberToObject(response1, "agent", 1); - - cJSON *response2 = cJSON_CreateObject(); - cJSON_AddNumberToObject(response2, "error", WM_TASK_SUCCESS); - cJSON_AddStringToObject(response2, "message", "Success"); - cJSON_AddNumberToObject(response2, "agent", 2); - - cJSON_AddItemToArray(data_array, response1); - cJSON_AddItemToArray(data_array, response2); - - char *response = "{\"error\":0,\"data\":[{\"error\":0,\"message\":\"Success\",\"agent\":1},{\"error\":0,\"message\":\"Success\",\"agent\":2}],\"message\":\"Success\"}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, message); - will_return(__wrap_OS_RecvSecureTCP, strlen(message) + 1); - - // wm_task_manager_dispatch - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8204): Incomming message: '{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}'"); - - expect_string(__wrap_wm_task_manager_parse_message, msg, message); - will_return(__wrap_wm_task_manager_parse_message, task); - - expect_memory(__wrap_wm_task_manager_process_task, task, task, sizeof(task)); - will_return(__wrap_wm_task_manager_process_task, WM_TASK_SUCCESS); - will_return(__wrap_wm_task_manager_process_task, data_array); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8205): Response to message: '{\"error\":0,\"data\":[{\"error\":0,\"message\":\"Success\",\"agent\":1},{\"error\":0,\"message\":\"Success\",\"agent\":2}],\"message\":\"Success\"}'"); - - expect_value(__wrap_OS_SendSecureTCP, sock, peer); - expect_value(__wrap_OS_SendSecureTCP, size, strlen(response)); - expect_string(__wrap_OS_SendSecureTCP, msg, response); - will_return(__wrap_OS_SendSecureTCP, 0); - - wm_task_manager_main(config); -} - -void test_wm_task_manager_main_recv_max_err(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, message); - will_return(__wrap_OS_RecvSecureTCP, OS_MAXLEN); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8256): Received message > '4194304'"); - - wm_task_manager_main(config); -} - -void test_wm_task_manager_main_recv_empty_err(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, message); - will_return(__wrap_OS_RecvSecureTCP, 0); - - expect_string(__wrap__mtdebug1, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtdebug1, formatted_msg, "(8203): Empty message from local client."); - - wm_task_manager_main(config); -} - -void test_wm_task_manager_main_recv_err(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, message); - will_return(__wrap_OS_RecvSecureTCP, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8254): Error in recv(): 'Success'"); - - wm_task_manager_main(config); -} - -void test_wm_task_manager_main_sockterr_err(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, message); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8255): Response size is bigger than expected."); - - wm_task_manager_main(config); -} - -void test_wm_task_manager_main_accept_err(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8253): Error in accept(): 'Success'"); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, message); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8255): Response size is bigger than expected."); - - wm_task_manager_main(config); -} - -void test_wm_task_manager_main_select_empty_err(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, 0); - - will_return(__wrap_select, 1); - - will_return(__wrap_accept, peer); - - expect_value(__wrap_OS_RecvSecureTCP, sock, peer); - expect_value(__wrap_OS_RecvSecureTCP, size, OS_MAXSTR); - will_return(__wrap_OS_RecvSecureTCP, message); - will_return(__wrap_OS_RecvSecureTCP, OS_SOCKTERR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8255): Response size is bigger than expected."); - - wm_task_manager_main(config); -} - -void test_wm_task_manager_main_select_err(void **state) -{ - wm_task_manager *config = *state; - int sock = 555; - int peer = 1111; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 0); - - // wm_task_manager_init - - expect_string(__wrap_OS_BindUnixDomainWithPerms, path, TASK_QUEUE); - expect_value(__wrap_OS_BindUnixDomainWithPerms, type, SOCK_STREAM); - expect_value(__wrap_OS_BindUnixDomainWithPerms, max_msg_size, OS_MAXSTR); - expect_value(__wrap_OS_BindUnixDomainWithPerms, uid, getuid()); - expect_value(__wrap_OS_BindUnixDomainWithPerms, gid, 0); - expect_value(__wrap_OS_BindUnixDomainWithPerms, perm, 0660); - - will_return(__wrap_OS_BindUnixDomainWithPerms, sock); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8200): Module Task Manager started."); - - will_return(__wrap_select, -1); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8252): Error in select(): 'Success'. Exiting..."); - - expect_assert_failure(wm_task_manager_main(config)); -} - -void test_wm_task_manager_main_worker_err(void **state) -{ - wm_task_manager *config = *state; - - config->enabled = 1; - - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - will_return(__wrap_w_is_worker, 1); - - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mtinfo, formatted_msg, "(8207): Module Task Manager only runs on Master nodes in cluster configuration."); - - wm_task_manager_main(config); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_task_manager_dump - cmocka_unit_test_teardown(test_wm_task_manager_dump_enabled, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_dump_disabled, teardown_json), - // wm_task_manager_destroy - cmocka_unit_test(test_wm_task_manager_destroy), - // wm_task_manager_init - cmocka_unit_test(test_wm_task_manager_init_ok), - cmocka_unit_test(test_wm_task_manager_init_bind_err), - cmocka_unit_test(test_wm_task_manager_init_disabled), - // wm_task_manager_dispatch - cmocka_unit_test_teardown(test_wm_task_manager_dispatch_ok, teardown_string), - cmocka_unit_test_teardown(test_wm_task_manager_dispatch_command_err, teardown_string), - cmocka_unit_test_teardown(test_wm_task_manager_dispatch_db_err, teardown_string), - cmocka_unit_test_teardown(test_wm_task_manager_dispatch_db_parse_err, teardown_string), - cmocka_unit_test_teardown(test_wm_task_manager_dispatch_db_request_err, teardown_string), - cmocka_unit_test_teardown(test_wm_task_manager_dispatch_parse_err, teardown_string), - // wm_task_manager_main - cmocka_unit_test(test_wm_task_manager_main_ok), - cmocka_unit_test(test_wm_task_manager_main_recv_max_err), - cmocka_unit_test(test_wm_task_manager_main_recv_empty_err), - cmocka_unit_test(test_wm_task_manager_main_recv_err), - cmocka_unit_test(test_wm_task_manager_main_sockterr_err), - cmocka_unit_test(test_wm_task_manager_main_accept_err), - cmocka_unit_test(test_wm_task_manager_main_select_empty_err), - cmocka_unit_test(test_wm_task_manager_main_select_err), - cmocka_unit_test(test_wm_task_manager_main_worker_err) - }; - return cmocka_run_group_tests(tests, setup_group, teardown_group); -} diff --git a/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager_commands.c b/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager_commands.c deleted file mode 100644 index cd3ca4238f8..00000000000 --- a/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager_commands.c +++ /dev/null @@ -1,1486 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/time_op_wrappers.h" -#include "../../wrappers/wazuh/wazuh_db/wdb_wrappers.h" -#include "../../wrappers/wazuh/wazuh_modules/wm_task_manager_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/task_manager/wm_task_manager.h" -#include "../../wazuh_modules/task_manager/wm_task_manager_tasks.h" -#include "../../headers/shared.h" - -cJSON* wm_task_manager_command_upgrade(wm_task_manager_upgrade *task, int command, int *error_code); -cJSON* wm_task_manager_command_upgrade_get_status(wm_task_manager_upgrade_get_status *task, int *error_code); -cJSON* wm_task_manager_command_upgrade_update_status(wm_task_manager_upgrade_update_status *task, int *error_code); -cJSON* wm_task_manager_command_upgrade_result(wm_task_manager_upgrade_result *task, int *error_code); -cJSON* wm_task_manager_command_upgrade_cancel_tasks(wm_task_manager_upgrade_cancel_tasks *task, int *error_code); -cJSON* wm_task_manager_send_message_to_wdb(const char *command, cJSON *parameters, int *error_code); - -// Setup / teardown - -static int setup_config(void **state) { - wm_task_manager *config = NULL; - os_calloc(1, sizeof(wm_task_manager), config); - *state = config; - return 0; -} - -static int teardown_config(void **state) { - wm_task_manager *config = *state; - os_free(config); - return 0; -} - -static int teardown_jsons(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - cJSON *json = state[1]; - cJSON_Delete(json); - } - return 0; -} - -static int teardown_json_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_task *task = (wm_task_manager_task*)state[1]; - wm_task_manager_free_task(task); - } - return 0; -} - -static int teardown_json_upgrade_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade *task = (wm_task_manager_upgrade*)state[1]; - wm_task_manager_free_upgrade_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_get_status_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_get_status *task = (wm_task_manager_upgrade_get_status*)state[1]; - wm_task_manager_free_upgrade_get_status_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_update_status_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_update_status *task = (wm_task_manager_upgrade_update_status*)state[1]; - wm_task_manager_free_upgrade_update_status_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_result_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_result *task = (wm_task_manager_upgrade_result*)state[1]; - wm_task_manager_free_upgrade_result_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_cancel_tasks_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_cancel_tasks *task = (wm_task_manager_upgrade_cancel_tasks*)state[1]; - wm_task_manager_free_upgrade_cancel_tasks_parameters(task); - } - return 0; -} - -// Tests - -void test_wm_task_manager_send_message_to_wdb_ok(void **state) -{ - char *command = "upgrade"; - int error_code = 0; - - char *wdb_response = "ok {\"error\":0,\"task_id\":24}"; - - cJSON* parameters = cJSON_CreateObject(); - - cJSON_AddNumberToObject(parameters, "agent", 35); - cJSON_AddStringToObject(parameters, "node", "node02"); - cJSON_AddStringToObject(parameters, "module", "upgrade_module"); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - cJSON *response = wm_task_manager_send_message_to_wdb(command, parameters, &error_code); - - state[0] = parameters; - state[1] = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, 0); - assert_non_null(cJSON_GetObjectItem(response, "task_id")); - assert_int_equal(cJSON_GetObjectItem(response, "task_id")->valueint, 24); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_send_message_to_wdb_parse_err(void **state) -{ - char *command = "upgrade"; - int error_code = 0; - - char *wdb_response = "ok {\"error\":0,\"task_id\":24"; - - cJSON* parameters = cJSON_CreateObject(); - - cJSON_AddNumberToObject(parameters, "agent", 35); - cJSON_AddStringToObject(parameters, "node", "node02"); - cJSON_AddStringToObject(parameters, "module", "upgrade_module"); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8257): Error parsing JSON event: '{\"error\":0,\"task_id\":24'"); - - cJSON *response = wm_task_manager_send_message_to_wdb(command, parameters, &error_code); - - state[0] = parameters; - state[1] = NULL; - - assert_null(response); - assert_int_equal(error_code, WM_TASK_DATABASE_PARSE_ERROR); -} - -void test_wm_task_manager_send_message_to_wdb_request_err(void **state) -{ - char *command = "upgrade"; - int error_code = 0; - - char *wdb_response = "err Invalid message"; - - cJSON* parameters = cJSON_CreateObject(); - - cJSON_AddNumberToObject(parameters, "agent", 35); - cJSON_AddStringToObject(parameters, "node", "node02"); - cJSON_AddStringToObject(parameters, "module", "upgrade_module"); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_ERROR); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8208): Tasks DB Error reported in the result of the query, message: 'Invalid message'"); - - cJSON *response = wm_task_manager_send_message_to_wdb(command, parameters, &error_code); - - state[0] = parameters; - state[1] = NULL; - - assert_null(response); - assert_int_equal(error_code, WM_TASK_DATABASE_REQUEST_ERROR); -} - -void test_wm_task_manager_send_message_to_wdb_response_err(void **state) -{ - char *command = "upgrade"; - int error_code = 0; - - cJSON* parameters = cJSON_CreateObject(); - - cJSON_AddNumberToObject(parameters, "agent", 35); - cJSON_AddStringToObject(parameters, "node", "node02"); - cJSON_AddStringToObject(parameters, "module", "upgrade_module"); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8209): Tasks DB Cannot execute SQL query: err database 'queue/tasks/tasks.db'"); - - cJSON *response = wm_task_manager_send_message_to_wdb(command, parameters, &error_code); - - state[0] = parameters; - state[1] = NULL; - - assert_null(response); - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_ok(void **state) -{ - char *node = "node02"; - char *module = "upgrade_module"; - char *command = "upgrade"; - int error_code = 0; - int agent_id = 35; - int task_id = 24; - - char *wdb_response = "ok {\"error\":0,\"task_id\":24}"; - - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - os_strdup(module, task_parameters->module); - task_parameters->agent_ids = agents; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_command_upgrade(task_parameters, WM_TASK_UPGRADE, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_custom_ok(void **state) -{ - char *node = "node02"; - char *module = "upgrade_module"; - char *command = "upgrade_custom"; - int error_code = 0; - int agent_id = 35; - int task_id = 24; - - char *wdb_response = "ok {\"error\":0,\"task_id\":24}"; - - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - os_strdup(module, task_parameters->module); - task_parameters->agent_ids = agents; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_custom {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_command_upgrade(task_parameters, WM_TASK_UPGRADE_CUSTOM, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_db_err(void **state) -{ - char *node = "node02"; - char *module = "upgrade_module"; - char *command = "upgrade"; - int error_code = 0; - int agent_id = 35; - - char *wdb_response = "ok {\"error\":-1}"; - - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - os_strdup(module, task_parameters->module); - task_parameters->agent_ids = agents; - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - state[0] = NULL; - state[1] = task_parameters; - - cJSON *response = wm_task_manager_command_upgrade(task_parameters, WM_TASK_UPGRADE, &error_code); - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_db_response_null(void **state) -{ - char *node = "node02"; - char *module = "upgrade_module"; - char *command = "upgrade"; - int error_code = 0; - int agent_id = 35; - - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - os_strdup(module, task_parameters->module); - task_parameters->agent_ids = agents; - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":35,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8209): Tasks DB Cannot execute SQL query: err database 'queue/tasks/tasks.db'"); - - state[0] = NULL; - state[1] = task_parameters; - - cJSON *response = wm_task_manager_command_upgrade(task_parameters, WM_TASK_UPGRADE, &error_code); - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_get_status_ok(void **state) -{ - char *node = "node02"; - int error_code = 0; - int agent_id = 35; - - char *status_result = "In progress"; - - char *wdb_response = "ok {\"error\":0,\"status\":\"In progress\"}"; - - wm_task_manager_upgrade_get_status *task_parameters = wm_task_manager_init_upgrade_get_status_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_get_status {\"agent\":35,\"node\":\"node02\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - expect_string(__wrap_wm_task_manager_parse_data_response, status, status_result); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_command_upgrade_get_status(task_parameters, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_get_status_db_err(void **state) -{ - char *node = "node02"; - int error_code = 0; - int agent_id = 35; - - char *wdb_response = "ok {\"error\":-1}"; - - wm_task_manager_upgrade_get_status *task_parameters = wm_task_manager_init_upgrade_get_status_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_get_status {\"agent\":35,\"node\":\"node02\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - state[0] = NULL; - state[1] = task_parameters; - - cJSON *response = wm_task_manager_command_upgrade_get_status(task_parameters, &error_code); - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_get_status_db_response_null(void **state) -{ - char *node = "node02"; - int error_code = 0; - int agent_id = 35; - - wm_task_manager_upgrade_get_status *task_parameters = wm_task_manager_init_upgrade_get_status_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_get_status {\"agent\":35,\"node\":\"node02\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8209): Tasks DB Cannot execute SQL query: err database 'queue/tasks/tasks.db'"); - - state[0] = NULL; - state[1] = task_parameters; - - cJSON *response = wm_task_manager_command_upgrade_get_status(task_parameters, &error_code); - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_update_status_ok(void **state) -{ - char *node = "node02"; - int error_code = 0; - int agent_id = 35; - char *status = "Done"; - - char *wdb_response = "ok {\"error\":0}"; - - wm_task_manager_upgrade_update_status *task_parameters = wm_task_manager_init_upgrade_update_status_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - os_strdup(status, task_parameters->status); - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_update_status {\"agent\":35,\"node\":\"node02\",\"status\":\"Done\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_command_upgrade_update_status(task_parameters, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_update_status_task_err(void **state) -{ - char *node = "node02"; - int error_code = 0; - int agent_id = 35; - char *status = "Done"; - - char *wdb_response = "ok {\"error\":-2}"; - - wm_task_manager_upgrade_update_status *task_parameters = wm_task_manager_init_upgrade_update_status_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - os_strdup(status, task_parameters->status); - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_update_status {\"agent\":35,\"node\":\"node02\",\"status\":\"Done\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_DATABASE_NO_TASK); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_command_upgrade_update_status(task_parameters, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_update_status_db_err(void **state) -{ - char *node = "node02"; - int error_code = 0; - int agent_id = 35; - char *status = "Done"; - - char *wdb_response = "ok {\"error\":-1}"; - - wm_task_manager_upgrade_update_status *task_parameters = wm_task_manager_init_upgrade_update_status_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - os_strdup(status, task_parameters->status); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_update_status {\"agent\":35,\"node\":\"node02\",\"status\":\"Done\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - cJSON *response = wm_task_manager_command_upgrade_update_status(task_parameters, &error_code); - - state[0] = NULL; - state[1] = task_parameters; - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_update_status_db_response_null(void **state) -{ - char *node = "node02"; - int error_code = 0; - int agent_id = 35; - char *status = "Done"; - - wm_task_manager_upgrade_update_status *task_parameters = wm_task_manager_init_upgrade_update_status_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - os_strdup(status, task_parameters->status); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_update_status {\"agent\":35,\"node\":\"node02\",\"status\":\"Done\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8209): Tasks DB Cannot execute SQL query: err database 'queue/tasks/tasks.db'"); - - cJSON *response = wm_task_manager_command_upgrade_update_status(task_parameters, &error_code); - - state[0] = NULL; - state[1] = task_parameters; - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_result_ok(void **state) -{ - int error_code = 0; - int agent_id = 35; - int task_id = 24; - char *command = "upgrade_result"; - - char *node_result = "node01"; - char *module_result = "upgrade_module"; - char *command_result = "upgrade"; - char *status_result = "In progress"; - char *error_result = "Error string"; - int create_time = 789456123; - int last_update = 987654321; - - char *wdb_response = "ok {\"error\":0,\"task_id\":24,\"node\":\"node01\",\"module\":\"upgrade_module\",\"command\":\"upgrade\",\"create_time\":789456123,\"update_time\":987654321,\"status\":\"In progress\",\"error_msg\":\"Error string\"}"; - - wm_task_manager_upgrade_result *task_parameters = wm_task_manager_init_upgrade_result_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - task_parameters->agent_ids = agents; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_result {\"agent\":35}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - expect_string(__wrap_wm_task_manager_parse_data_result, node, node_result); - expect_string(__wrap_wm_task_manager_parse_data_result, module, module_result); - expect_string(__wrap_wm_task_manager_parse_data_result, command, command_result); - expect_string(__wrap_wm_task_manager_parse_data_result, status, status_result); - expect_string(__wrap_wm_task_manager_parse_data_result, error, error_result); - expect_value(__wrap_wm_task_manager_parse_data_result, create_time, create_time); - expect_value(__wrap_wm_task_manager_parse_data_result, last_update_time, last_update); - expect_string(__wrap_wm_task_manager_parse_data_result, request_command, command); - - cJSON *response = wm_task_manager_command_upgrade_result(task_parameters, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_result_not_found_err(void **state) -{ - int error_code = 0; - int agent_id = 35; - int task_id = OS_NOTFOUND; - - char *node_result = "node01"; - char *module_result = "upgrade_module"; - char *command_result = "upgrade"; - char *status_result = "In progress"; - char *error_result = "Error string"; - int create_time = 789456123; - int last_update = 987654321; - - char *wdb_response = "ok {\"error\":-2}"; - - wm_task_manager_upgrade_result *task_parameters = wm_task_manager_init_upgrade_result_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - task_parameters->agent_ids = agents; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_result {\"agent\":35}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_DATABASE_NO_TASK); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_command_upgrade_result(task_parameters, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_result_db_err(void **state) -{ - int error_code = 0; - int agent_id = 35; - int task_id = OS_INVALID; - - char *wdb_response = "ok {\"error\":-1}"; - - wm_task_manager_upgrade_result *task_parameters = wm_task_manager_init_upgrade_result_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - task_parameters->agent_ids = agents; - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_result {\"agent\":35}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - cJSON *response = wm_task_manager_command_upgrade_result(task_parameters, &error_code); - - state[0] = NULL; - state[1] = task_parameters; - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_result_db_response_null(void **state) -{ - int error_code = 0; - int agent_id = 35; - int task_id = OS_INVALID; - - wm_task_manager_upgrade_result *task_parameters = wm_task_manager_init_upgrade_result_parameters(); - int *agents = NULL; - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - task_parameters->agent_ids = agents; - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_result {\"agent\":35}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, NULL); - will_return(__wrap_wdbc_query_ex, OS_INVALID); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8209): Tasks DB Cannot execute SQL query: err database 'queue/tasks/tasks.db'"); - - cJSON *response = wm_task_manager_command_upgrade_result(task_parameters, &error_code); - - state[0] = NULL; - state[1] = task_parameters; - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_command_upgrade_cancel_tasks_ok(void **state) -{ - char *node = "node02"; - int error_code = 0; - - char *wdb_response = "ok {\"error\":0}"; - - wm_task_manager_upgrade_cancel_tasks *task_parameters = wm_task_manager_init_upgrade_cancel_tasks_parameters(); - - os_strdup(node, task_parameters->node); - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_cancel_tasks {\"node\":\"node02\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, OS_INVALID); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_command_upgrade_cancel_tasks(task_parameters, &error_code); - - state[0] = response; - state[1] = task_parameters; - - assert_non_null(response); - assert_memory_equal(response, res, sizeof(response)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_command_upgrade_cancel_tasks_db_err(void **state) -{ - char *node = "node02"; - int error_code = 0; - - char *wdb_response = "ok {\"error\":-1}"; - - wm_task_manager_upgrade_cancel_tasks *task_parameters = wm_task_manager_init_upgrade_cancel_tasks_parameters(); - - os_strdup(node, task_parameters->node); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_cancel_tasks {\"node\":\"node02\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - cJSON *response = wm_task_manager_command_upgrade_cancel_tasks(task_parameters, &error_code); - - state[0] = NULL; - state[1] = task_parameters; - - assert_int_equal(error_code, WM_TASK_DATABASE_ERROR); -} - -void test_wm_task_manager_process_task_upgrade_ok(void **state) -{ - int error_code = 0; - char *command = "upgrade"; - char *node = "node02"; - char *module = "upgrade_module"; - int agent_id1 = 45; - int agent_id2 = 49; - int *agents = NULL; - int task_id1 = 38; - int task_id2 = 39; - - char *wdb_response1 = "ok {\"error\":0,\"task_id\":38}"; - char *wdb_response2 = "ok {\"error\":0,\"task_id\":39}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - - os_calloc(3, sizeof(int), agents); - agents[0] = agent_id1; - agents[1] = agent_id2; - agents[2] = OS_INVALID; - - os_strdup(module, task_parameters->module); - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE; - task->parameters = task_parameters; - - cJSON* res1 = cJSON_CreateObject(); - cJSON* res2 = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":45,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response1); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response1); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id1); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id1); - will_return(__wrap_wm_task_manager_parse_data_response, res1); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade {\"agent\":49,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response2); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response2); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id2); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id2); - will_return(__wrap_wm_task_manager_parse_data_response, res2); - - cJSON *response = wm_task_manager_process_task(task, &error_code); - - state[0] = response; - state[1] = task; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 2); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res1, sizeof(res1)); - assert_memory_equal(cJSON_GetArrayItem(response, 1), res2, sizeof(res2)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_process_task_upgrade_custom_ok(void **state) -{ - int error_code = 0; - char *command = "upgrade_custom"; - char *node = "node02"; - char *module = "upgrade_module"; - int agent_id1 = 45; - int agent_id2 = 49; - int *agents = NULL; - int task_id1 = 38; - int task_id2 = 39; - - char *wdb_response1 = "ok {\"error\":0,\"task_id\":38}"; - char *wdb_response2 = "ok {\"error\":0,\"task_id\":39}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade *task_parameters = wm_task_manager_init_upgrade_parameters(); - - os_calloc(3, sizeof(int), agents); - agents[0] = agent_id1; - agents[1] = agent_id2; - agents[2] = OS_INVALID; - - os_strdup(module, task_parameters->module); - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE_CUSTOM; - task->parameters = task_parameters; - - cJSON* res1 = cJSON_CreateObject(); - cJSON* res2 = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_custom {\"agent\":45,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response1); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response1); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id1); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id1); - will_return(__wrap_wm_task_manager_parse_data_response, res1); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_custom {\"agent\":49,\"node\":\"node02\",\"module\":\"upgrade_module\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response2); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response2); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id2); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id2); - will_return(__wrap_wm_task_manager_parse_data_response, res2); - - cJSON *response = wm_task_manager_process_task(task, &error_code); - - state[0] = response; - state[1] = task; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 2); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res1, sizeof(res1)); - assert_memory_equal(cJSON_GetArrayItem(response, 1), res2, sizeof(res2)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_process_task_upgrade_get_status_ok(void **state) -{ - int error_code = 0; - char *node = "node02"; - int agent_id = 45; - int *agents = NULL; - char *status_result = "In progress"; - - char *wdb_response = "ok {\"error\":0,\"status\":\"In progress\"}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade_get_status *task_parameters = wm_task_manager_init_upgrade_get_status_parameters(); - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE_GET_STATUS; - task->parameters = task_parameters; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_get_status {\"agent\":45,\"node\":\"node02\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - expect_string(__wrap_wm_task_manager_parse_data_response, status, status_result); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_process_task(task, &error_code); - - state[0] = response; - state[1] = task; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_process_task_upgrade_update_status_ok(void **state) -{ - int error_code = 0; - char *node = "node02"; - int agent_id = 45; - int *agents = NULL; - char *status = "Failed"; - char *error = "Error message"; - - char *wdb_response = "ok {\"error\":0}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade_update_status *task_parameters = wm_task_manager_init_upgrade_update_status_parameters(); - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - os_strdup(node, task_parameters->node); - task_parameters->agent_ids = agents; - os_strdup(status, task_parameters->status); - os_strdup(error, task_parameters->error_msg); - - task->command = WM_TASK_UPGRADE_UPDATE_STATUS; - task->parameters = task_parameters; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_update_status {\"agent\":45,\"node\":\"node02\",\"status\":\"Failed\",\"error_msg\":\"Error message\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_process_task(task, &error_code); - - state[0] = response; - state[1] = task; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_process_task_upgrade_result_ok(void **state) -{ - int error_code = 0; - char *command = "upgrade_result"; - int agent_id = 45; - int *agents = NULL; - int task_id = 38; - - char *node_result = "node01"; - char *module_result = "api"; - char *command_result = "upgrade"; - char *status_result = "Updating"; - char *error_result = "Error string"; - int create_time = 789456123; - int last_update = 987654321; - - char *wdb_response = "ok {\"error\":0,\"task_id\":38,\"node\":\"node01\",\"module\":\"api\",\"command\":\"upgrade\",\"create_time\":789456123,\"update_time\":987654321,\"status\":\"Updating\",\"error_msg\":\"Error string\"}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade_result *task_parameters = wm_task_manager_init_upgrade_result_parameters(); - - os_calloc(2, sizeof(int), agents); - agents[0] = agent_id; - agents[1] = OS_INVALID; - - task_parameters->agent_ids = agents; - - task->command = WM_TASK_UPGRADE_RESULT; - task->parameters = task_parameters; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_result {\"agent\":45}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, agent_id); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, task_id); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - expect_string(__wrap_wm_task_manager_parse_data_result, node, node_result); - expect_string(__wrap_wm_task_manager_parse_data_result, module, module_result); - expect_string(__wrap_wm_task_manager_parse_data_result, command, command_result); - expect_string(__wrap_wm_task_manager_parse_data_result, status, status_result); - expect_string(__wrap_wm_task_manager_parse_data_result, error, error_result); - expect_value(__wrap_wm_task_manager_parse_data_result, create_time, create_time); - expect_value(__wrap_wm_task_manager_parse_data_result, last_update_time, last_update); - expect_string(__wrap_wm_task_manager_parse_data_result, request_command, command); - - cJSON *response = wm_task_manager_process_task(task, &error_code); - - state[0] = response; - state[1] = task; - - assert_non_null(response); - assert_int_equal(cJSON_GetArraySize(response), 1); - assert_memory_equal(cJSON_GetArrayItem(response, 0), res, sizeof(res)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_process_task_upgrade_cancel_tasks_ok(void **state) -{ - int error_code = 0; - char *node = "node02"; - - char *wdb_response = "ok {\"error\":0}"; - - wm_task_manager_task *task = wm_task_manager_init_task(); - wm_task_manager_upgrade_cancel_tasks *task_parameters = wm_task_manager_init_upgrade_cancel_tasks_parameters(); - - os_strdup(node, task_parameters->node); - - task->command = WM_TASK_UPGRADE_CANCEL_TASKS; - task->parameters = task_parameters; - - cJSON* res = cJSON_CreateObject(); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task upgrade_cancel_tasks {\"node\":\"node02\"}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wm_task_manager_parse_data_response, error_code, WM_TASK_SUCCESS); - expect_value(__wrap_wm_task_manager_parse_data_response, agent_id, OS_INVALID); - expect_value(__wrap_wm_task_manager_parse_data_response, task_id, OS_INVALID); - will_return(__wrap_wm_task_manager_parse_data_response, res); - - cJSON *response = wm_task_manager_process_task(task, &error_code); - - state[0] = response; - state[1] = task; - - assert_non_null(response); - assert_memory_equal(response, res, sizeof(response)); - assert_int_equal(error_code, 0); -} - -void test_wm_task_manager_process_task_command_err(void **state) -{ - int error_code = 0; - command_list command = WM_TASK_UNKNOWN; - - wm_task_manager_task *task = wm_task_manager_init_task(); - - task->command = command; - - cJSON *response = wm_task_manager_process_task(task, &error_code); - - state[0] = response; - state[1] = task; - - assert_null(response); - assert_int_equal(error_code, WM_TASK_INVALID_COMMAND); -} - -void test_wm_task_manager_clean_tasks(void **state) -{ - wm_task_manager *config = *state; - - config->cleanup_time = 1000; - config->task_timeout = 850; - - int now = 123456789; - - char *wdb_response1 = "ok {\"error\":0,\"timestamp\":123457639}"; - char *wdb_response2 = "ok {\"error\":0}"; - - will_return(__wrap_time, now); - - will_return(__wrap_time, now); - - will_return(__wrap_time, now); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task set_timeout {\"now\":123456789,\"interval\":850}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response1); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response1); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task delete_old {\"timestamp\":123455789}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response1); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response1); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - wm_task_manager_clean_tasks(config); - - assert_int_equal(current_time, now + config->task_timeout); -} - -void test_wm_task_manager_clean_tasks_timeout(void **state) -{ - wm_task_manager *config = *state; - - config->cleanup_time = 1000; - config->task_timeout = 850; - - int now = 123456789; - - char *wdb_response = "ok {\"error\":0,\"timestamp\":123457639}"; - - will_return(__wrap_time, now + 100); - - will_return(__wrap_time, now); - - will_return(__wrap_time, now); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task set_timeout {\"now\":123456789,\"interval\":850}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - wm_task_manager_clean_tasks(config); - - assert_int_equal(current_time, now + 100); -} - -void test_wm_task_manager_clean_tasks_clean(void **state) -{ - wm_task_manager *config = *state; - - config->cleanup_time = 1000; - config->task_timeout = 850; - - int now = 123456789; - - char *wdb_response = "ok {\"error\":0}"; - - will_return(__wrap_time, now); - - will_return(__wrap_time, now + 200); - - will_return(__wrap_time, now); - - expect_value(__wrap_wdbc_query_ex, *sock, -1); - expect_string(__wrap_wdbc_query_ex, query, "task delete_old {\"timestamp\":123455789}"); - expect_value(__wrap_wdbc_query_ex, len, OS_MAXSTR); - will_return(__wrap_wdbc_query_ex, wdb_response); - will_return(__wrap_wdbc_query_ex, 0); - - expect_string(__wrap_wdbc_parse_result, result, wdb_response); - will_return(__wrap_wdbc_parse_result, WDBC_OK); - - wm_task_manager_clean_tasks(config); - - assert_int_equal(current_time, now + 200); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_task_manager_send_message_to_wdb - cmocka_unit_test_teardown(test_wm_task_manager_send_message_to_wdb_ok, teardown_jsons), - cmocka_unit_test_teardown(test_wm_task_manager_send_message_to_wdb_parse_err, teardown_jsons), - cmocka_unit_test_teardown(test_wm_task_manager_send_message_to_wdb_request_err, teardown_jsons), - cmocka_unit_test_teardown(test_wm_task_manager_send_message_to_wdb_response_err, teardown_jsons), - // wm_task_manager_command_upgrade - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_ok, teardown_json_upgrade_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_custom_ok, teardown_json_upgrade_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_db_err, teardown_json_upgrade_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_db_response_null, teardown_json_upgrade_task), - // wm_task_manager_command_upgrade_get_status - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_get_status_ok, teardown_json_upgrade_get_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_get_status_db_err, teardown_json_upgrade_get_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_get_status_db_response_null, teardown_json_upgrade_get_status_task), - // wm_task_manager_command_upgrade_update_status - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_update_status_ok, teardown_json_upgrade_update_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_update_status_task_err, teardown_json_upgrade_update_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_update_status_db_err, teardown_json_upgrade_update_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_update_status_db_response_null, teardown_json_upgrade_update_status_task), - // wm_task_manager_command_upgrade_result - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_result_ok, teardown_json_upgrade_result_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_result_not_found_err, teardown_json_upgrade_result_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_result_db_err, teardown_json_upgrade_result_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_result_db_response_null, teardown_json_upgrade_result_task), - // wm_task_manager_command_upgrade_cancel_tasks - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_cancel_tasks_ok, teardown_json_upgrade_cancel_tasks_task), - cmocka_unit_test_teardown(test_wm_task_manager_command_upgrade_cancel_tasks_db_err, teardown_json_upgrade_cancel_tasks_task), - // wm_task_manager_process_task - cmocka_unit_test_teardown(test_wm_task_manager_process_task_upgrade_ok, teardown_json_task), - cmocka_unit_test_teardown(test_wm_task_manager_process_task_upgrade_custom_ok, teardown_json_task), - cmocka_unit_test_teardown(test_wm_task_manager_process_task_upgrade_get_status_ok, teardown_json_task), - cmocka_unit_test_teardown(test_wm_task_manager_process_task_upgrade_update_status_ok, teardown_json_task), - cmocka_unit_test_teardown(test_wm_task_manager_process_task_upgrade_result_ok, teardown_json_task), - cmocka_unit_test_teardown(test_wm_task_manager_process_task_upgrade_cancel_tasks_ok, teardown_json_task), - cmocka_unit_test_teardown(test_wm_task_manager_process_task_command_err, teardown_json_task), - // wm_task_manager_clean_tasks - cmocka_unit_test_setup_teardown(test_wm_task_manager_clean_tasks, setup_config, teardown_config), - cmocka_unit_test_setup_teardown(test_wm_task_manager_clean_tasks_timeout, setup_config, teardown_config), - cmocka_unit_test_setup_teardown(test_wm_task_manager_clean_tasks_clean, setup_config, teardown_config) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager_parsing.c b/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager_parsing.c deleted file mode 100644 index 73c7dd1b352..00000000000 --- a/src/unit_tests/wazuh_modules/task_manager/test_wm_task_manager_parsing.c +++ /dev/null @@ -1,1425 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - */ - -#include -#include -#include -#include -#include - -#include "../../wrappers/wazuh/shared/debug_op_wrappers.h" -#include "../../wrappers/wazuh/shared/time_op_wrappers.h" - -#include "../../wazuh_modules/wmodules.h" -#include "../../wazuh_modules/task_manager/wm_task_manager_parsing.h" -#include "../../wazuh_modules/task_manager/wm_task_manager_tasks.h" -#include "../../headers/shared.h" - -int* wm_task_manager_parse_ids(const cJSON* ids); -wm_task_manager_upgrade* wm_task_manager_parse_upgrade_parameters(const cJSON* origin, const cJSON* parameters); -wm_task_manager_upgrade_get_status* wm_task_manager_parse_upgrade_get_status_parameters(const cJSON* origin, const cJSON* parameters); -wm_task_manager_upgrade_update_status* wm_task_manager_parse_upgrade_update_status_parameters(const cJSON* origin, const cJSON* parameters); -wm_task_manager_upgrade_result* wm_task_manager_parse_upgrade_result_parameters(const cJSON* parameters); -wm_task_manager_upgrade_cancel_tasks* wm_task_manager_parse_upgrade_cancel_tasks_parameters(const cJSON* origin); -const char* wm_task_manager_decode_status(char *status); - -// Setup / teardown - -static int teardown_json(void **state) { - if (*state) { - cJSON *json = *state; - cJSON_Delete(json); - } - return 0; -} - -static int teardown_task(void **state) { - if (state[0]) { - wm_task_manager_task *task = (wm_task_manager_task*)state[0]; - wm_task_manager_free_task(task); - } - return 0; -} - -static int teardown_json_array(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - int *array = (int*)state[1]; - os_free(array); - } - return 0; -} - -static int teardown_json_upgrade_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade *task = (wm_task_manager_upgrade*)state[1]; - wm_task_manager_free_upgrade_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_get_status_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_get_status *task = (wm_task_manager_upgrade_get_status*)state[1]; - wm_task_manager_free_upgrade_get_status_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_update_status_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_update_status *task = (wm_task_manager_upgrade_update_status*)state[1]; - wm_task_manager_free_upgrade_update_status_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_result_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_result *task = (wm_task_manager_upgrade_result*)state[1]; - wm_task_manager_free_upgrade_result_parameters(task); - } - return 0; -} - -static int teardown_json_upgrade_cancel_tasks_task(void **state) { - if (state[0]) { - cJSON *json = state[0]; - cJSON_Delete(json); - } - if (state[1]) { - wm_task_manager_upgrade_cancel_tasks *task = (wm_task_manager_upgrade_cancel_tasks*)state[1]; - wm_task_manager_free_upgrade_cancel_tasks_parameters(task); - } - return 0; -} - -// Tests - -void test_wm_task_manager_decode_status_done(void **state) -{ - char *status = "Done"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_string_equal(ret, "Updated"); -} - -void test_wm_task_manager_decode_status_pending(void **state) -{ - char *status = "Pending"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_string_equal(ret, "In queue"); -} - -void test_wm_task_manager_decode_status_in_progress(void **state) -{ - char *status = "In progress"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_string_equal(ret, "Updating"); -} - -void test_wm_task_manager_decode_status_failed(void **state) -{ - char *status = "Failed"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_string_equal(ret, "Error"); -} - -void test_wm_task_manager_decode_status_cancelled(void **state) -{ - char *status = "Cancelled"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_string_equal(ret, "Task cancelled since the manager was restarted"); -} - -void test_wm_task_manager_decode_status_timeout(void **state) -{ - char *status = "Timeout"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_string_equal(ret, "Timeout reached while waiting for the response from the agent, check the result manually on the agent for more information"); -} - -void test_wm_task_manager_decode_status_legacy(void **state) -{ - char *status = "Legacy"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_string_equal(ret, "Legacy upgrade: check the result manually since the agent cannot report the result of the task"); -} - -void test_wm_task_manager_decode_status_unknown(void **state) -{ - char *status = "No status"; - - const char *ret = wm_task_manager_decode_status(status); - - assert_null(ret); -} - -void test_wm_task_manager_parse_data_response(void **state) -{ - int error_code = 0; - int agent_id = 77; - int task_id = 124; - char *status = "In progress"; - - cJSON *response = wm_task_manager_parse_data_response(error_code, agent_id, task_id, status); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(response, "agent")); - assert_int_equal(cJSON_GetObjectItem(response, "agent")->valueint, agent_id); - assert_non_null(cJSON_GetObjectItem(response, "task_id")); - assert_int_equal(cJSON_GetObjectItem(response, "task_id")->valueint, task_id); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); -} - -void test_wm_task_manager_parse_data_response_no_status(void **state) -{ - int error_code = 0; - int agent_id = 77; - int task_id = 124; - char *status = NULL; - - cJSON *response = wm_task_manager_parse_data_response(error_code, agent_id, task_id, status); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(response, "agent")); - assert_int_equal(cJSON_GetObjectItem(response, "agent")->valueint, agent_id); - assert_non_null(cJSON_GetObjectItem(response, "task_id")); - assert_int_equal(cJSON_GetObjectItem(response, "task_id")->valueint, task_id); - assert_null(cJSON_GetObjectItem(response, "status")); -} - -void test_wm_task_manager_parse_data_response_no_task_id(void **state) -{ - int error_code = 0; - int agent_id = 77; - int task_id = OS_INVALID; - char *status = "In progress"; - - cJSON *response = wm_task_manager_parse_data_response(error_code, agent_id, task_id, status); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(response, "agent")); - assert_int_equal(cJSON_GetObjectItem(response, "agent")->valueint, agent_id); - assert_null(cJSON_GetObjectItem(response, "task_id")); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); -} - -void test_wm_task_manager_parse_data_response_no_agent_id(void **state) -{ - int error_code = 0; - int agent_id = OS_INVALID; - int task_id = 124; - char *status = "In progress"; - - cJSON *response = wm_task_manager_parse_data_response(error_code, agent_id, task_id, status); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_null(cJSON_GetObjectItem(response, "agent")); - assert_non_null(cJSON_GetObjectItem(response, "task_id")); - assert_int_equal(cJSON_GetObjectItem(response, "task_id")->valueint, task_id); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); -} - -void test_wm_task_manager_parse_data_result(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = "api"; - char *command = "task"; - char *status = "In progress"; - char *error = "Error message"; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = 234567890; - char *last_update_timestamp = NULL; - char *req_command = "task_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - os_strdup("5/5/20 12:55:18.789", last_update_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, last_update); - will_return(__wrap_w_get_timestamp, last_update_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, error, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); - assert_non_null(cJSON_GetObjectItem(response, "error_msg")); - assert_string_equal(cJSON_GetObjectItem(response, "error_msg")->valuestring, error); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_non_null(cJSON_GetObjectItem(response, "update_time")); - assert_string_equal(cJSON_GetObjectItem(response, "update_time")->valuestring, "5/5/20 12:55:18.789"); -} - -void test_wm_task_manager_parse_data_result_last_update_0(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = "api"; - char *command = "task"; - char *status = "In progress"; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = 0; - char *req_command = "task_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_null(cJSON_GetObjectItem(response, "update_time")); -} - -void test_wm_task_manager_parse_data_result_no_last_update(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = "api"; - char *command = "task"; - char *status = "In progress"; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = OS_INVALID; - char *req_command = "task_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_null(cJSON_GetObjectItem(response, "update_time")); -} - -void test_wm_task_manager_parse_data_result_no_create_time(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = "api"; - char *command = "task"; - char *status = "In progress"; - int create_time = OS_INVALID; - int last_update = 234567890; - char *last_update_timestamp = NULL; - char *req_command = "task_result"; - - os_strdup("5/5/20 12:55:18.789", last_update_timestamp); - - expect_value(__wrap_w_get_timestamp, time, last_update); - will_return(__wrap_w_get_timestamp, last_update_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_null(cJSON_GetObjectItem(response, "create_time")); - assert_non_null(cJSON_GetObjectItem(response, "update_time")); - assert_string_equal(cJSON_GetObjectItem(response, "update_time")->valuestring, "5/5/20 12:55:18.789"); -} - -void test_wm_task_manager_parse_data_result_status_upgrade_result(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = "Legacy"; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = 234567890; - char *last_update_timestamp = NULL; - char *req_command = "upgrade_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - os_strdup("5/5/20 12:55:18.789", last_update_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, last_update); - will_return(__wrap_w_get_timestamp, last_update_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, "Legacy upgrade: check the result manually since the agent cannot report the result of the task"); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_non_null(cJSON_GetObjectItem(response, "update_time")); - assert_string_equal(cJSON_GetObjectItem(response, "update_time")->valuestring, "5/5/20 12:55:18.789"); -} - -void test_wm_task_manager_parse_data_result_no_status(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = "upgrade_module"; - char *command = "upgrade"; - char *status = NULL; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = 234567890; - char *last_update_timestamp = NULL; - char *req_command = "upgrade_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - os_strdup("5/5/20 12:55:18.789", last_update_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, last_update); - will_return(__wrap_w_get_timestamp, last_update_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_null(cJSON_GetObjectItem(response, "status")); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_non_null(cJSON_GetObjectItem(response, "update_time")); - assert_string_equal(cJSON_GetObjectItem(response, "update_time")->valuestring, "5/5/20 12:55:18.789"); -} - -void test_wm_task_manager_parse_data_result_no_command(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = "api"; - char *command = NULL; - char *status = "In progress"; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = 234567890; - char *last_update_timestamp = NULL; - char *req_command = "task_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - os_strdup("5/5/20 12:55:18.789", last_update_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, last_update); - will_return(__wrap_w_get_timestamp, last_update_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_null(cJSON_GetObjectItem(response, "command")); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_non_null(cJSON_GetObjectItem(response, "update_time")); - assert_string_equal(cJSON_GetObjectItem(response, "update_time")->valuestring, "5/5/20 12:55:18.789"); -} - -void test_wm_task_manager_parse_data_result_no_module(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = "node04"; - char *module = NULL; - char *command = "task"; - char *status = "In progress"; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = 234567890; - char *last_update_timestamp = NULL; - char *req_command = "task_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - os_strdup("5/5/20 12:55:18.789", last_update_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, last_update); - will_return(__wrap_w_get_timestamp, last_update_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_non_null(cJSON_GetObjectItem(response, "node")); - assert_string_equal(cJSON_GetObjectItem(response, "node")->valuestring, node); - assert_null(cJSON_GetObjectItem(response, "module")); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_non_null(cJSON_GetObjectItem(response, "update_time")); - assert_string_equal(cJSON_GetObjectItem(response, "update_time")->valuestring, "5/5/20 12:55:18.789"); -} - -void test_wm_task_manager_parse_data_result_no_node(void **state) -{ - cJSON *response = cJSON_CreateObject(); - - char *node = NULL; - char *module = "api"; - char *command = "task"; - char *status = "In progress"; - int create_time = 123456789; - char *create_time_timestamp = NULL; - int last_update = 234567890; - char *last_update_timestamp = NULL; - char *req_command = "task_result"; - - os_strdup("5/5/20 12:30:55.666", create_time_timestamp); - os_strdup("5/5/20 12:55:18.789", last_update_timestamp); - - expect_value(__wrap_w_get_timestamp, time, create_time); - will_return(__wrap_w_get_timestamp, create_time_timestamp); - - expect_value(__wrap_w_get_timestamp, time, last_update); - will_return(__wrap_w_get_timestamp, last_update_timestamp); - - wm_task_manager_parse_data_result(response, node, module, command, status, NULL, create_time, last_update, req_command); - - *state = response; - - assert_non_null(response); - assert_null(cJSON_GetObjectItem(response, "node")); - assert_non_null(cJSON_GetObjectItem(response, "module")); - assert_string_equal(cJSON_GetObjectItem(response, "module")->valuestring, module); - assert_non_null(cJSON_GetObjectItem(response, "command")); - assert_string_equal(cJSON_GetObjectItem(response, "command")->valuestring, command); - assert_non_null(cJSON_GetObjectItem(response, "status")); - assert_string_equal(cJSON_GetObjectItem(response, "status")->valuestring, status); - assert_null(cJSON_GetObjectItem(response, "error_msg")); - assert_non_null(cJSON_GetObjectItem(response, "create_time")); - assert_string_equal(cJSON_GetObjectItem(response, "create_time")->valuestring, "5/5/20 12:30:55.666"); - assert_non_null(cJSON_GetObjectItem(response, "update_time")); - assert_string_equal(cJSON_GetObjectItem(response, "update_time")->valuestring, "5/5/20 12:55:18.789"); -} - -void test_wm_task_manager_parse_response_data_array(void **state) -{ - int error_code = 0; - cJSON *data = cJSON_CreateArray(); - - cJSON *response = wm_task_manager_parse_response(error_code, data); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(response, "data")); - assert_memory_equal(cJSON_GetObjectItem(response, "data"), data, sizeof(data)); -} - -void test_wm_task_manager_parse_response_data_object(void **state) -{ - int error_code = 0; - cJSON *data = cJSON_CreateObject(); - - cJSON *response = wm_task_manager_parse_response(error_code, data); - - *state = response; - - assert_non_null(cJSON_GetObjectItem(response, "error")); - assert_int_equal(cJSON_GetObjectItem(response, "error")->valueint, error_code); - assert_non_null(cJSON_GetObjectItem(response, "message")); - assert_string_equal(cJSON_GetObjectItem(response, "message")->valuestring, "Success"); - assert_non_null(cJSON_GetObjectItem(response, "data")); - assert_memory_equal(cJSON_GetArrayItem(cJSON_GetObjectItem(response, "data"), 0), data, sizeof(data)); -} - -void test_wm_task_manager_parse_upgrade_cancel_tasks_parameters_ok(void **state) -{ - cJSON *origin = cJSON_CreateObject(); - - cJSON_AddStringToObject(origin, "name", "node01"); - - wm_task_manager_upgrade_cancel_tasks* upgrade_cancel_result = wm_task_manager_parse_upgrade_cancel_tasks_parameters(origin); - - state[0] = origin; - state[1] = upgrade_cancel_result; - - assert_non_null(upgrade_cancel_result); - assert_non_null(upgrade_cancel_result->node); - assert_string_equal(upgrade_cancel_result->node, "node01"); -} - -void test_wm_task_manager_parse_upgrade_cancel_tasks_parameters_node_err(void **state) -{ - cJSON *origin = cJSON_CreateObject(); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'name' not found."); - - wm_task_manager_upgrade_cancel_tasks* upgrade_cancel_result = wm_task_manager_parse_upgrade_cancel_tasks_parameters(origin); - - state[0] = origin; - state[1] = upgrade_cancel_result; - - assert_null(upgrade_cancel_result); -} - -void test_wm_task_manager_parse_upgrade_result_parameters_ok(void **state) -{ - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddItemToArray(agents, cJSON_CreateNumber(65)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(70)); - - cJSON_AddItemToObject(parameters, "agents", agents); - - wm_task_manager_upgrade_result* upgrade_result = wm_task_manager_parse_upgrade_result_parameters(parameters); - - state[0] = parameters; - state[1] = upgrade_result; - - assert_non_null(upgrade_result); - assert_non_null(upgrade_result->agent_ids); - assert_int_equal(upgrade_result->agent_ids[0], 65); - assert_int_equal(upgrade_result->agent_ids[1], 70); - assert_int_equal(upgrade_result->agent_ids[2], OS_INVALID); -} - -void test_wm_task_manager_parse_upgrade_result_parameters_agents_err(void **state) -{ - cJSON *parameters = cJSON_CreateObject(); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'agents' not found."); - - wm_task_manager_upgrade_result* upgrade_result = wm_task_manager_parse_upgrade_result_parameters(parameters); - - state[0] = parameters; - state[1] = upgrade_result; - - assert_null(upgrade_result); -} - -void test_wm_task_manager_parse_upgrade_update_status_parameters_ok(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "name", "node01"); - - cJSON_AddStringToObject(parameters, "status", "Failed"); - cJSON_AddStringToObject(parameters, "error_msg", "SHA1 error"); - - cJSON_AddItemToArray(agents, cJSON_CreateNumber(65)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(70)); - - cJSON_AddItemToObject(parameters, "agents", agents); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - wm_task_manager_upgrade_update_status* upgrade_update_status = wm_task_manager_parse_upgrade_update_status_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade_update_status; - - assert_non_null(upgrade_update_status); - assert_non_null(upgrade_update_status->node); - assert_string_equal(upgrade_update_status->node, "node01"); - assert_non_null(upgrade_update_status->status); - assert_string_equal(upgrade_update_status->status, "Failed"); - assert_non_null(upgrade_update_status->error_msg); - assert_string_equal(upgrade_update_status->error_msg, "SHA1 error"); - assert_non_null(upgrade_update_status->agent_ids); - assert_int_equal(upgrade_update_status->agent_ids[0], 65); - assert_int_equal(upgrade_update_status->agent_ids[1], 70); - assert_int_equal(upgrade_update_status->agent_ids[2], OS_INVALID); -} - -void test_wm_task_manager_parse_upgrade_update_status_parameters_agents_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(origin, "name", "node01"); - - cJSON_AddStringToObject(parameters, "status", "Done"); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'agents' not found."); - - wm_task_manager_upgrade_update_status* upgrade_update_status = wm_task_manager_parse_upgrade_update_status_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade_update_status; - - assert_null(upgrade_update_status); -} - -void test_wm_task_manager_parse_upgrade_update_status_parameters_status_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(origin, "name", "node01"); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'status' not found."); - - wm_task_manager_upgrade_update_status* upgrade_update_status = wm_task_manager_parse_upgrade_update_status_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade_update_status; - - assert_null(upgrade_update_status); -} - -void test_wm_task_manager_parse_upgrade_update_status_parameters_node_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'name' not found."); - - wm_task_manager_upgrade_update_status* upgrade_update_status = wm_task_manager_parse_upgrade_update_status_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade_update_status; - - assert_null(upgrade_update_status); -} - -void test_wm_task_manager_parse_upgrade_get_status_parameters_ok(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "name", "node01"); - - cJSON_AddItemToArray(agents, cJSON_CreateNumber(65)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(70)); - - cJSON_AddItemToObject(parameters, "agents", agents); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - wm_task_manager_upgrade_get_status* upgrade_get_status = wm_task_manager_parse_upgrade_get_status_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade_get_status; - - assert_non_null(upgrade_get_status); - assert_non_null(upgrade_get_status->node); - assert_string_equal(upgrade_get_status->node, "node01"); - assert_non_null(upgrade_get_status->agent_ids); - assert_int_equal(upgrade_get_status->agent_ids[0], 65); - assert_int_equal(upgrade_get_status->agent_ids[1], 70); - assert_int_equal(upgrade_get_status->agent_ids[2], OS_INVALID); -} - -void test_wm_task_manager_parse_upgrade_get_status_parameters_agents_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(origin, "name", "node01"); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'agents' not found."); - - wm_task_manager_upgrade_get_status* upgrade_get_status = wm_task_manager_parse_upgrade_get_status_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade_get_status; - - assert_null(upgrade_get_status); -} - -void test_wm_task_manager_parse_upgrade_get_status_parameters_node_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'name' not found."); - - wm_task_manager_upgrade_get_status* upgrade_get_status = wm_task_manager_parse_upgrade_get_status_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade_get_status; - - assert_null(upgrade_get_status); -} - -void test_wm_task_manager_parse_upgrade_parameters_ok(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddStringToObject(origin, "name", "node01"); - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - - cJSON_AddItemToArray(agents, cJSON_CreateNumber(65)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(70)); - - cJSON_AddItemToObject(parameters, "agents", agents); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - wm_task_manager_upgrade* upgrade = wm_task_manager_parse_upgrade_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade; - - assert_non_null(upgrade); - assert_non_null(upgrade->node); - assert_string_equal(upgrade->node, "node01"); - assert_non_null(upgrade->module); - assert_string_equal(upgrade->module, "upgrade_module"); - assert_non_null(upgrade->agent_ids); - assert_int_equal(upgrade->agent_ids[0], 65); - assert_int_equal(upgrade->agent_ids[1], 70); - assert_int_equal(upgrade->agent_ids[2], OS_INVALID); -} - -void test_wm_task_manager_parse_upgrade_parameters_agents_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(origin, "name", "node01"); - cJSON_AddStringToObject(origin, "module", "upgrade_module"); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'agents' not found."); - - wm_task_manager_upgrade* upgrade = wm_task_manager_parse_upgrade_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade; - - assert_null(upgrade); -} - -void test_wm_task_manager_parse_upgrade_parameters_module_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddStringToObject(origin, "name", "node01"); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'module' not found."); - - wm_task_manager_upgrade* upgrade = wm_task_manager_parse_upgrade_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade; - - assert_null(upgrade); -} - -void test_wm_task_manager_parse_upgrade_parameters_node_err(void **state) -{ - cJSON *event = cJSON_CreateObject(); - cJSON *origin = cJSON_CreateObject(); - cJSON *parameters = cJSON_CreateObject(); - - cJSON_AddItemToObject(event, "origin", origin); - cJSON_AddItemToObject(event, "parameters", parameters); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'name' not found."); - - wm_task_manager_upgrade* upgrade = wm_task_manager_parse_upgrade_parameters(origin, parameters); - - state[0] = event; - state[1] = upgrade; - - assert_null(upgrade); -} - -void test_wm_task_manager_parse_ids_ok(void **state) -{ - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddItemToArray(agents, cJSON_CreateNumber(5)); - cJSON_AddItemToArray(agents, cJSON_CreateNumber(78)); - - int *agents_array = wm_task_manager_parse_ids(agents); - - state[0] = agents; - state[1] = agents_array; - - assert_non_null(agents_array); - assert_int_equal(agents_array[0], 5); - assert_int_equal(agents_array[1], 78); - assert_int_equal(agents_array[2], OS_INVALID); -} - -void test_wm_task_manager_parse_ids_agents_type_err(void **state) -{ - cJSON *agents = cJSON_CreateArray(); - - cJSON_AddItemToArray(agents, cJSON_CreateNumber(5)); - cJSON_AddItemToArray(agents, cJSON_CreateString("78")); - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8260): Invalid element in array."); - - int *agents_array = wm_task_manager_parse_ids(agents); - - state[0] = agents; - state[1] = agents_array; - - assert_null(agents_array); -} - -void test_wm_task_manager_parse_ids_agents_empty_err(void **state) -{ - cJSON *agents = cJSON_CreateArray(); - - int *agents_array = wm_task_manager_parse_ids(agents); - - state[0] = agents; - state[1] = agents_array; - - assert_null(agents_array); -} - -void test_wm_task_manager_parse_message_upgrade(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - *state = task; - - assert_non_null(task); - assert_int_equal(task->command, WM_TASK_UPGRADE); - wm_task_manager_upgrade *parameters = (wm_task_manager_upgrade *)task->parameters; - assert_non_null(parameters->node); - assert_string_equal(parameters->node, "node05"); - assert_non_null(parameters->module); - assert_string_equal(parameters->module, "upgrade_module"); - assert_non_null(parameters->agent_ids); - assert_int_equal(parameters->agent_ids[0], 1); - assert_int_equal(parameters->agent_ids[1], 2); - assert_int_equal(parameters->agent_ids[2], -1); -} - -void test_wm_task_manager_parse_message_upgrade_custom(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade_custom\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - *state = task; - - assert_non_null(task); - assert_int_equal(task->command, WM_TASK_UPGRADE_CUSTOM); - wm_task_manager_upgrade *parameters = (wm_task_manager_upgrade *)task->parameters; - assert_non_null(parameters->node); - assert_string_equal(parameters->node, "node05"); - assert_non_null(parameters->module); - assert_string_equal(parameters->module, "upgrade_module"); - assert_non_null(parameters->agent_ids); - assert_int_equal(parameters->agent_ids[0], 1); - assert_int_equal(parameters->agent_ids[1], 2); - assert_int_equal(parameters->agent_ids[2], -1); -} - -void test_wm_task_manager_parse_message_upgrade_get_status(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade_get_status\"," - " \"parameters\": {" - " \"agents\": [1]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - *state = task; - - assert_non_null(task); - assert_int_equal(task->command, WM_TASK_UPGRADE_GET_STATUS); - wm_task_manager_upgrade_get_status *parameters = (wm_task_manager_upgrade_get_status *)task->parameters; - assert_non_null(parameters->node); - assert_string_equal(parameters->node, "node05"); - assert_non_null(parameters->agent_ids); - assert_int_equal(parameters->agent_ids[0], 1); - assert_int_equal(parameters->agent_ids[1], -1); -} - -void test_wm_task_manager_parse_message_upgrade_update_status(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade_update_status\"," - " \"parameters\": {" - " \"agents\": [1]," - " \"status\": \"Failed\"," - " \"error_msg\": \"SHA1 error\"" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - *state = task; - - assert_non_null(task); - assert_int_equal(task->command, WM_TASK_UPGRADE_UPDATE_STATUS); - wm_task_manager_upgrade_update_status *parameters = (wm_task_manager_upgrade_update_status *)task->parameters; - assert_non_null(parameters->node); - assert_string_equal(parameters->node, "node05"); - assert_non_null(parameters->agent_ids); - assert_int_equal(parameters->agent_ids[0], 1); - assert_int_equal(parameters->agent_ids[1], -1); - assert_non_null(parameters->status); - assert_string_equal(parameters->status, "Failed"); - assert_non_null(parameters->error_msg); - assert_string_equal(parameters->error_msg, "SHA1 error"); -} - -void test_wm_task_manager_parse_message_upgrade_result(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"api\"" - " }," - " \"command\": \"upgrade_result\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - *state = task; - - assert_non_null(task); - assert_int_equal(task->command, WM_TASK_UPGRADE_RESULT); - wm_task_manager_upgrade_result *parameters = (wm_task_manager_upgrade_result *)task->parameters; - assert_non_null(parameters->agent_ids); - assert_int_equal(parameters->agent_ids[0], 1); - assert_int_equal(parameters->agent_ids[1], 2); - assert_int_equal(parameters->agent_ids[2], -1); -} - -void test_wm_task_manager_parse_message_upgrade_cancel_tasks(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"api\"" - " }," - " \"command\": \"upgrade_cancel_tasks\"," - " \"parameters\": {" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - *state = task; - - assert_non_null(task); - assert_int_equal(task->command, WM_TASK_UPGRADE_CANCEL_TASKS); - wm_task_manager_upgrade_cancel_tasks *parameters = (wm_task_manager_upgrade_cancel_tasks *)task->parameters; - assert_non_null(parameters->node); - assert_string_equal(parameters->node, "node05"); -} - -void test_wm_task_manager_parse_message_unknown(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"api\"" - " }," - " \"command\": \"unknown\"," - " \"parameters\": {" - " }" - "}"; - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - *state = task; - - assert_non_null(task); - assert_int_equal(task->command, WM_TASK_UNKNOWN); - assert_null(task->parameters); -} - -void test_wm_task_manager_parse_message_command_parameters_err(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"," - " \"parameters\": {" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'agents' not found."); - - wm_task_manager_task *task = wm_task_manager_parse_message(message); -} - -void test_wm_task_manager_parse_message_command_err(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'command' not found."); - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - assert_null(task); -} - -void test_wm_task_manager_parse_message_origin_err(void **state) -{ - char *message = "{" - " \"command\": \"upgrade\"," - " \"parameters\": {" - " \"agents\": [1, 2]" - " }" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'origin' not found."); - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - assert_null(task); -} - -void test_wm_task_manager_parse_message_parameters_err(void **state) -{ - char *message = "{" - " \"origin\": {" - " \"name\": \"node05\"," - " \"module\": \"upgrade_module\"" - " }," - " \"command\": \"upgrade\"" - "}"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8259): Invalid message. 'parameters' not found."); - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - assert_null(task); -} - -void test_wm_task_manager_parse_message_invalid_json_err(void **state) -{ - char *message = "unknown json"; - - expect_string(__wrap__mterror, tag, "wazuh-modulesd:task-manager"); - expect_string(__wrap__mterror, formatted_msg, "(8257): Error parsing JSON event: 'unknown json'"); - - wm_task_manager_task *task = wm_task_manager_parse_message(message); - - assert_null(task); -} - -int main(void) { - const struct CMUnitTest tests[] = { - // wm_task_manager_decode_status - cmocka_unit_test(test_wm_task_manager_decode_status_done), - cmocka_unit_test(test_wm_task_manager_decode_status_pending), - cmocka_unit_test(test_wm_task_manager_decode_status_in_progress), - cmocka_unit_test(test_wm_task_manager_decode_status_failed), - cmocka_unit_test(test_wm_task_manager_decode_status_cancelled), - cmocka_unit_test(test_wm_task_manager_decode_status_timeout), - cmocka_unit_test(test_wm_task_manager_decode_status_legacy), - cmocka_unit_test(test_wm_task_manager_decode_status_unknown), - // wm_task_manager_parse_data_response - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_response, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_response_no_status, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_response_no_task_id, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_response_no_agent_id, teardown_json), - // wm_task_manager_parse_data_result - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_last_update_0, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_no_last_update, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_no_create_time, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_status_upgrade_result, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_no_status, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_no_command, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_no_module, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_data_result_no_node, teardown_json), - // wm_task_manager_parse_response - cmocka_unit_test_teardown(test_wm_task_manager_parse_response_data_array, teardown_json), - cmocka_unit_test_teardown(test_wm_task_manager_parse_response_data_object, teardown_json), - // wm_task_manager_parse_upgrade_cancel_tasks_parameters - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_cancel_tasks_parameters_ok, teardown_json_upgrade_cancel_tasks_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_cancel_tasks_parameters_node_err, teardown_json_upgrade_cancel_tasks_task), - // wm_task_manager_parse_upgrade_result_parameters - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_result_parameters_ok, teardown_json_upgrade_result_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_result_parameters_agents_err, teardown_json_upgrade_result_task), - // wm_task_manager_parse_upgrade_update_status_parameters - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_update_status_parameters_ok, teardown_json_upgrade_update_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_update_status_parameters_agents_err, teardown_json_upgrade_update_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_update_status_parameters_status_err, teardown_json_upgrade_update_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_update_status_parameters_node_err, teardown_json_upgrade_update_status_task), - // wm_task_manager_parse_upgrade_get_status_parameters - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_get_status_parameters_ok, teardown_json_upgrade_get_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_get_status_parameters_agents_err, teardown_json_upgrade_get_status_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_get_status_parameters_node_err, teardown_json_upgrade_get_status_task), - // wm_task_manager_parse_upgrade_parameters - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_parameters_ok, teardown_json_upgrade_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_parameters_agents_err, teardown_json_upgrade_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_parameters_module_err, teardown_json_upgrade_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_upgrade_parameters_node_err, teardown_json_upgrade_task), - // wm_task_manager_parse_ids - cmocka_unit_test_teardown(test_wm_task_manager_parse_ids_ok, teardown_json_array), - cmocka_unit_test_teardown(test_wm_task_manager_parse_ids_agents_type_err, teardown_json_array), - cmocka_unit_test_teardown(test_wm_task_manager_parse_ids_agents_empty_err, teardown_json_array), - // wm_task_manager_parse_message - cmocka_unit_test_teardown(test_wm_task_manager_parse_message_upgrade, teardown_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_message_upgrade_custom, teardown_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_message_upgrade_get_status, teardown_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_message_upgrade_update_status, teardown_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_message_upgrade_result, teardown_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_message_upgrade_cancel_tasks, teardown_task), - cmocka_unit_test_teardown(test_wm_task_manager_parse_message_unknown, teardown_task), - cmocka_unit_test(test_wm_task_manager_parse_message_command_parameters_err), - cmocka_unit_test(test_wm_task_manager_parse_message_command_err), - cmocka_unit_test(test_wm_task_manager_parse_message_origin_err), - cmocka_unit_test(test_wm_task_manager_parse_message_parameters_err), - cmocka_unit_test(test_wm_task_manager_parse_message_invalid_json_err) - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/src/unit_tests/wazuh_modules/wmodules/CMakeLists.txt b/src/unit_tests/wazuh_modules/wmodules/CMakeLists.txt deleted file mode 100644 index 51dd29841d9..00000000000 --- a/src/unit_tests/wazuh_modules/wmodules/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (C) 2015, Wazuh Inc. -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Generate wmodules library -file(GLOB wmodules_files - ${SRC_FOLDER}/wazuh_modules/*.o) -list(REMOVE_ITEM wmodules_files ${SRC_FOLDER}/wazuh_modules/main.o) - -add_library(WMODULES_O STATIC ${wmodules_files}) - -set_source_files_properties( - ${wmodules_files} - PROPERTIES - EXTERNAL_OBJECT true - GENERATED true -) - -set_target_properties( - WMODULES_O - PROPERTIES - LINKER_LANGUAGE C -) - -target_link_libraries(WMODULES_O ${WAZUHLIB} ${WAZUHEXT} -lpthread) - -#include wrappers -include(${SRC_FOLDER}/unit_tests/wrappers/wazuh/shared/shared.cmake) - -# Generate wmodules tests -list(APPEND wmodules_names "test_wmodules") -list(APPEND wmodules_flags " ") - -# Compilig tests -list(LENGTH wmodules_names count) -math(EXPR count "${count} - 1") -foreach(counter RANGE ${count}) - list(GET wmodules_names ${counter} test_name) - list(GET wmodules_flags ${counter} test_flags) - - add_executable(${test_name} ${test_name}.c) - - target_link_libraries( - ${test_name} - ${WAZUHLIB} - ${WAZUHEXT} - WMODULES_O - ${TEST_DEPS} - ) - - if(NOT test_flags STREQUAL " ") - target_link_libraries( - ${test_name} - ${test_flags} - ) - endif() - add_test(NAME ${test_name} COMMAND ${test_name}) -endforeach() diff --git a/src/unit_tests/wazuh_modules/wmodules/test_wmodules.c b/src/unit_tests/wazuh_modules/wmodules/test_wmodules.c deleted file mode 100644 index 21db17704cd..00000000000 --- a/src/unit_tests/wazuh_modules/wmodules/test_wmodules.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2015, Wazuh Inc. - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License (version 2) as published by the FSF - Free Software - * Foundation. - * - * Test corresponding to the wazuh-modulesd shared functions - */ - -#include -#include -#include -#include -#include - -#include "../../../wazuh_modules/wmodules.h" - -static size_t echo(void * module, char * query, char ** output) { - (void)module; - *output = strdup(query); - return strlen(query); -} - -static int setup_modules(void ** state) { - static wm_context CONTEXTS[] = { - { .name = "A", .query = echo }, - { .name = "B", .query = NULL }, - }; - - wmodules = calloc(1, sizeof(wmodule)); - wmodules->context = &CONTEXTS[0]; - wmodules->next = calloc(1, sizeof(wmodule)); - wmodules->next->context = &CONTEXTS[1]; - - *state = NULL; - return 0; -} - -static int teardown_modules(void ** state) { - free(*state); - free(wmodules->next); - free(wmodules); - - return 0; -} - -static void test_find_module_found(void ** state) { - (void)state; - - wmodule * m = wm_find_module("A"); - - assert_non_null(m); - assert_string_equal(m->context->name, "A"); - - m = wm_find_module("B"); - - assert_non_null(m); - assert_string_equal(m->context->name, "B"); -} - -static void test_find_module_not_found(void ** state) { - (void)state; - - wmodule * m = wm_find_module("C"); - - assert_null(m); -} - -static void test_module_query_no_args(void ** state) { - char input[] = "none"; - const char EXPECTED_OUTPUT[] = "err {\"error\":1,\"message\":\"Module query needs arguments\"}"; - - size_t n = wm_module_query(input, (char **)state); - - assert_string_equal(*state, EXPECTED_OUTPUT); - assert_int_equal(n, strlen(EXPECTED_OUTPUT)); -} - -static void test_module_query_no_module(void ** state) { - char input[] = "C some-command"; - const char EXPECTED_OUTPUT[] = "err {\"error\":2,\"message\":\"Module not found or not configured\"}"; - - size_t n = wm_module_query(input, (char **)state); - - assert_string_equal(*state, EXPECTED_OUTPUT); - assert_int_equal(n, strlen(EXPECTED_OUTPUT)); -} - -static void test_module_query_no_queries(void ** state) { - char input[] = "B some-command"; - const char EXPECTED_OUTPUT[] = "err {\"error\":3,\"message\":\"This module does not support queries\"}"; - - size_t n = wm_module_query(input, (char **)state); - - assert_string_equal(*state, EXPECTED_OUTPUT); - assert_int_equal(n, strlen(EXPECTED_OUTPUT)); -} - -static void test_module_query_echo(void ** state) { - char input[] = "A echo"; - - size_t n = wm_module_query(input, (char **)state); - - assert_string_equal(*state, "echo"); - assert_int_equal(n, 4); -} - -int main() { - const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_find_module_found, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_find_module_not_found, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_module_query_no_args, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_module_query_no_module, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_module_query_no_queries, setup_modules, teardown_modules), - cmocka_unit_test_setup_teardown(test_module_query_echo, setup_modules, teardown_modules), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -}